configure

changeset 0
804d8803eade
child 4
d8e8f34e65ee
equal deleted inserted replaced
-1:000000000000 0:804d8803eade
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 Options:
58 --toolkit=(gtk3|gtk2|gtk2legacy|qt5|qt4|motif)
59
60 __EOF__
61 }
62
63 #
64 # parse arguments
65 #
66 for ARG in $@
67 do
68 case "$ARG" in
69 "--prefix="*) PREFIX=${ARG#--prefix=} ;;
70 "--exec-prefix="*) EPREFIX=${ARG#--exec-prefix=} ;;
71 "--bindir="*) BINDIR=${ARG#----bindir=} ;;
72 "--sbindir="*) SBINDIR=${ARG#--sbindir=} ;;
73 "--libdir="*) LIBDIR=${ARG#--libdir=} ;;
74 "--libexecdir="*) LIBEXECDIR=${ARG#--libexecdir=} ;;
75 "--datadir="*) DATADIR=${ARG#--datadir=} ;;
76 "--sysconfdir="*) SYSCONFDIR=${ARG#--sysconfdir=} ;;
77 "--sharedstatedir="*) SHAREDSTATEDIR=${ARG#--sharedstatedir=} ;;
78 "--localstatedir="*) LOCALSTATEDIR=${ARG#--localstatedir=} ;;
79 "--includedir="*) INCLUDEDIR=${ARG#--includedir=} ;;
80 "--infodir="*) INFODIR=${ARG#--infodir=} ;;
81 "--mandir"*) MANDIR=${ARG#--mandir} ;;
82 "--help"*) printhelp; exit 1 ;;
83 "--toolkit="*) OPT_TOOLKIT=${ARG#--toolkit=} ;;
84 "-"*) echo "unknown option: $ARG"; exit 1 ;;
85 esac
86 done
87
88 # set dir variables
89 if [ -z "$BINDIR" ]; then
90 BINDIR=$EPREFIX/bin
91 fi
92 if [ -z "$SBINDIR" ]; then
93 SBINDIR=$EPREFIX/sbin
94 fi
95 if [ -z "$LIBDIR" ]; then
96 LIBDIR=$EPREFIX/lib
97 fi
98 if [ -z "$LIBEXEC" ]; then
99 LIBEXECDIR=$EPREFIX/libexec
100 fi
101 if [ -z "$DATADIR" ]; then
102 DATADIR=$PREFIX/share
103 fi
104 if [ -z "$SYSCONFDIR" ]; then
105 SYSCONFDIR=$PREFIX/etc
106 fi
107 if [ -z "$SHAREDSTATEDIR" ]; then
108 SHAREDSTATEDIR=$PREFIX/com
109 fi
110 if [ -z "$LOCALSTATEDIR" ]; then
111 LOCALSTATEDIR=$PREFIX/var
112 fi
113 if [ -z "$INCLUDEDIR" ]; then
114 INCLUDEDIR=$PREFIX/include
115 fi
116 if [ -z "$INFODIR" ]; then
117 INFODIR=$PREFIX/info
118 fi
119 if [ -z "$MANDIR" ]; then
120 MANDIR=$PREFIX/man
121 fi
122
123 which pkg-config > /dev/null
124 if [ $? -eq 0 ]; then
125 PKG_CONFIG=pkg-config
126 else
127 PKG_CONFIG=false
128 fi
129
130 # Simple uname based platform detection
131 # $PLATFORM is used for platform dependent dependency selection
132 printf "detect platform... "
133 if [ $OS = SunOS ]; then
134 PLATFORM="solaris sunos unix svr4"
135 fi
136 if [ $OS = Linux ]; then
137 PLATFORM="linux unix"
138 fi
139 if [ $OS = FreeBSD ]; then
140 PLATFORM="freebsd bsd unix"
141 fi
142 if [ $OS = Darwin ]; then
143 PLATFORM="macos osx bsd unix"
144 fi
145 echo $OS | grep "MINGW" > /dev/null
146 if [ $? -eq 0 ]; then
147 PLATFORM="windows mingw"
148 fi
149
150 if [ -z "$PLATFORM" ]; then
151 PLATFORM="unix"
152 fi
153
154 for p in $PLATFORM
155 do
156 PLATFORM_NAME=$p
157 break
158 done
159 echo $PLATFORM_NAME
160
161 isplatform()
162 {
163 for p in $PLATFORM
164 do
165 if [ $p = $1 ]; then
166 return 0
167 fi
168 done
169 return 1
170 }
171 isnotplatform()
172 {
173 for p in $PLATFORM
174 do
175 if [ $p = $1 ]; then
176 return 1
177 fi
178 done
179 return 0
180 }
181
182 # generate config.mk and config.h
183 cat > $TEMP_DIR/config.mk << __EOF__
184 #
185 # config.mk generated by configure
186 #
187
188 # general vars
189
190 PREFIX=$PREFIX
191 EPREFIX=$EPREFIX
192
193 BINDIR=$BINDIR
194 SBINDIR=$SBINDIR
195 LIBDIR=$LIBDIR
196 LIBEXECDIR=$LIBEXECDIR
197 DATADIR=$DATADIR
198 SYSCONFDIR=$SYSCONFDIR
199 SHAREDSTATEDIR=$SHAREDSTATEDIR
200 LOCALSTATEDIR=$LOCALSTATEDIR
201 INCLUDEDIR=$INCLUDEDIR
202 INFODIR=$INFODIR
203 MANDIR=$MANDIR
204
205 __EOF__
206
207 echo > $TEMP_DIR/make.mk
208
209 ENV_CFLAGS=$CFLAGS
210 ENV_LDFLAGS=$LDFLAGS
211 ENV_CXXFLAGS=$CXXFLAGS
212
213 # Toolchain detection
214 # this will insert make vars to config.mk
215 . make/toolchain.sh
216
217 # add user specified flags to config.mk
218 echo >> $TEMP_DIR/config.mk
219 if [ ! -z "${ENV_CFLAGS}" ]; then
220 echo "CFLAGS += $ENV_CFLAGS" >> $TEMP_DIR/config.mk
221 fi
222 if [ ! -z "${ENV_CXXFLAGS}" ]; then
223 echo "CXXFLAGS += $ENV_CXXFLAGS" >> $TEMP_DIR/config.mk
224 fi
225 if [ ! -z "${ENV_LDFLAGS}" ]; then
226 echo "LDFLAGS += $ENV_LDFLAGS" >> $TEMP_DIR/config.mk
227 fi
228
229 #
230 # DEPENDENCIES
231 #
232
233 dependency_qt4()
234 {
235 printf "checking for qt4... "
236 # dependency qt4
237 while true
238 do
239 qmake-qt4 -o - /dev/null | grep DEFINES\ > /dev/null
240 if [ $? -eq 0 ]; then
241 CFLAGS="$CFLAGS `qmake-qt4 -o - /dev/null | grep DEFINES\ `"
242 else
243 break
244 fi
245 qmake-qt4 -o - /dev/null | grep INCPATH\ > /dev/null
246 if [ $? -eq 0 ]; then
247 CFLAGS="$CFLAGS `qmake-qt4 -o - /dev/null | grep INCPATH\ `"
248 else
249 break
250 fi
251 > /dev/null
252 if [ $? -eq 0 ]; then
253 LDFLAGS="$LDFLAGS ``"
254 else
255 break
256 fi
257 which qmake-qt4 > /dev/null
258 if [ $? -ne 0 ]; then
259 break
260 fi
261 echo yes
262 return 0
263 done
264
265 echo no
266 return 1
267 }
268 dependency_gtk2legacy()
269 {
270 printf "checking for gtk2legacy... "
271 # dependency gtk2legacy
272 while true
273 do
274 if [ -z "$PKG_CONFIG" ]; then
275 break
276 fi
277 $PKG_CONFIG gtk+-2.0
278 if [ $? -ne 0 ] ; then
279 break
280 fi
281 CFLAGS="$CFLAGS `$PKG_CONFIG --cflags gtk+-2.0`"
282 LDFLAGS="$LDFLAGS `$PKG_CONFIG --libs gtk+-2.0`"
283 CFLAGS="$CFLAGS -DUI_GTK2 -DUI_GTK2LEGACY"
284 LDFLAGS="$LDFLAGS -lpthread"
285 echo yes
286 return 0
287 done
288
289 echo no
290 return 1
291 }
292 dependency_qt5()
293 {
294 printf "checking for qt5... "
295 # dependency qt5
296 while true
297 do
298 qmake-qt5 -o - /dev/null | grep DEFINES\ > /dev/null
299 if [ $? -eq 0 ]; then
300 CFLAGS="$CFLAGS `qmake-qt5 -o - /dev/null | grep DEFINES\ `"
301 else
302 break
303 fi
304 qmake-qt5 -o - /dev/null | grep INCPATH\ > /dev/null
305 if [ $? -eq 0 ]; then
306 CFLAGS="$CFLAGS `qmake-qt5 -o - /dev/null | grep INCPATH\ `"
307 else
308 break
309 fi
310 > /dev/null
311 if [ $? -eq 0 ]; then
312 LDFLAGS="$LDFLAGS ``"
313 else
314 break
315 fi
316 which qmake-qt5 > /dev/null
317 if [ $? -ne 0 ]; then
318 break
319 fi
320 echo yes
321 return 0
322 done
323
324 echo no
325 return 1
326 }
327 dependency_gtk2()
328 {
329 printf "checking for gtk2... "
330 # dependency gtk2
331 while true
332 do
333 if [ -z "$PKG_CONFIG" ]; then
334 break
335 fi
336 $PKG_CONFIG gtk+-2.0
337 if [ $? -ne 0 ] ; then
338 break
339 fi
340 CFLAGS="$CFLAGS `$PKG_CONFIG --cflags gtk+-2.0`"
341 LDFLAGS="$LDFLAGS `$PKG_CONFIG --libs gtk+-2.0`"
342 CFLAGS="$CFLAGS -DUI_GTK2"
343 LDFLAGS="$LDFLAGS -lpthread"
344 pkg-config --atleast-version=2.20 gtk+-2.0 > /dev/null
345 if [ $? -ne 0 ]; then
346 break
347 fi
348 echo yes
349 return 0
350 done
351
352 echo no
353 return 1
354 }
355 dependency_gtk3()
356 {
357 printf "checking for gtk3... "
358 # dependency gtk3
359 while true
360 do
361 if [ -z "$PKG_CONFIG" ]; then
362 break
363 fi
364 $PKG_CONFIG gtk+-3.0
365 if [ $? -ne 0 ] ; then
366 break
367 fi
368 CFLAGS="$CFLAGS `$PKG_CONFIG --cflags gtk+-3.0`"
369 LDFLAGS="$LDFLAGS `$PKG_CONFIG --libs gtk+-3.0`"
370 CFLAGS="$CFLAGS -DUI_GTK3"
371 LDFLAGS="$LDFLAGS -lpthread"
372 echo yes
373 return 0
374 done
375
376 echo no
377 return 1
378 }
379 dependency_motif()
380 {
381 printf "checking for motif... "
382 # dependency motif
383 while true
384 do
385 CFLAGS="$CFLAGS -DUI_MOTIF"
386 LDFLAGS="$LDFLAGS -lXm -lXt -lX11 -lpthread"
387 echo yes
388 return 0
389 done
390
391 echo no
392 return 1
393 }
394 dependency_wpf()
395 {
396 printf "checking for wpf... "
397 # dependency wpf platform="windows"
398 while true
399 do
400 if isnotplatform "windows"; then
401 break
402 fi
403 CFLAGS="$CFLAGS -DUI_WPF"
404 echo yes
405 return 0
406 done
407
408 echo no
409 return 1
410 }
411 dependency_cocoa()
412 {
413 printf "checking for cocoa... "
414 # dependency cocoa platform="macos"
415 while true
416 do
417 if isnotplatform "macos"; then
418 break
419 fi
420 CFLAGS="$CFLAGS -DUI_COCOA"
421 LDFLAGS="$LDFLAGS -lobjc -framework Cocoa"
422 echo yes
423 return 0
424 done
425
426 echo no
427 return 1
428 }
429
430 DEPENDENCIES_FAILED=
431 ERROR=0
432 # general dependencies
433 CFLAGS=
434 LDFLAGS=
435 while true
436 do
437 if isnotplatform "macos"; then
438 break
439 fi
440 while true
441 do
442
443 cat >> $TEMP_DIR/make.mk << __EOF__
444 OBJ_EXT = o
445 LIB_EXT = a
446 PACKAGE_SCRIPT = package_osx.sh
447
448 __EOF__
449
450 break
451 done
452
453 break
454 done
455 while true
456 do
457 if isnotplatform "unix"; then
458 break
459 fi
460 if isplatform "macos"; then
461 break
462 fi
463 while true
464 do
465
466 cat >> $TEMP_DIR/make.mk << __EOF__
467 OBJ_EXT = o
468 LIB_EXT = a
469 PACKAGE_SCRIPT = package_unix.sh
470
471 __EOF__
472
473 break
474 done
475
476 break
477 done
478
479 # add general dependency flags to config.mk
480 echo >> $TEMP_DIR/config.mk
481 if [ ! -z "${CFLAGS}" ]; then
482 echo "CFLAGS += $CFLAGS" >> $TEMP_DIR/config.mk
483 fi
484 if [ ! -z "${CXXFLAGS}" ]; then
485 echo "CXXFLAGS += $CXXFLAGS" >> $TEMP_DIR/config.mk
486 fi
487 if [ ! -z "${LDFLAGS}" ]; then
488 echo "LDFLAGS += $LDFLAGS" >> $TEMP_DIR/config.mk
489 fi
490
491 #
492 # OPTION VALUES
493 #
494 checkopt_toolkit_gtk3()
495 {
496 VERR=0
497 dependency_gtk3
498 if [ $? -ne 0 ]; then
499 VERR=1
500 fi
501 if [ $VERR -ne 0 ]; then
502 return 1
503 fi
504 cat >> $TEMP_DIR/make.mk << __EOF__
505 TOOLKIT = gtk
506 GTKOBJ = draw_cairo.o
507
508 __EOF__
509 return 0
510 }
511 checkopt_toolkit_gtk2()
512 {
513 VERR=0
514 dependency_gtk2
515 if [ $? -ne 0 ]; then
516 VERR=1
517 fi
518 if [ $VERR -ne 0 ]; then
519 return 1
520 fi
521 cat >> $TEMP_DIR/make.mk << __EOF__
522 TOOLKIT = gtk
523 GTKOBJ = draw_cairo.o
524
525 __EOF__
526 return 0
527 }
528 checkopt_toolkit_gtk2legacy()
529 {
530 VERR=0
531 dependency_gtk2legacy
532 if [ $? -ne 0 ]; then
533 VERR=1
534 fi
535 if [ $VERR -ne 0 ]; then
536 return 1
537 fi
538 cat >> $TEMP_DIR/make.mk << __EOF__
539 TOOLKIT = gtk
540 GTKOBJ = draw_gdk.o
541
542 __EOF__
543 return 0
544 }
545 checkopt_toolkit_qt5()
546 {
547 VERR=0
548 dependency_qt5
549 if [ $? -ne 0 ]; then
550 VERR=1
551 fi
552 if [ $VERR -ne 0 ]; then
553 return 1
554 fi
555 cat >> $TEMP_DIR/make.mk << __EOF__
556 TOOLKIT = qt
557 LD = $(CXX)
558
559 __EOF__
560 return 0
561 }
562 checkopt_toolkit_qt4()
563 {
564 VERR=0
565 dependency_qt4
566 if [ $? -ne 0 ]; then
567 VERR=1
568 fi
569 if [ $VERR -ne 0 ]; then
570 return 1
571 fi
572 cat >> $TEMP_DIR/make.mk << __EOF__
573 TOOLKIT = qt
574 LD = $(CXX)
575
576 __EOF__
577 return 0
578 }
579 checkopt_toolkit_motif()
580 {
581 VERR=0
582 dependency_motif
583 if [ $? -ne 0 ]; then
584 VERR=1
585 fi
586 if [ $VERR -ne 0 ]; then
587 return 1
588 fi
589 cat >> $TEMP_DIR/make.mk << __EOF__
590 TOOLKIT = motif
591
592 __EOF__
593 return 0
594 }
595
596 #
597 # TARGETS
598 #
599 CFLAGS=
600 CXXFLAGS=
601 LDFLAGS=
602
603 # Target: tk
604 CFLAGS=
605 LDFLAGS=
606 CXXFLAGS=
607
608
609 # Features
610
611 # Option: --toolkit
612 if [ -z $OPT_TOOLKIT ]; then
613 SAVED_ERROR=$ERROR
614 SAVED_DEPENDENCIES_FAILED=$DEPENDENCIES_FAILED
615 ERROR=0
616 while true
617 do
618 if isplatform "windows"; then
619 checkopt_toolkit_wpf
620 if [ $? -eq 0 ]; then
621 echo " toolkit: wpf" >> $TEMP_DIR/options
622 ERROR=0
623 break
624 fi
625 fi
626 if isplatform "macos"; then
627 checkopt_toolkit_cocoa
628 if [ $? -eq 0 ]; then
629 echo " toolkit: cocoa" >> $TEMP_DIR/options
630 ERROR=0
631 break
632 fi
633 fi
634 checkopt_toolkit_gtk3
635 if [ $? -eq 0 ]; then
636 echo " toolkit: gtk3" >> $TEMP_DIR/options
637 ERROR=0
638 break
639 fi
640 checkopt_toolkit_qt5
641 if [ $? -eq 0 ]; then
642 echo " toolkit: qt5" >> $TEMP_DIR/options
643 ERROR=0
644 break
645 fi
646 checkopt_toolkit_gtk2
647 if [ $? -eq 0 ]; then
648 echo " toolkit: gtk2" >> $TEMP_DIR/options
649 ERROR=0
650 break
651 fi
652 checkopt_toolkit_qt4
653 if [ $? -eq 0 ]; then
654 echo " toolkit: qt4" >> $TEMP_DIR/options
655 ERROR=0
656 break
657 fi
658 checkopt_toolkit_motif
659 if [ $? -eq 0 ]; then
660 echo " toolkit: motif" >> $TEMP_DIR/options
661 ERROR=0
662 break
663 fi
664 break
665 done
666 if [ $ERROR -ne 0 ]; then
667 SAVED_ERROR=1
668 fi
669 ERROR=$SAVED_ERROR
670 DEPENDENCIES_FAILED=$SAVED_DEPENDENCIES_FAILED=
671 else
672 if false; then
673 false
674 elif [ $OPT_TOOLKIT = "gtk3" ]; then
675 echo " toolkit: $OPT_TOOLKIT" >> $TEMP_DIR/options
676 checkopt_toolkit_gtk3
677 if [ $? -ne 0 ]; then
678 ERROR=1
679 fi
680 elif [ $OPT_TOOLKIT = "gtk2" ]; then
681 echo " toolkit: $OPT_TOOLKIT" >> $TEMP_DIR/options
682 checkopt_toolkit_gtk2
683 if [ $? -ne 0 ]; then
684 ERROR=1
685 fi
686 elif [ $OPT_TOOLKIT = "gtk2legacy" ]; then
687 echo " toolkit: $OPT_TOOLKIT" >> $TEMP_DIR/options
688 checkopt_toolkit_gtk2legacy
689 if [ $? -ne 0 ]; then
690 ERROR=1
691 fi
692 elif [ $OPT_TOOLKIT = "qt5" ]; then
693 echo " toolkit: $OPT_TOOLKIT" >> $TEMP_DIR/options
694 checkopt_toolkit_qt5
695 if [ $? -ne 0 ]; then
696 ERROR=1
697 fi
698 elif [ $OPT_TOOLKIT = "qt4" ]; then
699 echo " toolkit: $OPT_TOOLKIT" >> $TEMP_DIR/options
700 checkopt_toolkit_qt4
701 if [ $? -ne 0 ]; then
702 ERROR=1
703 fi
704 elif [ $OPT_TOOLKIT = "motif" ]; then
705 echo " toolkit: $OPT_TOOLKIT" >> $TEMP_DIR/options
706 checkopt_toolkit_motif
707 if [ $? -ne 0 ]; then
708 ERROR=1
709 fi
710 fi
711 fi
712
713 echo >> $TEMP_DIR/config.mk
714 if [ ! -z "${CFLAGS}" ]; then
715 echo "TK_CFLAGS += $CFLAGS" >> $TEMP_DIR/config.mk
716 fi
717 if [ ! -z "${CXXFLAGS}" ]; then
718 echo "TK_CXXFLAGS += $CXXFLAGS" >> $TEMP_DIR/config.mk
719 fi
720 if [ ! -z "${LDFLAGS}" ]; then
721 echo "TK_LDFLAGS += $LDFLAGS" >> $TEMP_DIR/config.mk
722 fi
723
724 if [ $ERROR -ne 0 ]; then
725 echo
726 echo "Error: Unresolved dependencies"
727 echo $DEPENDENCIES_FAILED
728 rm -Rf $TEMP_DIR
729 exit 1
730 fi
731
732 echo "configure finished"
733 echo
734 echo "Build Config:"
735 echo " PREFIX: $PREFIX"
736 echo " TOOLCHAIN: $TOOLCHAIN_NAME"
737 echo "Options:"
738 cat $TEMP_DIR/options
739 echo
740 cat $TEMP_DIR/config.mk $TEMP_DIR/make.mk > config.mk
741 rm -Rf $TEMP_DIR
742
743

mercurial