-
Notifications
You must be signed in to change notification settings - Fork 2
/
configure
executable file
·306 lines (272 loc) · 7.68 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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
#!/bin/bash
#-------------------------------------------------------------------------------
#
# Simple configure script / build system.
# Version 1.03 (10/05/2013)
#
#-------------------------------------------------------------------------------
# Settings:
# makefile target for this configuration
targetname="csc688_target"
builddir="build/csc688_target"
bin="build/csc688"
# list of needed libraries
lib_list=""
#list of needed external tools
tool_list=""
# compiler and linker flags
cxx="g++-4.4"
#cxx="g++"
optional_cflags="-Wno-deprecated -ggdb -O3 -m32 -std=c++0x -U_FORTIFY_SOURCE -D_GLIBCXX_USE_NANOSLEEP -I. -I./offline"
#optional_cflags="-Wno-deprecated -ggdb"
optional_lflags="-std=c++0x -pthread"
#optional_lflags="-pthread"
# Use single quotes around pattern with * to avoid early glob expansion.
# Ignored files:
ignore="viz/*' 'viz/plot/*' 'build/.moc/*'"
# List of files that are compiled with -fpermissive and -w:
hideWarningsFilelist=""
# ---------------------------------------
includedMakefiles=""
generatedFiles=""
#----------------------------------------
# Settings can be overidden by command line arguments
#loop for all arguments
for arg in "$@"
do
argname=`echo $arg | sed 's/\([^=]*\)=.*/\1/g'`
argvalue=`echo $arg | sed 's/.*=\([^=]*\)/\1/g'`
if [ "$argname" == "target" ]; then targetname=$argvalue; fi
if [ "$argname" == "cxx" ]; then cxx=$argvalue; fi
if [ "$argname" == "cflags" ]; then optional_cflags=$argvalue; fi
if [ "$argname" == "lflags" ]; then optional_lflags=$argvalue; fi
if [ "$argname" == "builddir" ]; then builddir=$argvalue; fi
if [ "$argname" == "bin" ]; then bin=$argvalue; fi
if [ "$argname" == "lib_list" ]; then lib_list=$argvalue; fi
if [ "$argname" == "ignore" ]; then ignore="$ignore $argvalue"; fi
done
#-------------------------------------------------------------------------------
#-------------------------------------------------------------------------------
# DO NOT MODIFY ANYTHING BELOW :)
#-------------------------------------------------------------------------------
#-------------------------------------------------------------------------------
#check libraries
libflags_compiler=""
libflags_linker=""
missing_libs=0
for lib in $lib_list
do
echo -n "Checking library $lib... "
tmp=`pkg-config --cflags $lib 2> /dev/null`
if [ "$?" == "0" ]
then
libflags_compiler="$libflags_compiler $tmp"
libflags_linker="$libflags_linker `pkg-config --libs $lib`"
echo ok
else
echo NOT FOUND
missing_libs=$((missing_libs+1))
fi
done
#check external tools
missing_tools=0
for tool in $tool_list
do
echo -n "Checking $tool... "
tmp=`which $tool`
if [ "$?" == "0" ]
then
echo ok
else
echo NOT FOUND
missing_tools=$((missing_tools+1))
fi
done
#if something is missing, stop here
if [ "$missing_libs" != "0" ]; then
echo $missing_libs libraries missing!; fi
if [ "$missing_tools" != "0" ]; then
echo $missing_tools external tools missing!; fi
if [ "$missing_libs$missing_tools" != "00" ]; then
exit; fi
#----------------------------------------
#write Makefile
src_list=$builddir/src_list
dep_list=$builddir/dep_list
cflags="$libflags_compiler -I. -Wall $optional_cflags"
lflags="$libflags_linker $optional_lflags"
echo Creating Makefile...
{ # BEGIN printing Makefile
# create new default target
cat << EOC
default: $targetname
# --- BEGIN TARGETS
# --- BEGIN $targetname
$targetname: CXX=$cxx
$targetname: CFLAGS=$cflags
$targetname: LFLAGS=$lflags
$targetname: BIN=$bin
$targetname: BUILDDIR=$builddir
-include $src_list
-include $dep_list
$targetname: \$(OBJ_$targetname) link_$targetname
@echo $targetname compiled.
link_$targetname: \$(OBJ_$targetname)
@echo \$(YEL)Linking...\$(NOR)
@\$(CXX) \$(CFLAGS) -o $bin \$(OBJ_$targetname) \$(LFLAGS)
# --- END $targetname
EOC
#append all existing other targets
if [ -e Makefile ]
then
cat Makefile | sed "1,/BEGIN TARGETS/d;/END TARGETS/,\$d" \
| sed "/BEGIN $targetname\$/,/END $targetname\$/d" \
| grep -E -v "^default:"
else
echo "ALLTARGETS="
echo "ALLOBJ="
fi
echo "# --- END TARGETS"
for file in $includedMakefiles
do
echo "-include $file"
done
# add some static stuff (coloring, targets all and clean)
cat << 'EOC'
# Some Coloring
OS_TYPE=$(shell uname)
ifeq ($(OS_TYPE),Darwin)
ECHOEN=echo -en
else
ECHOEN=echo
endif
ESC=`$(ECHOEN) "\033"`
RED="$(ESC)[1;31m"
GRN="$(ESC)[1;32m"
YEL="$(ESC)[1;33m"
BLU="$(ESC)[1;34m"
VIO="$(ESC)[1;35m"
TUQ="$(ESC)[1;36m"
WHT="$(ESC)[1;37m"
NOR="$(ESC)[m"
# --- compile all
all:
$(foreach target,$(ALLTARGETS),$(MAKE) $(MAKEFILE) $(target);)
clean:
@rm -f $(ALLOBJ)
@echo All object files deleted.
EOC
} > Makefile.tmp #END printing Makefile
mv Makefile.tmp Makefile
if ! grep -q -E "^ALLTARGETS=.* $targetname .*\$" Makefile
then
sed -i -e "s/^\(ALLTARGETS=.*\)\$/\1 $targetname /g" Makefile
fi
if ! grep -q -E "^ALLOBJ=.* \\\$\(OBJ_$targetname\) .*\$" Makefile
then
sed -i -e "s/^\(ALLOBJ=.*\)\$/\1 \$(OBJ_$targetname) /g" Makefile
fi
#----------------------------------------
#create build directory
echo Creating build directory...
#create list with all src files
allsrc=""
for file in `find -L . -name \*.cpp -or -name \*.c | cut -c3- | xargs`
do
fileIgnored=0
for pattern in $ignore
do
pattern=${pattern//\'/}
if [[ $file == $pattern ]]; then
fileIgnored=1
fi
done
[ "$fileIgnored" == "0" ] && allsrc="$allsrc $file"
done
for file in $generatedFiles
do
[[ $allsrc != *$file* ]] && [[ $file == *.cpp ]] && allsrc="$allsrc $file"
[[ $allsrc != *$file* ]] && [[ $file == *.c ]] && allsrc="$allsrc $file"
done
#create builddir and all subdirectories
mkdir -p $builddir
for file in $allsrc
do
mkdir -p $builddir/`dirname $file`
done
#create object list
allobj=""
for srcfile in $allsrc
do
object="$builddir/${srcfile%.*}.o"
allobj="$allobj $object"
done
echo "OBJ_$targetname = $allobj" > $builddir/src_list
#create dep files and dep_list
echo Init dependency files...
olddeps=`find $builddir -name \*.dep | xargs`
if [ "$olddeps" != "" ]
then
rm $olddeps
fi
echo > $dep_list #clear dep list
filenamenew="_new"
jobs=0
for srcfile in $allsrc
do
let jobs+=1
{
#get path and filenames
objpath="$builddir/"${srcfile%/*}
[[ "$srcfile" != */* ]] && objpath="$builddir"
basefilename=${srcfile%.*}
objfile="$builddir/$basefilename.o"
depfile="$builddir/$basefilename.dep"
#check if file is on the no-warnings-list
extraflags=""
for pattern in $hideWarningsFilelist
do
pattern=${pattern//\'/}
[[ $srcfile == $pattern ]] && extraflags="-fpermissive -w"
done
#write dep file
{
if [ -f $srcfile ] #if src file exists
then
echo -n "$objpath/"
$cxx $cflags -M $srcfile 2> /dev/null
#if there was an error, try again using -MG and add full path for files in generatedFiles
if [ ! $? -eq 0 ]
then
$cxx $cflags -M -MG $srcfile | while read -r line
do
for dependency in $line
do
if [[ $generatedFiles == *$dependency* ]]
then
longDependency=`echo $generatedFiles | grep -oE "\b[^ ]*$dependency[^ ]*\b"`
line=`echo $line | sed "s@$dependency@$longDependency@"`
fi
done
echo "$line"
done
fi
else # if src file does not exist
echo "$objfile: $srcfile"
fi
cat << EOC
@echo \$(BLU)[\$(CXX)]\$(NOR) $srcfile
@\$(CXX) \$(CFLAGS) $extraflags -c $srcfile -o $objfile
@echo -n "$objpath/" > $depfile$filenamenew
@\$(CXX) \$(CFLAGS) -M $srcfile >> $depfile$filenamenew
@tail -n6 $depfile >> $depfile$filenamenew
@mv $depfile$filenamenew $depfile
EOC
} > $depfile
#add dep file to dep_list
echo "-include $depfile" >> $dep_list
} &
[[ $jobs -eq 8 ]] && wait && jobs=0
done
wait
echo Done.