Last active
August 29, 2015 14:08
-
-
Save necrophcodr/05bfc2d755a4e1abb1ce to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Made by necrophcodr 2014 ( http://necrophcodr.me/ ) | |
PWD="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" | |
check_jq() { | |
if [[ $(which jq 2>/dev/null; echo $?) -ne 0 ]]; then | |
printf "jq utility not in path..." | |
if [[ -x "deps/jq-jq-1.4/jq" ]]; then | |
printf "found deps/jq-jq-1.4/jq!\n"; | |
PATH="$PWD/deps/jq-jq-1.4:$PATH" | |
return | |
fi | |
( mkdir -p deps && | |
cd deps && | |
wget -c https://github.com/stedolan/jq/archive/jq-1.4.tar.gz -O \ | |
jq-1.4.tar.gz && | |
tar xf jq-1.4.tar.gz && | |
rm jq-1.4.tar.gz | |
cd jq-jq-1.4 && | |
autoreconf -i && | |
./configure && | |
make && | |
make check ) && ( cd $PWD && ./$0 $@ ) | |
exit | |
fi | |
} | |
try_fetch() { | |
dep_type="$1" | |
dep_url="$2" | |
dep_file="$3" | |
cd deps | |
[[ -e "$dep_file" ]] && return | |
echo "Using $dep_type to fetch $dep_url -> $dep_file" | |
case "$dep_type" in | |
wget) | |
wget -c $dep_url | |
local err | |
tar xf $dep_file | |
err=$? | |
if [[ $err -eq 0 ]]; then | |
rm -f $dep_file | |
fi | |
return $? | |
;; | |
git) | |
git clone $dep_url $dep_file | |
return $? | |
;; | |
hg) | |
hg clone $dep_url $dep_file | |
return $? | |
;; | |
fossil) | |
mkdir -p $dep_file | |
fossil clone $dep_url $dep_file/.repo.fossil | |
( cd $dep_file && fossil open --nested .repo.fossil ) | |
return $? | |
;; | |
*) | |
echo "no idea how to fetch using \"$dep_type\".. :(" | |
return 1 | |
;; | |
esac | |
} | |
try_configure() { | |
dep_dir="$1" | |
cd $dep_dir | |
[[ -f "Makefile" ]] && return | |
if [[ -f "configure" ]]; then | |
PREFIX=$(pwd) ./configure && return | |
fi | |
if [[ -f "configure.ac" ]]; then | |
autoreconf -i && try_configure $dep_dir && return | |
fi | |
} | |
try_build() { | |
dep_dir="$1" | |
cd $dep_dir | |
if [[ -f "Makefile" ]]; then | |
make install && return | |
fi | |
} | |
check_jq | |
cat spm.json | jq '.depends | keys[]' | sed 's|"||g' | while read dep; do | |
dep_type=$(cat spm.json | jq -c '.depends["'$dep'"][0]' | sed 's|"||g') | |
if [[ "$dep_type" == "null" ]]; then | |
dep_type="wget" | |
fi | |
dep_url=$(cat spm.json | jq -c '.depends["'$dep'"][1]' | sed 's|"||g') | |
( ( try_fetch $dep_type $dep_url $dep ) && ( try_configure deps/$dep ) && \ | |
( try_build deps/$dep ) ) | |
[[ $? -ne 0 ]] && exit 1 | |
done | |
./configure | |
[[ -d ".tup" ]] || tup init | |
tup upd |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"name":"some project", | |
"depends":{ | |
"libmicrohttpd-0.9.38":[null, "http://ftp.gnu.org/gnu/libmicrohttpd/libmicrohttpd-0.9.38.tar.gz"] | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment