-
Notifications
You must be signed in to change notification settings - Fork 1
/
configure
executable file
·123 lines (105 loc) · 3.3 KB
/
configure
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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
#!/bin/bash
#
# Copyright (C) Niklaus F.Schen.
#
# test system type
sysname=`uname -s`
debug=0
path=/usr/bin/
libpath=/usr/local/melon
cc="cc"
echo -e "#include <stdio.h>\nint main(void) {printf(\"1\");return 0;}" > .xcode.c
$cc -o .xcode .xcode.c 2>/dev/null 1>&2
if [ $? -ne 0 ]; then
cc="$cc -isysroot `xcrun --show-sdk-path`"
fi
rm -fr .xcode .xcode.c
#installation path
if ! case $sysname in MINGW*) false;; esac; then
echo "No support Windows"
exit 1
fi
#get all parameters
for param in $@
do
if [ $param == "--help" ]; then
echo -e "\nMelon platform."
echo "Copyright (C) Niklaus F.Schen."
echo "Options:"
echo -e "\t--prefix=INSTALL_PATH"
echo -e "\t--melon-prefix=INSTALLED_MELON_PATH"
echo -e "\t--cc=C compiler"
echo -e "\t--debug"
exit 0
fi
param_prefix=`echo $param|cut -d '=' -f 1`
param_suffix=`echo $param|cut -d '=' -f 2`
if [ $param_prefix == "--prefix" ]; then
path=$param_suffix
elif [ $param_prefix == "--melon-prefix" ]; then
libpath=$param_suffix
elif [ $param_prefix == "--debug" ]; then
debug=1
elif [ $param_prefix == "--cc" ]; then
cc=$param_suffix
fi
done
#debug
if [ $debug -ne 0 ]; then
debug='-ggdb -D__DEBUG__'
else
debug=''
fi
# build makefile content
echo "# " > Makefile
echo "# Copyright (C) Niklaus F.Schen." >> Makefile
echo "# " >> Makefile
echo -e "CC\t\t= $cc" >> Makefile
gccver=`gcc -dumpversion|cut -d '.' -f 1`
if [ $sysname != 'Darwin' -a "$?" == "0" -a $gccver -ge 11 ]; then
echo -e "FLAGS\t\t= -I$libpath/include -c -Wall $debug -Werror -O2 -fPIC -Iinclude" >> Makefile
else
echo -e "FLAGS\t\t= -I$libpath/include -c -Wall $debug -Werror -O3 -fPIC -Iinclude" >> Makefile
fi
echo -e "MEDGE\t\t= medge" >> Makefile
echo -e "OBJS\t\t= \\" >> Makefile
for f in `find src -name "*.c"`
do
prefix=`echo $f|cut -d '/' -f 2 | cut -d '.' -f 1`
echo -e "\tobjs/$prefix.o \\" >> Makefile
done
echo -e "\n" >> Makefile
echo -e ".PHONY :\tcompile install clean" >> Makefile
echo "compile: MKDIR \$(OBJS) \$(MEDGE)" >> Makefile
echo "clean:" >> Makefile
echo -e "\trm -fr objs bin Makefile" >> Makefile
echo "MKDIR :" >> Makefile
echo -e "\ttest -d objs || mkdir objs" >> Makefile
echo -e "\ttest -d bin || mkdir bin" >> Makefile
echo "\$(MEDGE) : \$(OBJS)" >> Makefile
echo -e "\t\$(CC) -o bin/\$(MEDGE) \$(OBJS) $debug -Wall -Werror -L$libpath/lib -lmelon -I$libpath/include" >> Makefile
echo "install:" >> Makefile
echo -e "\ttest -d $path || mkdir -p $path" >> Makefile
echo -e "\ttest -d /opt/medge || mkdir -p /opt/medge && cp example/* /opt/medge/" >> Makefile
echo -e "\tcp -fr bin/medge $path/" >> Makefile
for fname in `find . -name "*.c"`
do
objname=`basename $fname | cut -d '.' -f 1`".o"
echo -n "objs/$objname :" >> Makefile
for header in `cpp -MM -MG $fname 2> /dev/null`
do
suffix=`echo $header | cut -d '.' -f 2`
if [ $suffix = 'c' ]; then
echo -n $header >> Makefile
echo -n " " >> Makefile
continue
fi
if [ $suffix != 'h' ]; then
continue
fi
test -e include/$header && echo -n "include/$header " >> Makefile
done
echo "" >> Makefile
echo -e "\t\$(CC) \$(FLAGS) -o \$@ $fname" >> Makefile
done
echo "Configure done!"