]> err.no Git - sope/blob - configure
Add libxml2-dev to libsope-xml4.7-dev deps
[sope] / configure
1 #!/bin/bash
2
3 #
4 # Note: When adding make options to this script, ensure that the source still
5 #       compiles without those options! (and just with GNUstep.sh being
6 #       sourced)
7 #       We do not want to force people to run configure.
8 #
9
10 # ******************** variables ****************
11
12 CFG_ARGS="$0 $1 $2 $3 $4 $5 $6 $7 $8 $9"
13
14 ARG_BEQUIET=0
15 ARG_NOCREATE=0
16 ARG_PREFIX=""
17 ARG_FRAMEWORK_DIR=""
18 ARG_GSMAKE="$GNUSTEP_MAKEFILES"
19 ARG_CFGMAKE="$PWD/config.make"
20 ARG_WITH_GNUSTEP=0
21 ARG_WITH_DEBUG=1
22 ARG_WITH_STRIP=1
23
24 DARG_GNUSTEP_SH="$ARG_GSMAKE/GNUstep.sh"
25 DARG_IS_FHS=1
26
27 SOPE_SRCDIR="$PWD" # TODO: rather use location of configure (using basename)
28 NGSTREAMS_DIR="${SOPE_SRCDIR}/sope-core/NGStreams"
29 GSTEPMAKE_SRCDIR="${SOPE_SRCDIR}/gnustep-make"
30 INTERNAL_MAKEDIR="${SOPE_SRCDIR}/.gsmake"
31 USES_INTERNAL_MAKE=no
32
33 # TODO: add pg_config, mysql_config etc!
34 LINK_SYSLIBDIRS="-L/usr/local/pgsql/lib -L/usr/local/lib -L/usr/lib"
35
36 # ******************** usage ********************
37
38 function usage() {
39   cat <<_ACEOF
40 \`configure' configures a GNUstep-make based sourcetree for installation.
41
42 Usage: $0 [OPTION]...
43
44 Note: You do not need to configure this source tree, as another option
45       just ensure that the GNUstep.sh of your GNUstep make installation
46       is properly sourced prior running make.
47
48 Configuration:
49   -h, --help              display this help and exit
50   -q, --quiet, --silent   do not print \`checking...' messages
51   -n, --no-create         do not create output files
52
53 Installation directories:
54   --prefix=PREFIX         install files in PREFIX [/usr/local]
55   --frameworks=DIR        build frameworks and install in DIR
56   --gsmake=PATH           path to gnustep-make tree
57   --configmake=PATH       path to the config file being created
58   --with-gnustep          install in GNUstep tree
59   --enable-debug          turn on debugging and compile time warnings
60   --enable-strip          turn on stripping of debug symbols
61
62 _ACEOF
63
64   exit 0;
65 }
66
67 # ******************** running ********************
68
69 function printParas() {
70   echo "Configuration:"
71   if test $ARG_BEQUIET  = 1; then echo "  will be quite.";  fi
72   if test $ARG_NOCREATE = 1; then echo "  won't create files"; fi
73   if test "x$ARG_FRAMEWORK_DIR" != "x"; then
74     echo "  FHS:    install in frameworks directory"; 
75   elif test $DARG_IS_FHS = 1;  then
76     echo "  FHS:    install in FHS root"; 
77   else
78     echo "  FHS:    install in GNUstep tree"; 
79   fi
80
81   if test $ARG_WITH_DEBUG = 1; then 
82     echo "  debug:  yes";
83   else
84     echo "  debug:  no";
85   fi
86   if test $ARG_WITH_STRIP = 1; then 
87     echo "  strip:  yes";
88   else
89     echo "  strip:  no";
90   fi
91   
92   echo "  prefix:     $ARG_PREFIX"
93   echo "  frameworks: $ARG_FRAMEWORK_DIR"
94   echo "  gstep:      $ARG_GSMAKE"
95   echo "  config:     $ARG_CFGMAKE"
96   echo "  script:     $DARG_GNUSTEP_SH"
97   echo ""
98 }
99
100 function warnOnFHSPrefix() {
101   cat <<_ACEOFWARN
102 Warning: you are configuring for a non standard FHS style prefix.
103          prefix: $ARG_PREFIX
104
105 Some code in SOPE only looks in /usr and /usr/local for resources and is
106 therefore incompatible with arbitary install pathes.
107
108 If you want to have the flexibility of installation in arbitary pathes just
109 configure GNUstep-make and source the GNUstep.sh script prior executing tools
110 to ensure a proper environment.
111 All SOPE based code is completely relocatable when being used in a GNUstep
112 environment.
113
114 _ACEOFWARN
115 }
116
117 function setupInternalGSMake() {
118   if test -f ${INTERNAL_MAKEDIR}/Library/Makefiles/GNUstep.sh; then
119     ARG_GSMAKE="${INTERNAL_MAKEDIR}/Library/Makefiles/"
120     ARG_IS_FHS=1
121     DARG_IS_FHS=1
122     ARG_WITH_GNUSTEP=0
123     USES_INTERNAL_MAKE=yes
124     if test "x$ARG_PREFIX" = "x"; then
125       ARG_PREFIX="/usr/local/"
126     fi
127   elif test -d gnustep-make; then
128     ENABLE_PCH_OPT=""
129     SETUP_COMBO="gnu-fd-nil"
130     SETUP_LOGNAME="config-gstepmake.log"
131     if test -d /Developer/Applications/Xcode.app; then
132       # rather weird OSX test, right? ;->
133       SETUP_COMBO="apple-apple-nil"
134       ENABLE_PCH_OPT="--enable-pch"
135     fi
136     pregsmdir="$PWD"
137     
138     echo -n "configuring builtin gnustep-make environment (${SETUP_LOGNAME}) .."
139     
140     cd "$GSTEPMAKE_SRCDIR"
141     ./configure >${pregsmdir}/${SETUP_LOGNAME} \
142       ${ENABLE_PCH_OPT} \
143       --prefix="${INTERNAL_MAKEDIR}" \
144       --with-config-file="${INTERNAL_MAKEDIR}/GNUstep.conf" \
145       --with-system-root="${INTERNAL_MAKEDIR}" \
146       --with-network-root="${INTERNAL_MAKEDIR}" \
147       --with-local-root="${INTERNAL_MAKEDIR}" \
148       --with-user-root="${INTERNAL_MAKEDIR}" \
149       --with-library-combo="${SETUP_COMBO}"
150
151     echo -n ".. install .."
152     make install >>${pregsmdir}/${SETUP_LOGNAME}
153     
154     ARG_GSMAKE="${INTERNAL_MAKEDIR}/Library/Makefiles/"
155     ARG_IS_FHS=1
156     DARG_IS_FHS=1
157     ARG_WITH_GNUSTEP=0
158     USES_INTERNAL_MAKE=yes
159     if test "x$ARG_PREFIX" = "x"; then
160       ARG_PREFIX="/usr/local/"
161     fi
162     
163     cd "$pregsmdir"
164     if test -f $ARG_GSMAKE/GNUstep.sh; then
165       echo ".. done (log in ${SETUP_LOGNAME})."
166     else
167       echo "error: failed to setup embedded gnustep-make sources!"
168       tail ${pregsmdir}/${SETUP_LOGNAME}
169       exit 1
170     fi
171   else
172     echo "error: did not find embedded gnustep-make sources!"
173     exit 1
174   fi
175 }
176
177 function validateGNUstepArgs() {
178   # GNUstep make
179   if test "x$ARG_GSMAKE" = "x"; then
180     if test -f $HOME/OGoRoot/Library/Makefiles/GNUstep.sh; then
181       ARG_GSMAKE="$HOME/OGoRoot/Library/Makefiles/"
182     elif test -f $HOME/GNUstep/Library/Makefiles/GNUstep.sh; then
183       ARG_GSMAKE="$HOME/GNUstep/Library/Makefiles/"
184     elif test -f /usr/GNUstep/System/Library/Makefiles/GNUstep.sh; then
185       ARG_GSMAKE="/usr/GNUstep/System/Library/Makefiles/"
186     else
187       setupInternalGSMake;
188     fi
189     DARG_GNUSTEP_SH="$ARG_GSMAKE/GNUstep.sh"
190   elif test -d $ARG_GSMAKE; then
191     if test -f $ARG_GSMAKE/GNUstep.sh; then
192       DARG_GNUSTEP_SH="$ARG_GSMAKE/GNUstep.sh"
193     elif test -f $ARG_GSMAKE/Library/Makefiles/GNUstep.sh; then
194       ARG_GSMAKE="$ARG_GSMAKE/Library/Makefiles"
195       DARG_GNUSTEP_SH="$ARG_GSMAKE/GNUstep.sh"
196     else
197       echo "error: specified directory contains no GNUstep.sh: $ARG_GSMAKE"
198       exit 1
199     fi
200   else
201     echo "error: specified GNUstep make tree does not exist: $ARG_GSMAKE"
202     exit 1
203   fi
204 }
205
206 function setupAppleArgs() {
207   ARG_WITH_STRIP=0
208   if test "x${USES_INTERNAL_MAKE}" = "no"; then
209     ARG_WITH_GNUSTEP=1
210   fi
211   
212   # no reason to print a warning?
213   #if test "x${xLIBRARY_COMBO}" != "xapple-apple-nil"; then
214   #  if test "x${LIBRARY_COMBO}" != "xapple-apple-apple"; then
215   #    echo "WARNING: detected MacOSX GNUstep setup: ${LIBRARY_COMBO}"
216   #    echo ""
217   #  fi
218   #fi
219 }
220
221 function validateArgs() {
222   # validate prefix (could be better?)
223   case "x$ARG_PREFIX" in
224     "x/usr/local"|"x/usr/local/")
225         DARG_IS_FHS=1;
226         ;;
227     "x/usr"|"x/usr/")
228         DARG_IS_FHS=1;
229         ;;
230     "x$GNUSTEP_USER_ROOT"|"x$GNUSTEP_LOCAL_ROOT"|"x$GNUSTEP_SYSTEM_ROOT")
231         DARG_IS_FHS=0;
232         ARG_WITH_GNUSTEP=1;
233         ;;
234     "x")
235         if test $ARG_WITH_GNUSTEP = 1; then
236           DARG_IS_FHS=0;
237           ARG_PREFIX="$GNUSTEP_LOCAL_ROOT"
238           if test $ARG_BEQUIET != 1; then
239             echo "Note: will install in GNUSTEP_LOCAL_ROOT: $ARG_PREFIX"
240             echo ""
241           fi
242         elif test "x$ARG_FRAMEWORK_DIR" != "x"; then
243           DARG_IS_FHS=0;
244           ARG_PREFIX="$ARG_FRAMEWORK_DIR"
245           echo "Note: will install in frameworks location: $ARG_PREFIX"
246           echo ""
247         else
248           DARG_IS_FHS=1;
249           ARG_PREFIX="/usr/local/"
250           echo "Note: will install in default location: $ARG_PREFIX"
251           echo ""
252         fi
253         ;;
254     *)
255         if test $ARG_WITH_GNUSTEP = 1; then
256           echo "error: specified --with-gnustep, but specified prefix is not"
257           echo "       a GNUstep root: '$ARG_PREFIX'"
258           exit 1
259         else
260           if test $ARG_BEQUIET != 1; then
261             warnOnFHSPrefix;
262           fi
263           DARG_IS_FHS=1;
264         fi
265         ;;
266   esac
267   
268   if test $ARG_WITH_GNUSTEP = 1; then
269     if test $DARG_IS_FHS = 1; then
270       echo "error: configured for FHS root _and_ GNUstep tree. Choose one!"
271       exit 1
272     fi
273   fi
274 }
275
276 function printGNUstepSetup() {
277   echo "GNUstep environment:"
278   echo "  system: ${GNUSTEP_SYSTEM_ROOT}"
279   echo "  local:  ${GNUSTEP_LOCAL_ROOT}"
280   echo "  user:   ${GNUSTEP_USER_ROOT}"
281   echo "  path:   ${GNUSTEP_PATHLIST}"
282   echo "  flat:   ${GNUSTEP_FLATTENED}"
283   echo "  arch:   ${GNUSTEP_HOST}"
284   echo "  combo:  ${LIBRARY_COMBO}"
285   echo ""
286 }
287
288 function cfgwrite() {
289   echo "$1" >> $ARG_CFGMAKE
290 }
291
292 function genConfigMake() {
293   # we ignore the following vars also patches by gstep-make:
294   #   PATH
295   #   DYLD_LIBRARY_PATH
296   #   GUILE_LOAD_PATH
297   #   CLASSPATH
298   
299   if test $ARG_BEQUIET != 1; then
300     echo "creating: $ARG_CFGMAKE"
301   fi
302   
303   echo "# GNUstep environment configuration" > $ARG_CFGMAKE
304   cfgwrite "#   created by: '$CFG_ARGS'"
305   cfgwrite ""
306   
307   cfgwrite "# Note: you can override any option as a 'make' parameter, eg:"
308   cfgwrite "#         make debug=yes"
309   cfgwrite ""
310   
311   #cfgwrite "# print on the cmdline that this file is being used"
312   #cfgwrite "all :: "
313   #cfgwrite "   @echo Local GNUstep config.make is active"
314   #cfgwrite ""
315   
316   # TODO: should be also write a GNUSTEP_INSTALLATION_DIR / BUNDLE_INSTALL_DIR?
317   
318   
319   if test "x$ARG_FRAMEWORK_DIR" != "x"; then
320     cfgwrite "# configured to install in Frameworks directory"
321     cfgwrite "FRAMEWORK_INSTALL_DIR:=${ARG_FRAMEWORK_DIR}"
322     cfgwrite "frameworks=yes"
323     cfgwrite ""
324   elif test $DARG_IS_FHS = 1; then
325     cfgwrite "# configured for FHS install"
326     cfgwrite "FHS_INSTALL_ROOT:=$ARG_PREFIX"
327     cfgwrite ""
328   else
329     cfgwrite "# configured for GNUstep install"
330   fi
331   
332   if test $ARG_WITH_DEBUG = 1; then
333     cfgwrite "# configured to produce debugging code";
334     cfgwrite "debug:=yes"
335   else
336     cfgwrite "# configured to produce non-debugging code";
337     cfgwrite "debug:=no"
338   fi
339   cfgwrite ""
340   
341   if test $ARG_WITH_STRIP = 1; then
342     cfgwrite "# configured to produce stripped code";
343     cfgwrite "strip:=yes"
344   else
345     cfgwrite "# configured not to strip code";
346     cfgwrite "strip:=no"
347   fi
348   cfgwrite ""
349
350   cfgwrite "# enforce shared libraries";
351   cfgwrite "shared:=yes"
352   cfgwrite ""
353   
354   cfgwrite "# GNUstep environment variables:";
355   for i in `env | grep GNUSTEP_ | sort`; do
356     MAKE_ASSI="`echo $i | sed s/=/:=/`"
357     cfgwrite "${MAKE_ASSI}";
358   done
359   cfgwrite "LIBRARY_COMBO=$LIBRARY_COMBO"
360   cfgwrite ""
361   
362   # Note: GNUSTEP_TARGET_CPU is not yet available (set by common.make), so we
363   #       only have environment variables
364   # Note: we can't set SYSTEM_LIB_DIR in this location, it gets overridden by
365   #       common.make
366   cfgwrite "ifeq (\$(findstring _64, \$(GNUSTEP_HOST_CPU)), _64)"
367   cfgwrite "CONFIGURE_64BIT:=yes"
368   cfgwrite "CGS_LIBDIR_NAME:=lib64"
369   cfgwrite "else"
370   cfgwrite "CGS_LIBDIR_NAME:=lib"
371   cfgwrite "endif"
372
373   cfgwrite "ifneq (\$(FHS_INSTALL_ROOT),)"
374   cfgwrite "CONFIGURE_FHS_INSTALL_LIBDIR:=\$(FHS_INSTALL_ROOT)/\$(CGS_LIBDIR_NAME)/"
375   cfgwrite "CONFIGURE_SYSTEM_LIB_DIR += -L\$(CONFIGURE_FHS_INSTALL_LIBDIR)"
376   cfgwrite "endif"
377   cfgwrite "CONFIGURE_SYSTEM_LIB_DIR += -L/usr/\$(CGS_LIBDIR_NAME)/"
378   
379   cfgwrite "# avoid a gstep-make warning"
380   cfgwrite "PATH:=\$(GNUSTEP_SYSTEM_ROOT)/Tools:\$(PATH)"
381 }
382
383 function checkLinking() {
384   # library-name => $1, type => $2
385   local oldpwd=$PWD
386   local tmpdir=".configure-test-$$"
387   
388   mkdir $tmpdir
389   cd $tmpdir
390   cp ../maintenance/dummytool.c .
391   
392   tmpmake="GNUmakefile"
393   echo  >$tmpmake "include ../config.make"
394   echo >>$tmpmake "include \$(GNUSTEP_MAKEFILES)/common.make"
395   echo >>$tmpmake "CTOOL_NAME           := linktest"
396   echo >>$tmpmake "linktest_C_FILES := dummytool.c"
397   echo >>$tmpmake "linktest_TOOL_LIBS  += -l$1"
398   echo >>$tmpmake "SYSTEM_LIB_DIR += \$(CONFIGURE_SYSTEM_LIB_DIR)"
399   echo >>$tmpmake "SYSTEM_LIB_DIR      += ${LINK_SYSLIBDIRS}"
400   echo >>$tmpmake "include \$(GNUSTEP_MAKEFILES)/ctool.make"
401   
402   make -s messages=yes -f $tmpmake linktest >out.log 2>err.log
403   LINK_RESULT=$?
404   
405   if test $LINK_RESULT = 0; then
406     echo "$2 library found: $1"
407     cfgwrite "HAS_LIBRARY_$1=yes"
408   else
409     if test "x$2" = "xrequired"; then
410       echo "failed to link $2 library: $1"
411       rm ../config.make
412       exit 1
413     else
414       echo "failed to link $2 library: $1"
415       cfgwrite "HAS_LIBRARY_$1=no"
416     fi
417   fi
418   
419   cd $oldpwd
420   rm -rf $tmpdir
421 }
422
423 function checkDependencies() {
424   cfgwrite ""
425   cfgwrite "# library dependencies"
426   checkLinking "xml2"        optional;
427   checkLinking "ldap"        optional;
428   checkLinking "ssl"         required; # TODO: make optional
429   checkLinking "pq"          optional;
430   checkLinking "sqlite3"     optional;
431   checkLinking "mysqlclient" optional;
432 }
433
434 function runIt() {
435   if test $ARG_BEQUIET != 1; then
436     printParas;
437   fi
438   
439   if test $ARG_NOCREATE = 1; then 
440     if test $ARG_BEQUIET != 1; then
441       echo "not creating the config file ...";
442     fi
443   else
444     genConfigMake;
445     checkDependencies;
446     
447     if test -x $NGSTREAMS_DIR/configure; then
448       if test $ARG_BEQUIET != 1; then
449         echo -n "configuring NGStreams library .."
450         old="$PWD"
451         cd $NGSTREAMS_DIR
452         ./configure >$old/config-NGStreams.log
453         cd $old
454         echo ".. done (log in config-NGStreams.log)."
455       fi
456     fi
457   fi
458 }
459
460 # ******************** options ********************
461
462 function extractFuncValue() {
463   VALUE="`echo "$1" | sed "s/[^=]*=//g"`"
464 }
465
466 function processOption() {
467   case "x$1" in
468     "x--help"|"x-h")
469         usage;
470         ;;
471     "x--quiet"|"x--silent"|"x-q") ARG_BEQUIET=1;  ;;
472     "x--no-create"|"x-n")         ARG_NOCREATE=1; ;;
473     x--prefix=*)
474         extractFuncValue $1;
475         ARG_PREFIX="$VALUE";
476         ;;
477     x--frameworks=*)
478         extractFuncValue $1;
479         ARG_FRAMEWORK_DIR="$VALUE";
480         ;;
481     x--gsmake=*)
482         extractFuncValue $1;
483         ARG_GSMAKE="$VALUE";
484         ;;
485     x--configmake=*)
486         extractFuncValue $1;
487         ARG_CFGMAKE="$VALUE";
488         ;;
489     "x--with-gnustep")
490         ARG_WITH_GNUSTEP=1
491         DARG_IS_FHS=0
492         ;;
493     "x--without-gnustep")
494         ARG_WITH_GNUSTEP=0
495         DARG_IS_FHS=1
496         ;;
497     "x--enable-debug")
498         ARG_WITH_DEBUG=1
499         ;;
500     "x--disable-debug")
501         ARG_WITH_DEBUG=0
502         ;;
503     "x--enable-strip")
504         ARG_WITH_STRIP=1
505         ;;
506     "x--disable-strip")
507         ARG_WITH_STRIP=0
508         ;;
509
510     *) echo "error: cannot process argument: $1"; exit 1; ;;
511   esac
512 }
513
514 for i in $@; do
515   processOption $i;
516 done
517
518 # load GNUstep environment
519 validateGNUstepArgs
520 # first we load the GNUstep.sh environment
521 source $DARG_GNUSTEP_SH
522 if test $ARG_BEQUIET != 1; then
523   printGNUstepSetup;
524 fi
525
526 # setup some GNUstep dependend defaults
527 if test "x$GNUSTEP_HOST_VENDOR" = "xapple"; then
528   setupAppleArgs;
529 fi
530
531 # ensure the parameters make sense
532 validateArgs
533
534 # start it
535 runIt