-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.sh
executable file
·107 lines (96 loc) · 2.83 KB
/
build.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
#!/usr/bin/env bash
CC=
PROG="pkgmgr"
PROGPATH="$HOME/$PROG"
FLAGS="-std=gnu99 -Wall -Wextra -pedantic"
LD_FLAGS="-lm"
if [ "$CFLAGS" != "" ]; then
FLAGS="$FLAGS $CFLAGS"
fi
if [ "$LDFLAGS" != "" ]; then
LD_FLAGS="$LD_FLAGS $LDFLAGS"
fi
#check if someone builds in the wrong place
if [ "$PWD" == "$PROGPATH" -o "$PWD" == "/usr$PROGPATH" ]; then
echo "Building inside $PROGPATH is not allowed"
cd ..
mv $PROGPATH $PROGPATH"_build"
cd $PROGPATH"_build"
exec ./build.sh
fi
#building procedure
if [ "$1" == "help" ];then
echo "Usage: $0 [cmd]"
echo " all: builds $PROG"
echo " nocut: builds $PROG without cut used in list function"
echo " debug: builds $PROG with debug output enabled"
echo " install: installs $PROG in $PROGPATH"
echo " clean: cleans the build dir"
echo " alias to 'all' is $0 w/o any cmd"
elif [ "$1" == "" -o "$1" == "all" -o "$1" == "nocut" -o "$1" == "debug" ]; then
#set compiler
echo "Setting compiler..."
if [ "$CC" == "" ]; then
if [ -f /usr/bin/gcc -o -f /usr/local/bin/gcc ]; then
CC=gcc
echo " using gcc"
elif [ -f /usr/bin/clang -o -f /usr/local/bin/clang ]; then
CC=clang
echo " using clang"
else
echo " Neither clang nor gcc was found on your system!"
exit 255
fi
else
echo " using $CC (manually set)"
fi
echo " DONE"
#dependency check
echo "Checking dependencies..."
if [ ! -f /usr/bin/wget -a ! -f /usr/local/bin/wget ]; then
echo " wget was not found on your system"
echo " Please install wget to use $PROG!"
exit 177
else
wgetver=$(wget --version | grep "Wget 1." | cut -d " " -f 3 | cut -d "." -f 2)
if ((wgetver < 16)); then
echo " wget version below 1.16"
echo " formated wget output disabled"
FLAGS="$FLAGS -DOLD_WGET"
fi
fi
if [ "$1" == "nocut" -o ! -f /usr/bin/cut -a ! -f /usr/local/bin/cut ]; then
echo " not using cut"
FLAGS="$FLAGS -DNO_CUT"
fi
echo " DONE"
#debug output
if [ "$1" == "debug" ]; then
echo " debug output enabled"
FLAGS="$FLAGS -DDEBUG -g"
fi
#it's showtime
echo
echo "$CC $FLAGS $PROG.c -o $PROG $LD_FLAGS"
$CC $FLAGS $PROG.c -o $PROG $LD_FLAGS
echo
#install/copy to the program folder at $PROGPATH
elif [ "$1" == "install" -a -f $PROG ]; then
if [ ! -f $PROGPATH/$PROG ];then
#initial execution (creates folders and such)
echo "First execution"
echo
./$PROG "-h"
echo
fi
cp $PROG $PROGPATH
echo "$PROG was copied to $PROGPATH"
#or build first if it wasn't build
elif [ "$1" == "install" -a ! -f $PROG ]; then
$0 && $0 install
#clean the build dir of binaries
elif [ "$1" == "clean" ];then
rm -rf *.o
rm -rf $PROG
fi
#echo "All done, have fun!"