|
1 #!/bin/sh |
|
2 |
|
3 |
|
4 PREFIX=/usr |
|
5 EPREFIX=$PREFIX |
|
6 |
|
7 BINDIR= |
|
8 SBINDIR= |
|
9 LIBDIR= |
|
10 LIBEXECDIR= |
|
11 DATADIR= |
|
12 SYSCONFDIR= |
|
13 SHAREDSTATEDIR= |
|
14 LOCALSTATEDIR= |
|
15 INCLUDEDIR= |
|
16 INFODIR= |
|
17 MANDIR= |
|
18 |
|
19 OS=`uname -s` |
|
20 OS_VERSION=`uname -r` |
|
21 |
|
22 TEMP_DIR=".tmp-`uname -n`" |
|
23 mkdir -p $TEMP_DIR |
|
24 if [ $? -ne 0 ]; then |
|
25 echo "Cannot create tmp dir" |
|
26 echo "Abort" |
|
27 fi |
|
28 touch $TEMP_DIR/options |
|
29 touch $TEMP_DIR/features |
|
30 |
|
31 # features |
|
32 |
|
33 # help text |
|
34 printhelp() |
|
35 { |
|
36 echo "Usage: $0 [OPTIONS]..." |
|
37 cat << __EOF__ |
|
38 Installation directories: |
|
39 --prefix=PREFIX path prefix for architecture-independent files |
|
40 [/usr] |
|
41 --exec-prefix=EPREFIX path prefix for architecture-dependent files |
|
42 [PREFIX] |
|
43 |
|
44 --bindir=DIR user executables [EPREFIX/bin] |
|
45 --sbindir=DIR system admin executables [EPREFIX/sbin] |
|
46 --libexecdir=DIR program executables [EPREFIX/libexec] |
|
47 --sysconfdir=DIR system configuration files [PREFIX/etc] |
|
48 --sharedstatedir=DIR modifiable architecture-independent data [PREFIX/com] |
|
49 --localstatedir=DIR modifiable single-machine data [PREFIX/var] |
|
50 --libdir=DIR object code libraries [EPREFIX/lib] |
|
51 --includedir=DIR C header files [PREFIX/include] |
|
52 --datarootdir=DIR read-only arch.-independent data root [PREFIX/share] |
|
53 --datadir=DIR read-only architecture-independent data [DATAROOTDIR] |
|
54 --infodir=DIR info documentation [DATAROOTDIR/info] |
|
55 --mandir=DIR man documentation [DATAROOTDIR/man] |
|
56 |
|
57 __EOF__ |
|
58 } |
|
59 |
|
60 # |
|
61 # parse arguments |
|
62 # |
|
63 for ARG in $@ |
|
64 do |
|
65 case "$ARG" in |
|
66 "--prefix="*) PREFIX=${ARG#--prefix=} ;; |
|
67 "--exec-prefix="*) EPREFIX=${ARG#--exec-prefix=} ;; |
|
68 "--bindir="*) BINDIR=${ARG#----bindir=} ;; |
|
69 "--sbindir="*) SBINDIR=${ARG#--sbindir=} ;; |
|
70 "--libdir="*) LIBDIR=${ARG#--libdir=} ;; |
|
71 "--libexecdir="*) LIBEXECDIR=${ARG#--libexecdir=} ;; |
|
72 "--datadir="*) DATADIR=${ARG#--datadir=} ;; |
|
73 "--sysconfdir="*) SYSCONFDIR=${ARG#--sysconfdir=} ;; |
|
74 "--sharedstatedir="*) SHAREDSTATEDIR=${ARG#--sharedstatedir=} ;; |
|
75 "--localstatedir="*) LOCALSTATEDIR=${ARG#--localstatedir=} ;; |
|
76 "--includedir="*) INCLUDEDIR=${ARG#--includedir=} ;; |
|
77 "--infodir="*) INFODIR=${ARG#--infodir=} ;; |
|
78 "--mandir"*) MANDIR=${ARG#--mandir} ;; |
|
79 "--help"*) printhelp; exit 1 ;; |
|
80 "-"*) echo "unknown option: $ARG"; exit 1 ;; |
|
81 esac |
|
82 done |
|
83 |
|
84 # set dir variables |
|
85 if [ -z "$BINDIR" ]; then |
|
86 BINDIR=$EPREFIX/bin |
|
87 fi |
|
88 if [ -z "$SBINDIR" ]; then |
|
89 SBINDIR=$EPREFIX/sbin |
|
90 fi |
|
91 if [ -z "$LIBDIR" ]; then |
|
92 LIBDIR=$EPREFIX/lib |
|
93 fi |
|
94 if [ -z "$LIBEXEC" ]; then |
|
95 LIBEXECDIR=$EPREFIX/libexec |
|
96 fi |
|
97 if [ -z "$DATADIR" ]; then |
|
98 DATADIR=$PREFIX/share |
|
99 fi |
|
100 if [ -z "$SYSCONFDIR" ]; then |
|
101 SYSCONFDIR=$PREFIX/etc |
|
102 fi |
|
103 if [ -z "$SHAREDSTATEDIR" ]; then |
|
104 SHAREDSTATEDIR=$PREFIX/com |
|
105 fi |
|
106 if [ -z "$LOCALSTATEDIR" ]; then |
|
107 LOCALSTATEDIR=$PREFIX/var |
|
108 fi |
|
109 if [ -z "$INCLUDEDIR" ]; then |
|
110 INCLUDEDIR=$PREFIX/include |
|
111 fi |
|
112 if [ -z "$INFODIR" ]; then |
|
113 INFODIR=$PREFIX/info |
|
114 fi |
|
115 if [ -z "$MANDIR" ]; then |
|
116 MANDIR=$PREFIX/man |
|
117 fi |
|
118 |
|
119 which pkg-config > /dev/null |
|
120 if [ $? -eq 0 ]; then |
|
121 PKG_CONFIG=pkg-config |
|
122 else |
|
123 PKG_CONFIG=false |
|
124 fi |
|
125 |
|
126 # Simple uname based platform detection |
|
127 # $PLATFORM is used for platform dependent dependency selection |
|
128 printf "detect platform... " |
|
129 if [ $OS = SunOS ]; then |
|
130 PLATFORM="solaris sunos unix svr4" |
|
131 fi |
|
132 if [ $OS = Linux ]; then |
|
133 PLATFORM="linux unix" |
|
134 fi |
|
135 if [ $OS = FreeBSD ]; then |
|
136 PLATFORM="freebsd bsd unix" |
|
137 fi |
|
138 if [ $OS = Darwin ]; then |
|
139 PLATFORM="macos osx bsd unix" |
|
140 fi |
|
141 echo $OS | grep "MINGW" > /dev/null |
|
142 if [ $? -eq 0 ]; then |
|
143 PLATFORM="windows mingw" |
|
144 fi |
|
145 |
|
146 if [ -z "$PLATFORM" ]; then |
|
147 PLATFORM="unix" |
|
148 fi |
|
149 |
|
150 for p in $PLATFORM |
|
151 do |
|
152 PLATFORM_NAME=$p |
|
153 break |
|
154 done |
|
155 echo $PLATFORM_NAME |
|
156 |
|
157 isplatform() |
|
158 { |
|
159 for p in $PLATFORM |
|
160 do |
|
161 if [ $p = $1 ]; then |
|
162 return 0 |
|
163 fi |
|
164 done |
|
165 return 1 |
|
166 } |
|
167 isnotplatform() |
|
168 { |
|
169 for p in $PLATFORM |
|
170 do |
|
171 if [ $p = $1 ]; then |
|
172 return 1 |
|
173 fi |
|
174 done |
|
175 return 0 |
|
176 } |
|
177 |
|
178 # generate config.mk and config.h |
|
179 cat > $TEMP_DIR/config.mk << __EOF__ |
|
180 # |
|
181 # config.mk generated by configure |
|
182 # |
|
183 |
|
184 # general vars |
|
185 |
|
186 PREFIX=$PREFIX |
|
187 EPREFIX=$EPREFIX |
|
188 |
|
189 BINDIR=$BINDIR |
|
190 SBINDIR=$SBINDIR |
|
191 LIBDIR=$LIBDIR |
|
192 LIBEXECDIR=$LIBEXECDIR |
|
193 DATADIR=$DATADIR |
|
194 SYSCONFDIR=$SYSCONFDIR |
|
195 SHAREDSTATEDIR=$SHAREDSTATEDIR |
|
196 LOCALSTATEDIR=$LOCALSTATEDIR |
|
197 INCLUDEDIR=$INCLUDEDIR |
|
198 INFODIR=$INFODIR |
|
199 MANDIR=$MANDIR |
|
200 |
|
201 __EOF__ |
|
202 |
|
203 echo > $TEMP_DIR/make.mk |
|
204 |
|
205 ENV_CFLAGS=$CFLAGS |
|
206 ENV_LDFLAGS=$LDFLAGS |
|
207 ENV_CXXFLAGS=$CXXFLAGS |
|
208 |
|
209 # Toolchain detection |
|
210 # this will insert make vars to config.mk |
|
211 . make/toolchain.sh |
|
212 |
|
213 # add user specified flags to config.mk |
|
214 echo >> $TEMP_DIR/config.mk |
|
215 if [ ! -z "${ENV_CFLAGS}" ]; then |
|
216 echo "CFLAGS += $ENV_CFLAGS" >> $TEMP_DIR/config.mk |
|
217 fi |
|
218 if [ ! -z "${ENV_CXXFLAGS}" ]; then |
|
219 echo "CXXFLAGS += $ENV_CXXFLAGS" >> $TEMP_DIR/config.mk |
|
220 fi |
|
221 if [ ! -z "${ENV_LDFLAGS}" ]; then |
|
222 echo "LDFLAGS += $ENV_LDFLAGS" >> $TEMP_DIR/config.mk |
|
223 fi |
|
224 |
|
225 # |
|
226 # DEPENDENCIES |
|
227 # |
|
228 |
|
229 dependency_curl() |
|
230 { |
|
231 printf "checking for curl... " |
|
232 # dependency curl platform="windows" |
|
233 while true |
|
234 do |
|
235 if isnotplatform "windows"; then |
|
236 break |
|
237 fi |
|
238 CFLAGS="$CFLAGS -I/mingw/include" |
|
239 LDFLAGS="$LDFLAGS -lcurl" |
|
240 echo yes |
|
241 return 0 |
|
242 done |
|
243 |
|
244 # dependency curl platform="macos" |
|
245 while true |
|
246 do |
|
247 if isnotplatform "macos"; then |
|
248 break |
|
249 fi |
|
250 curl-config --cflags > /dev/null |
|
251 if [ $? -eq 0 ]; then |
|
252 CFLAGS="$CFLAGS `curl-config --cflags`" |
|
253 else |
|
254 break |
|
255 fi |
|
256 curl-config --ldflags > /dev/null |
|
257 if [ $? -eq 0 ]; then |
|
258 LDFLAGS="$LDFLAGS `curl-config --ldflags`" |
|
259 else |
|
260 break |
|
261 fi |
|
262 echo yes |
|
263 return 0 |
|
264 done |
|
265 |
|
266 # dependency curl |
|
267 while true |
|
268 do |
|
269 if [ -z "$PKG_CONFIG" ]; then |
|
270 break |
|
271 fi |
|
272 $PKG_CONFIG libcurl |
|
273 if [ $? -ne 0 ] ; then |
|
274 break |
|
275 fi |
|
276 CFLAGS="$CFLAGS `$PKG_CONFIG --cflags libcurl`" |
|
277 LDFLAGS="$LDFLAGS `$PKG_CONFIG --libs libcurl`" |
|
278 echo yes |
|
279 return 0 |
|
280 done |
|
281 |
|
282 # dependency curl |
|
283 while true |
|
284 do |
|
285 curl-config --cflags > /dev/null |
|
286 if [ $? -eq 0 ]; then |
|
287 CFLAGS="$CFLAGS `curl-config --cflags`" |
|
288 else |
|
289 break |
|
290 fi |
|
291 curl-config --ldflags > /dev/null |
|
292 if [ $? -eq 0 ]; then |
|
293 LDFLAGS="$LDFLAGS `curl-config --ldflags`" |
|
294 else |
|
295 break |
|
296 fi |
|
297 which curl-config > /dev/null |
|
298 if [ $? -ne 0 ]; then |
|
299 break |
|
300 fi |
|
301 echo yes |
|
302 return 0 |
|
303 done |
|
304 |
|
305 echo no |
|
306 return 1 |
|
307 } |
|
308 dependency_openssl() |
|
309 { |
|
310 printf "checking for openssl... " |
|
311 # dependency openssl platform="windows" |
|
312 while true |
|
313 do |
|
314 if isnotplatform "windows"; then |
|
315 break |
|
316 fi |
|
317 LDFLAGS="$LDFLAGS -lssl -lcrypto" |
|
318 echo yes |
|
319 return 0 |
|
320 done |
|
321 |
|
322 # dependency openssl platform="macos" |
|
323 while true |
|
324 do |
|
325 if isnotplatform "macos"; then |
|
326 break |
|
327 fi |
|
328 LDFLAGS="$LDFLAGS -framework CoreFoundation" |
|
329 echo yes |
|
330 return 0 |
|
331 done |
|
332 |
|
333 # dependency openssl platform="bsd" |
|
334 while true |
|
335 do |
|
336 if isnotplatform "bsd"; then |
|
337 break |
|
338 fi |
|
339 if isplatform "macos"; then |
|
340 break |
|
341 fi |
|
342 LDFLAGS="$LDFLAGS -lssl -lcrypto" |
|
343 echo yes |
|
344 return 0 |
|
345 done |
|
346 |
|
347 # dependency openssl |
|
348 while true |
|
349 do |
|
350 if [ -z "$PKG_CONFIG" ]; then |
|
351 break |
|
352 fi |
|
353 $PKG_CONFIG openssl |
|
354 if [ $? -ne 0 ] ; then |
|
355 break |
|
356 fi |
|
357 CFLAGS="$CFLAGS `$PKG_CONFIG --cflags openssl`" |
|
358 LDFLAGS="$LDFLAGS `$PKG_CONFIG --libs openssl`" |
|
359 echo yes |
|
360 return 0 |
|
361 done |
|
362 |
|
363 echo no |
|
364 return 1 |
|
365 } |
|
366 dependency_libxml2() |
|
367 { |
|
368 printf "checking for libxml2... " |
|
369 # dependency libxml2 platform="windows" |
|
370 while true |
|
371 do |
|
372 if isnotplatform "windows"; then |
|
373 break |
|
374 fi |
|
375 xml2-config --cflags > /dev/null |
|
376 if [ $? -eq 0 ]; then |
|
377 CFLAGS="$CFLAGS `xml2-config --cflags`" |
|
378 else |
|
379 break |
|
380 fi |
|
381 xml2-config --libs > /dev/null |
|
382 if [ $? -eq 0 ]; then |
|
383 LDFLAGS="$LDFLAGS `xml2-config --libs`" |
|
384 else |
|
385 break |
|
386 fi |
|
387 echo yes |
|
388 return 0 |
|
389 done |
|
390 |
|
391 # dependency libxml2 platform="macos" |
|
392 while true |
|
393 do |
|
394 if isnotplatform "macos"; then |
|
395 break |
|
396 fi |
|
397 xml2-config --cflags > /dev/null |
|
398 if [ $? -eq 0 ]; then |
|
399 CFLAGS="$CFLAGS `xml2-config --cflags`" |
|
400 else |
|
401 break |
|
402 fi |
|
403 xml2-config --libs > /dev/null |
|
404 if [ $? -eq 0 ]; then |
|
405 LDFLAGS="$LDFLAGS `xml2-config --libs`" |
|
406 else |
|
407 break |
|
408 fi |
|
409 echo yes |
|
410 return 0 |
|
411 done |
|
412 |
|
413 # dependency libxml2 |
|
414 while true |
|
415 do |
|
416 if [ -z "$PKG_CONFIG" ]; then |
|
417 break |
|
418 fi |
|
419 $PKG_CONFIG libxml-2.0 |
|
420 if [ $? -ne 0 ] ; then |
|
421 break |
|
422 fi |
|
423 CFLAGS="$CFLAGS `$PKG_CONFIG --cflags libxml-2.0`" |
|
424 LDFLAGS="$LDFLAGS `$PKG_CONFIG --libs libxml-2.0`" |
|
425 echo yes |
|
426 return 0 |
|
427 done |
|
428 |
|
429 # dependency libxml2 |
|
430 while true |
|
431 do |
|
432 xml2-config --cflags > /dev/null |
|
433 if [ $? -eq 0 ]; then |
|
434 CFLAGS="$CFLAGS `xml2-config --cflags`" |
|
435 else |
|
436 break |
|
437 fi |
|
438 xml2-config --libs > /dev/null |
|
439 if [ $? -eq 0 ]; then |
|
440 LDFLAGS="$LDFLAGS `xml2-config --libs`" |
|
441 else |
|
442 break |
|
443 fi |
|
444 echo yes |
|
445 return 0 |
|
446 done |
|
447 |
|
448 echo no |
|
449 return 1 |
|
450 } |
|
451 |
|
452 DEPENDENCIES_FAILED= |
|
453 ERROR=0 |
|
454 # general dependencies |
|
455 CFLAGS= |
|
456 LDFLAGS= |
|
457 while true |
|
458 do |
|
459 while true |
|
460 do |
|
461 |
|
462 LDFLAGS="$LDFLAGS -lpthread" |
|
463 |
|
464 break |
|
465 done |
|
466 |
|
467 break |
|
468 done |
|
469 while true |
|
470 do |
|
471 if isnotplatform "bsd"; then |
|
472 break |
|
473 fi |
|
474 if isplatform "macos"; then |
|
475 break |
|
476 fi |
|
477 while true |
|
478 do |
|
479 |
|
480 CFLAGS="$CFLAGS -I/usr/local/include" |
|
481 LDFLAGS="$LDFLAGS -L/usr/local/lib" |
|
482 |
|
483 break |
|
484 done |
|
485 |
|
486 break |
|
487 done |
|
488 while true |
|
489 do |
|
490 if isnotplatform "macos"; then |
|
491 break |
|
492 fi |
|
493 while true |
|
494 do |
|
495 |
|
496 cat >> $TEMP_DIR/make.mk << __EOF__ |
|
497 OBJ_EXT = .o |
|
498 LIB_EXT = .a |
|
499 |
|
500 __EOF__ |
|
501 |
|
502 break |
|
503 done |
|
504 |
|
505 break |
|
506 done |
|
507 while true |
|
508 do |
|
509 if isnotplatform "unix"; then |
|
510 break |
|
511 fi |
|
512 if isplatform "macos"; then |
|
513 break |
|
514 fi |
|
515 while true |
|
516 do |
|
517 |
|
518 cat >> $TEMP_DIR/make.mk << __EOF__ |
|
519 OBJ_EXT = .o |
|
520 LIB_EXT = .a |
|
521 |
|
522 __EOF__ |
|
523 |
|
524 break |
|
525 done |
|
526 |
|
527 break |
|
528 done |
|
529 |
|
530 # add general dependency flags to config.mk |
|
531 echo >> $TEMP_DIR/config.mk |
|
532 if [ ! -z "${CFLAGS}" ]; then |
|
533 echo "CFLAGS += $CFLAGS" >> $TEMP_DIR/config.mk |
|
534 fi |
|
535 if [ ! -z "${CXXFLAGS}" ]; then |
|
536 echo "CXXFLAGS += $CXXFLAGS" >> $TEMP_DIR/config.mk |
|
537 fi |
|
538 if [ ! -z "${LDFLAGS}" ]; then |
|
539 echo "LDFLAGS += $LDFLAGS" >> $TEMP_DIR/config.mk |
|
540 fi |
|
541 |
|
542 # |
|
543 # OPTION VALUES |
|
544 # |
|
545 |
|
546 # |
|
547 # TARGETS |
|
548 # |
|
549 CFLAGS= |
|
550 CXXFLAGS= |
|
551 LDFLAGS= |
|
552 |
|
553 # Target: dav |
|
554 CFLAGS= |
|
555 LDFLAGS= |
|
556 CXXFLAGS= |
|
557 |
|
558 dependency_curl |
|
559 if [ $? -ne 0 ]; then |
|
560 DEPENDENCIES_FAILED="$DEPENDENCIES_FAILED curl " |
|
561 ERROR=1 |
|
562 fi |
|
563 dependency_libxml2 |
|
564 if [ $? -ne 0 ]; then |
|
565 DEPENDENCIES_FAILED="$DEPENDENCIES_FAILED libxml2 " |
|
566 ERROR=1 |
|
567 fi |
|
568 dependency_openssl |
|
569 if [ $? -ne 0 ]; then |
|
570 DEPENDENCIES_FAILED="$DEPENDENCIES_FAILED openssl " |
|
571 ERROR=1 |
|
572 fi |
|
573 |
|
574 # Features |
|
575 |
|
576 |
|
577 echo >> $TEMP_DIR/config.mk |
|
578 if [ ! -z "${CFLAGS}" ]; then |
|
579 echo "DAV_CFLAGS += $CFLAGS" >> $TEMP_DIR/config.mk |
|
580 fi |
|
581 if [ ! -z "${CXXFLAGS}" ]; then |
|
582 echo "DAV_CXXFLAGS += $CXXFLAGS" >> $TEMP_DIR/config.mk |
|
583 fi |
|
584 if [ ! -z "${LDFLAGS}" ]; then |
|
585 echo "DAV_LDFLAGS += $LDFLAGS" >> $TEMP_DIR/config.mk |
|
586 fi |
|
587 |
|
588 if [ $ERROR -ne 0 ]; then |
|
589 echo |
|
590 echo "Error: Unresolved dependencies" |
|
591 echo $DEPENDENCIES_FAILED |
|
592 rm -Rf $TEMP_DIR |
|
593 exit 1 |
|
594 fi |
|
595 |
|
596 echo "configure finished" |
|
597 echo |
|
598 echo "Build Config:" |
|
599 echo " PREFIX: $PREFIX" |
|
600 echo " TOOLCHAIN: $TOOLCHAIN_NAME" |
|
601 echo |
|
602 cat $TEMP_DIR/config.mk $TEMP_DIR/make.mk > config.mk |
|
603 rm -Rf $TEMP_DIR |
|
604 |
|
605 |