-
Notifications
You must be signed in to change notification settings - Fork 0
/
make
executable file
·89 lines (73 loc) · 1.67 KB
/
make
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
#!/bin/sh
info="\033[0;32m[info]\033[0m"
err="\033[0;31m[err]\033[0m"
detect_compiler() {
if echo $(which clang) | grep -qF "clang"; then
CC="clang"
elif echo $(which gcc) | grep -qF "gcc"; then
CC="gcc"
fi
echo "$info Using compiler: $CC"
}
detect_os() {
osfound=$(uname -o)
case $osfound in
"GNU/Linux")
os="gnu"
;;
"Android")
os="android"
;;
*)
echo "$err OS not recognized"
exit 1
esac
echo "$info Found OS: $os"
}
detect_machine(){
m=$(uname -m)
echo "$info Found machine: $m"
}
compile() {
detect_compiler
detect_os
detect_machine
$CC ./client4.c $components -o "client-$os-$m"
#$CC ./server.c . -o "server-$os-$m"
}
program=$1
# With libcurl inside, it is no longer possible to have static binaries.
# because libcurl contains: getaddrinfo()
components="-Wall -Wextra -g ./libcurl.a ./libcjson.a -lssl -lcrypto -lpthread"
#components="-g -Wall -Wextra -lcurl "
main() {
if [ "$program" != "" ]; then
detect_compiler
detect_os
detect_machine
lenpn=${#program} #length of Program's name
leni=$(($lenpn-2)) #len(".c")=2 #length index
exen=$(echo $program | cut -c1-$leni) #executable name
exenfull="$exen-$os-$m"
$CC $program $components -o $exenfull
if echo $? | grep -qF "0"; then
if [ ! -d ./chatnet_role_change/ ]; then
mkdir ./chatnet_role_change/
fi
cp ./$exenfull ./chatnet_role_change/
echo "$info Program copied to ./chatnet_role_change\n";
./$exenfull
else echo "$err Program not compiled"
fi
else
echo "$err Program name missing"
exit
compile
if echo $? | grep -qF "0"; then
echo "$info Programs compiled."
else
echo "$err Compilation failed."
fi
fi
}
main