-
Notifications
You must be signed in to change notification settings - Fork 0
/
compile.sh
executable file
·78 lines (68 loc) · 1.72 KB
/
compile.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
#!/bin/bash
#
# compile sample for Linux by clang
#
usage_exit() {
echo "Usage: $0 [-h][-c][-d][-g][-i][-m][-o obj] [source] [libsansi]" 1>&2
echo " [source]: compiling source file, default is 'main.sample.c' " 1>&2
echo " [libsansi]: path for linking 'libsansi….o', default is found it in cwd automatically " 1>&2
echo " [-h]: show this usage and exit" 1>&2
echo " [-c]: compile for linux by clang" 1>&2
echo " [-d]: compile for linux by clang++ with standard c++11" 1>&2
echo " [-g]: compile for linux by gcc, this is default" 1>&2
echo " [-i]: compile for linux by g++ with standard c++11" 1>&2
echo " [-m]: compile for mac by clang" 1>&2
echo " [-o obj] set compiled object file name, default is a.out" 1>&2
exit 1
}
compiler="gcc"
obj="a.out"
std=""
while getopts "hcdgimo:" OPT; do
case "$OPT" in
h) usage_exit
;;
c) compiler="clang"
;;
d) compiler="clang++"
std="-std=c++11"
;;
g) compiler="gcc"
;;
i) compiler="g++"
std="-std=c++11"
;;
m) compiler="clang"
# use openssl
export LIBRARY_PATH=$LIBRARY_PATH:/usr/local/opt/openssl/lib/
;;
o) obj="$OPTARG"
;;
esac
done
if [ ${@:$OPTIND+1:1} ]; then
libsansi=${@:$OPTIND+1:1}
else
libsansi=`ls libsansi*.o`
fi
if [ ${@:$OPTIND:1} ]; then
sfile=${@:$OPTIND:1}
else
sfile="main.simple.c"
fi
echo "source =" $sfile
echo "libsansi =" $libsansi
echo "compiler =" $compiler
echo "obj =" $obj
echo "std =" $std
echo "compiling…"
#
# compile by clang with your sansi library
#
$compiler $std -o $obj $libsansi $sfile -L . -lssl -lcrypto -lpthread -ldl -lm
#
# strip
#
strip $obj
# @author Dr. Takeyuki UEDA
# @copyright Copyright© Atelier UEDA 2020 - All rights reserved.