blob: 903cbf263be33d2a5850f459d25052230df6a793 (
plain)
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
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
|
#!/bin/sh
# Configure script by blankhex
# Default values
cc=${CC:-gcc}
ld=${LD:-gcc}
ar=${AR:-ar}
source_path="$(dirname "$0")"
prefix_path=${PREFIX:-/usr/local}
enable_shared="no"
enable_mt="yes"
enable_lfs="no"
enable_tests="yes"
enable_pic="yes"
use_clock_gettime="no"
arflags=${ARFLAGS:-cr}
cflags=${CFLAGS}
ldflags=${LDFLAGS}
ldlibs=${LDLIBS}
ldshared=${LDSHARED:--shared}
cflagsmt=${CFLAGSMT:--pthread}
ldflagsmt=${LDFLAGSMT:--pthread}
ldlibsmt=${LDLIBSMT}
platform=""
display_help="no"
# Parse arguments
for option do
case $option in
--cc=*) cc="${option#--cc=}" ;;
--ar=*) ar="${option#--ar=}" ;;
--ld=*) ld="${option#--ld=}" ;;
--arflags=*) arflags="${option#--arflags=}" ;;
--cflags=*) cflags="${option#--cflags=}" ;;
--ldflags=*) ldflags="${option#--ldflags=}" ;;
--ldlibs=*) ldlibs="${option#--ldlibs=}" ;;
--ldshared=*) ldshared="${option#--ldshared=}" ;;
--cflagsmt=*) cflagsmt="${option#--cflagsmt=}" ;;
--ldflagsmt=*) ldflagsmt="${option#--ldflagsmt=}" ;;
--ldlibsmt=*) ldlibsmt="${option#--ldlibsmt=}" ;;
--platform=*) platform="${option#--platform=}" ;;
--prefix=*) prefix_path="${option#--prefix=}" ;;
--enable-shared|--enable-shared=yes) enable_shared="yes" ;;
--enable-shared=no) enable_shared="no" ;;
--enable-mt|--enable-mt=yes) enable_mt="yes" ;;
--enable-mt=no) enable_mt="no" ;;
--enable-lfs|--enable-lfs=yes) enable_lfs="yes" ;;
--enable-lfs=no) enable_lfs="no" ;;
--enable-tests|--enable-tests=yes) enable_tests="yes" ;;
--enable-tests=no) enable_tests="no" ;;
--use-clock_gettime|--use-clock_gettime=yes) use_clock_gettime="yes" ;;
--use-clock_gettime=no) use_clock_gettime="no" ;;
--source=*) source_path="${option#--source=}" ;;
--enable-pic|--with-pic=yes) enable_pic="yes" ;;
--enable-pic=no) enable_pic="no" ;;
--help|-h) display_help="yes" ;;
*) echo "configure: WARNING unrecognized option $option" ;;
esac
done
if [ "$display_help" = "yes" ]; then
cat << EOF
Usage: configure [OPTIONS]
Options:
--help Print this message
--source= Path to the source code
--cc=CC C compiler
--ld=LD Linker
--ar=AR Library archiver
--arflags= Archiver flags
--cflags= Compiler flags
--ldflags= Linker flags
--ldlibs= Linker libraries
--ldshared= Linker flags for shared libraries
--cflagsmt= Compiler flags for multithreading
--ldflagsmt= Linker flags for multithreading
--ldlibsmt= Linker libraries for multithreading
--platform=[Posix|Win32|Dummy] Specify target platform
--prefix= Install prefix
--enable-shared[=yes|no] Make shared library
--enable-pic[=yes|no] Enable position independent code (PIC)
--enable-mt[=yes|no] Enable multithreading support
--enable-lfs[=yes|no] Enable large file support
--enable-tests[=yes|no] Enable unit tests
--use-clock_gettime[=yes|no] Use of clock_gettime regardless of the support
EOF
exit 1
fi
# Ensure that source_path ends on /
case "$source_path" in
*/) ;;
*) source_path="$source_path/" ;;
esac
# Detect and validate OS
os="Unknown"
case "${platform:-$(uname)}" in
Posix|Win32|Dummy) ;;
Darwin*) os="MacOS"; platform="Posix" ;;
Linux*) os="Linux"; platform="Posix" ;;
*BSD) os="BSD"; platform="Posix" ;;
CYGWIN*|MINGW*|MSYS*) os="Windows"; platform="Win32" ;;
*) platform="Dummy" ;;
esac
case "$platform" in
Posix|Win32|Dummy) ;;
*) echo "configure: WARNING: unsupported platform '$platform'"; platform="Dummy" ;;
esac
# Platform-specific settings
exe_suffix=""
dll_prefix="libbh"
dll_suffix=".so"
if [ "$platform" = "Win32" ]; then
exe_suffix=".exe"
dll_prefix="bh"
dll_suffix=".dll"
fi
# Build flags
cflags="-I${source_path}include -I. $cflags"
ldlibs="-lm $ldlibs"
if [ "$enable_pic" = "yes" ]; then
cflags="$cflags -fPIC"
fi
if [ "$enable_pic" = "no" ] && [ "$enable_shared" = "yes" ]; then
echo "configure: WARNING: requested shared library while PIC is disabled"
echo "configure: WARNING: expect build failure"
fi
if [ "$enable_mt" = "yes" ]; then
cflags="$cflags $cflagsmt"
ldflags="$ldflags $ldflagsmt"
ldlibs="$ldlibs $ldlibsmt"
fi
# Create directories
mkdir src src/Platform src/Math src/String 2>/dev/null
mkdir src/Platform/Posix src/Platform/Win32 src/Platform/Dummy 2>/dev/null
if [ "$enable_tests" = "yes" ]; then
mkdir test test/src unit unit/src 2>/dev/null
fi
library=""
add_source() { library="${library}${library:+:}$1"; }
# Main source
for file in "${source_path}"src/*.c; do
add_source "$file"
done
for file in "${source_path}"src/Math/*.c; do
add_source "$file"
done
for file in "${source_path}"src/String/*.c; do
add_source "$file"
done
# Platform specific code
add_source "${source_path}src/Platform/Spinlock.c"
case "$platform" in
Posix) add_source "${source_path}src/Platform/Posix/File.c" ;;
Win32) add_source "${source_path}src/Platform/Win32/File.c" ;;
*) add_source "${source_path}src/Platform/Dummy/File.c" ;;
esac
if [ "$enable_mt" = "yes" ]; then
case "$platform" in
Posix)
for item in Condition Mutex Semaphore Thread Tss; do
add_source "${source_path}src/Platform/Posix/${item}.c"
done
;;
Win32)
for item in Condition Mutex Semaphore Thread Tss; do
add_source "${source_path}src/Platform/Win32/${item}.c"
done
;;
*)
for item in Condition Mutex Semaphore Thread Tss; do
add_source "${source_path}src/Platform/Dummy/${item}.c"
done
;;
esac
else
for item in Condition Mutex Semaphore Thread Tss; do
add_source "${source_path}src/Platform/Dummy/${item}.c"
done
fi
# Tests
tests=""
unit=""
add_test() { tests="${tests}${tests:+:}$1"; }
if [ "$enable_tests" = "yes" ]; then
unit="${source_path}unit/src/Unit.c"
for file in "${source_path}"test/src/*.c; do
add_test "$file"
done
fi
# Generate Makefile
{
echo "CC=$cc"
echo "LD=$ld"
echo "AR=$ar"
echo "ARFLAGS=$arflags"
echo "CFLAGS=$cflags"
echo "LDFLAGS=$ldflags"
echo "LDLIBS=$ldlibs"
echo "LDSHARED=$ldshared"
echo "PREFIX=$prefix_path"
echo "STATICLIB=libbh.a"
# Shared library
if [ "$enable_shared" = "yes" ]; then
printf "SHAREDLIB=${dll_prefix}${dll_suffix}\n"
printf "\nall: static shared\n"
printf "\nshared: \${SHAREDLIB}\n"
printf "\n\$(SHAREDLIB): "
( IFS=":"; for item in $library; do item="${item#$source_path}"; printf "%s " "${item%.c}.o"; done; )
printf "\n\t\$(LD) \$(LDFLAGS) \$(LDSHARED) -o \$@ "
( IFS=":"; for item in $library; do item="${item#$source_path}"; printf "%s " "${item%.c}.o"; done; )
printf "\$(LDLIBS)\n"
else
printf "\nall: static\n"
fi
# Static library
printf "\nstatic: \${STATICLIB}\n"
printf "\n\$(STATICLIB): "
( IFS=":"; for item in $library; do item="${item#$source_path}"; printf "%s " "${item%.c}.o"; done; )
printf "\n\t\$(AR) \$(ARFLAGS) \$@ "
( IFS=":"; for item in $library; do item="${item#$source_path}"; printf "%s " "${item%.c}.o"; done; )
printf "\n"
# Compile sources
(
IFS=":";
for item in $library; do
object="${item#$source_path}"
printf "\n%s: %s\n" "${object%.c}.o" "$item"
printf "\t\$(CC) \$(CFLAGS) -c -o \$@ %s\n" "$item"
done
)
# Tests
if [ "$enable_tests" = "yes" ]; then
(
unit_obj="${unit#$source_path}"
printf "\n%s: %s\n" "${unit_obj%.c}.o" "$unit"
printf "\t\$(CC) \$(CFLAGS) -I${source_path}unit/include -c -o \$@ %s\n" "$unit"
IFS=":";
for item in $tests; do
object="${item#$source_path}"
printf "\n%s: %s %s \$(STATICLIB)\n" "${object%.c}${exe_suffix}" "${object%.c}.o" "${unit_obj%.c}.o"
printf "\t\$(LD) \$(LDFLAGS) -o \$@ %s %s \$(STATICLIB) \$(LDLIBS)\n" "${object%.c}.o" "${unit_obj%.c}.o"
printf "\n%s: %s\n" "${object%.c}.o" "$item"
printf "\t\$(CC) \$(CFLAGS) -I${source_path}unit/include -c -o \$@ %s\n" "$item"
done
printf "\ntest: "
for item in $tests; do
object="${item#$source_path}"
printf "%s " "${object%.c}${exe_suffix}"
done
echo
for item in $tests; do
object="${item#$source_path}"
printf "\t./%s\n" "${object%.c}${exe_suffix}"
done
echo
)
fi
# Clean
printf "\nclean:\n"
printf "\t-rm -f %s\n" "\$(STATICLIB)"
if [ "$enable_shared" = "yes" ]; then
printf "\t-rm -f %s\n" "\$(SHAREDLIB)"
fi
(
IFS=":"
for item in $library; do
item="${item#$source_path}";
printf "\t-rm -f %s\n" "${item%.c}.o"
done
if [ "$enable_tests" = "yes" ]; then
unit_obj="${unit#$source_path}"
printf "\t-rm -f %s\n" "${unit_obj%.c}.o"
for item in $tests; do
item="${item#$source_path}"
printf "\t-rm -f %s\n" "${item%.c}.o"
printf "\t-rm -f %s\n" "${item%.c}${exe_suffix}"
done
fi
)
# Install
printf "\ninstall: \$(STATICLIB) "
if [ "$enable_shared" = "yes" ]; then
printf "\$(SHAREDLIB)"
fi
printf "\n\tinstall -d \$(DESTDIR)\$(PREFIX)/lib/\n"
printf "\tinstall -d \$(DESTDIR)\$(PREFIX)/include/BH/Math\n"
printf "\tinstall -m 644 \$(STATICLIB) \$(DESTDIR)\$(PREFIX)/lib\n"
if [ "$enable_shared" = "yes" ]; then
printf "\tinstall -m 644 \$(SHAREDLIB) \$(DESTDIR)\$(PREFIX)/lib\n"
fi
for file in "${source_path}"include/BH/*.h; do
printf "\tinstall -m 644 \"%s\" \$(DESTDIR)\$(PREFIX)/include/BH\n" "$file"
done
for file in "${source_path}"include/BH/Math/*.h; do
printf "\tinstall -m 644 \"%s\" \$(DESTDIR)\$(PREFIX)/include/BH/Math\n" "$file"
done
# Uninstall
printf "\nuninstall:\n"
printf "\trm -rf \$(DESTDIR)\$(PREFIX)/include/BH\n"
printf "\trm -rf \$(DESTDIR)\$(PREFIX)/lib/\$(STATICLIB)\n"
if [ "$enabled_shared" = "yes" ]; then
printf "\trm -rf \$(DESTDIR)\$(PREFIX)/lib/\$(SHAREDLIB)\n"
fi
} > Makefile
# Generate Config.h
{
printf "#ifndef BH_SRC_CONFIG_H\n"
printf "#define BH_SRC_CONFIG_H\n\n"
if [ "$use_clock_gettime" = "yes" ]; then
printf "#define BH_USE_CLOCK_GETTIME\n";
fi
if [ "$enable_lfs" = "yes" ]; then
printf "#define BH_ENABLE_LFS\n";
fi
printf "\n#endif /* BH_SRC_CONFIG_H */\n"
} > Config.h
echo " --- General information --- "
echo "OS: $os"
echo "Platform: $platform"
echo "Source path: $source_path"
echo
echo " --- Makefile variables --- "
echo "CC: $cc"
echo "LD: $ld"
echo "AR: $ar"
echo "ARFLAGS: $arflags"
echo "CFLAGS: $cflags"
echo "LDFLAGS: $ldflags"
echo "LDLIBS: $ldlibs"
echo "LDSHARED: $ldshared"
echo "PREFIX: $prefix_path"
echo
echo " --- Enabled options --- "
echo "Enable multithreading: $enable_mt"
echo "Enable long file support: $enable_lfs"
echo "Enable tests: $enable_tests"
echo "Enable PIC: $enable_pic"
echo "Build shared library: $enable_shared"
echo "Use clock_gettime: $use_clock_gettime"
|