]> err.no Git - sope/blob - configure
work on recurrences
[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     SETUP_COMBO="gnu-fd-nil"
129     SETUP_LOGNAME="config-gstepmake.log"
130     if test -d /Developer/Applications/Xcode.app; then
131       # rather weird OSX test, right? ;->
132       SETUP_COMBO="apple-apple-nil"
133     fi
134     pregsmdir="$PWD"
135     
136     echo -n "configuring builtin gnustep-make environment (${SETUP_LOGNAME}) .."
137
138     cd "$GSTEPMAKE_SRCDIR"
139     ./configure >${pregsmdir}/${SETUP_LOGNAME} \
140       --prefix="${INTERNAL_MAKEDIR}" \
141       --without-system-root \
142       --with-network-root="${INTERNAL_MAKEDIR}" \
143       --with-local-root="${INTERNAL_MAKEDIR}" \
144       --with-user-root="${INTERNAL_MAKEDIR}" \
145       --with-library-combo="${SETUP_COMBO}"
146
147     echo -n ".. install .."
148     make install >>${pregsmdir}/${SETUP_LOGNAME}
149     
150     ARG_GSMAKE="${INTERNAL_MAKEDIR}/Library/Makefiles/"
151     ARG_IS_FHS=1
152     DARG_IS_FHS=1
153     ARG_WITH_GNUSTEP=0
154     USES_INTERNAL_MAKE=yes
155     if test "x$ARG_PREFIX" = "x"; then
156       ARG_PREFIX="/usr/local/"
157     fi
158     
159     cd "$pregsmdir"
160     if test -f $ARG_GSMAKE/GNUstep.sh; then
161       echo ".. done (log in ${SETUP_LOGNAME})."
162     else
163       echo "error: failed to setup embedded gnustep-make sources!"
164       cat ${pregsmdir}/${SETUP_LOGNAME}
165       exit 1
166     fi
167   else
168     echo "error: did not find embedded gnustep-make sources!"
169     exit 1
170   fi
171 }
172
173 function validateGNUstepArgs() {
174   # GNUstep make
175   if test "x$ARG_GSMAKE" = "x"; then
176     if test -f $HOME/OGoRoot/Library/Makefiles/GNUstep.sh; then
177       ARG_GSMAKE="$HOME/OGoRoot/Library/Makefiles/"
178     elif test -f $HOME/GNUstep/Library/Makefiles/GNUstep.sh; then
179       ARG_GSMAKE="$HOME/GNUstep/Library/Makefiles/"
180     elif test -f /usr/GNUstep/System/Library/Makefiles/GNUstep.sh; then
181       ARG_GSMAKE="/usr/GNUstep/System/Library/Makefiles/"
182     else
183       setupInternalGSMake;
184     fi
185     DARG_GNUSTEP_SH="$ARG_GSMAKE/GNUstep.sh"
186   elif test -d $ARG_GSMAKE; then
187     if test -f $ARG_GSMAKE/GNUstep.sh; then
188       DARG_GNUSTEP_SH="$ARG_GSMAKE/GNUstep.sh"
189     elif test -f $ARG_GSMAKE/Library/Makefiles/GNUstep.sh; then
190       ARG_GSMAKE="$ARG_GSMAKE/Library/Makefiles"
191       DARG_GNUSTEP_SH="$ARG_GSMAKE/GNUstep.sh"
192     else
193       echo "error: specified directory contains no GNUstep.sh: $ARG_GSMAKE"
194       exit 1
195     fi
196   else
197     echo "error: specified GNUstep make tree does not exist: $ARG_GSMAKE"
198     exit 1
199   fi
200 }
201
202 function setupAppleArgs() {
203   ARG_WITH_STRIP=0
204   if test "x${USES_INTERNAL_MAKE}" = "no"; then
205     ARG_WITH_GNUSTEP=1
206   fi
207   
208   # no reason to print a warning?
209   #if test "x${xLIBRARY_COMBO}" != "xapple-apple-nil"; then
210   #  if test "x${LIBRARY_COMBO}" != "xapple-apple-apple"; then
211   #    echo "WARNING: detected MacOSX GNUstep setup: ${LIBRARY_COMBO}"
212   #    echo ""
213   #  fi
214   #fi
215 }
216
217 function validateArgs() {
218   # validate prefix (could be better?)
219   case "x$ARG_PREFIX" in
220     "x/usr/local"|"x/usr/local/")
221         DARG_IS_FHS=1;
222         ;;
223     "x/usr"|"x/usr/")
224         DARG_IS_FHS=1;
225         ;;
226     "x$GNUSTEP_USER_ROOT"|"x$GNUSTEP_LOCAL_ROOT"|"x$GNUSTEP_SYSTEM_ROOT")
227         DARG_IS_FHS=0;
228         ARG_WITH_GNUSTEP=1;
229         ;;
230     "x")
231         if test $ARG_WITH_GNUSTEP = 1; then
232           DARG_IS_FHS=0;
233           ARG_PREFIX="$GNUSTEP_LOCAL_ROOT"
234           if test $ARG_BEQUIET != 1; then
235             echo "Note: will install in GNUSTEP_LOCAL_ROOT: $ARG_PREFIX"
236             echo ""
237           fi
238         elif test "x$ARG_FRAMEWORK_DIR" != "x"; then
239           DARG_IS_FHS=0;
240           ARG_PREFIX="$ARG_FRAMEWORK_DIR"
241           echo "Note: will install in frameworks location: $ARG_PREFIX"
242           echo ""
243         else
244           DARG_IS_FHS=1;
245           ARG_PREFIX="/usr/local/"
246           echo "Note: will install in default location: $ARG_PREFIX"
247           echo ""
248         fi
249         ;;
250     *)
251         if test $ARG_WITH_GNUSTEP = 1; then
252           echo "error: specified --with-gnustep, but specified prefix is not"
253           echo "       a GNUstep root: '$ARG_PREFIX'"
254           exit 1
255         else
256           if test $ARG_BEQUIET != 1; then
257             warnOnFHSPrefix;
258           fi
259           DARG_IS_FHS=1;
260         fi
261         ;;
262   esac
263   
264   if test $ARG_WITH_GNUSTEP = 1; then
265     if test $DARG_IS_FHS = 1; then
266       echo "error: configured for FHS root _and_ GNUstep tree. Choose one!"
267       exit 1
268     fi
269   fi
270 }
271
272 function printGNUstepSetup() {
273   echo "GNUstep environment:"
274   echo "  system: ${GNUSTEP_SYSTEM_ROOT}"
275   echo "  local:  ${GNUSTEP_LOCAL_ROOT}"
276   echo "  user:   ${GNUSTEP_USER_ROOT}"
277   echo "  path:   ${GNUSTEP_PATHLIST}"
278   echo "  flat:   ${GNUSTEP_FLATTENED}"
279   echo "  arch:   ${GNUSTEP_HOST}"
280   echo "  combo:  ${LIBRARY_COMBO}"
281   echo ""
282 }
283
284 function cfgwrite() {
285   echo "$1" >> $ARG_CFGMAKE
286 }
287
288 function genConfigMake() {
289   # we ignore the following vars also patches by gstep-make:
290   #   PATH
291   #   DYLD_LIBRARY_PATH
292   #   GUILE_LOAD_PATH
293   #   CLASSPATH
294   
295   if test $ARG_BEQUIET != 1; then
296     echo "creating: $ARG_CFGMAKE"
297   fi
298   
299   echo "# GNUstep environment configuration" > $ARG_CFGMAKE
300   cfgwrite "#   created by: '$CFG_ARGS'"
301   cfgwrite ""
302   
303   cfgwrite "# Note: you can override any option as a 'make' parameter, eg:"
304   cfgwrite "#         make debug=yes"
305   cfgwrite ""
306   
307   #cfgwrite "# print on the cmdline that this file is being used"
308   #cfgwrite "all :: "
309   #cfgwrite "   @echo Local GNUstep config.make is active"
310   #cfgwrite ""
311   
312   # TODO: should be also write a GNUSTEP_INSTALLATION_DIR / BUNDLE_INSTALL_DIR?
313   
314   
315   if test "x$ARG_FRAMEWORK_DIR" != "x"; then
316     cfgwrite "# configured to install in Frameworks directory"
317     cfgwrite "FRAMEWORK_INSTALL_DIR:=${ARG_FRAMEWORK_DIR}"
318     cfgwrite "frameworks=yes"
319     cfgwrite ""
320   elif test $DARG_IS_FHS = 1; then
321     cfgwrite "# configured for FHS install"
322     cfgwrite "FHS_INSTALL_ROOT:=$ARG_PREFIX"
323     cfgwrite ""
324   else
325     cfgwrite "# configured for GNUstep install"
326   fi
327   
328   if test $ARG_WITH_DEBUG = 1; then
329     cfgwrite "# configured to produce debugging code";
330     cfgwrite "debug:=yes"
331   else
332     cfgwrite "# configured to produce non-debugging code";
333     cfgwrite "debug:=no"
334   fi
335   cfgwrite ""
336   
337   if test $ARG_WITH_STRIP = 1; then
338     cfgwrite "# configured to produce stripped code";
339     cfgwrite "strip:=yes"
340   else
341     cfgwrite "# configured not to strip code";
342     cfgwrite "strip:=no"
343   fi
344   cfgwrite ""
345
346   cfgwrite "# enforce shared libraries";
347   cfgwrite "shared:=yes"
348   cfgwrite ""
349   
350   cfgwrite "# GNUstep environment variables:";
351   for i in `env | grep GNUSTEP_ | sort`; do
352     MAKE_ASSI="`echo $i | sed s/=/:=/`"
353     cfgwrite "${MAKE_ASSI}";
354   done
355   cfgwrite "LIBRARY_COMBO=$LIBRARY_COMBO"
356   cfgwrite ""
357   
358   cfgwrite "# avoid a gstep-make warning"
359   cfgwrite "PATH:=\$(GNUSTEP_SYSTEM_ROOT)/Tools:\$(PATH)"
360 }
361
362 function checkLinking() {
363   # library-name => $1, type => $2
364   local oldpwd=$PWD
365   local tmpdir=".configure-test-$$"
366   
367   mkdir $tmpdir
368   cd $tmpdir
369   cp ../maintenance/dummytool.m .
370   
371   tmpmake="GNUmakefile"
372   echo  >$tmpmake "include ../config.make"
373   echo >>$tmpmake "include \$(GNUSTEP_MAKEFILES)/common.make"
374   echo >>$tmpmake "TOOL_NAME           := linktest"
375   echo >>$tmpmake "linktest_OBJC_FILES := dummytool.m"
376   echo >>$tmpmake "linktest_TOOL_LIBS  += -l$1"
377   echo >>$tmpmake "SYSTEM_LIB_DIR      += ${LINK_SYSLIBDIRS}"
378   echo >>$tmpmake "include \$(GNUSTEP_MAKEFILES)/tool.make"
379   
380   make -s messages=yes -f $tmpmake linktest >out.log 2>err.log
381   LINK_RESULT=$?
382   
383   if test $LINK_RESULT = 0; then
384     echo "$2 library found: $1"
385     cfgwrite "HAS_LIBRARY_$1=yes"
386   else
387     if test "x$2" = "xrequired"; then
388       echo "failed to link $2 library: $1"
389       rm ../config.make
390       exit 1
391     else
392       echo "failed to link $2 library: $1"
393       cfgwrite "HAS_LIBRARY_$1=no"
394     fi
395   fi
396   
397   cd $oldpwd
398   rm -rf $tmpdir
399 }
400
401 function checkDependencies() {
402   cfgwrite ""
403   cfgwrite "# library dependencies"
404   checkLinking "xml2"        optional;
405   checkLinking "ldap"        optional;
406   checkLinking "ssl"         required; # TODO: make optional
407   checkLinking "pq"          optional;
408   checkLinking "sqlite3"     optional;
409   checkLinking "mysqlclient" optional;
410 }
411
412 function runIt() {
413   if test $ARG_BEQUIET != 1; then
414     printParas;
415   fi
416   
417   if test $ARG_NOCREATE = 1; then 
418     if test $ARG_BEQUIET != 1; then
419       echo "not creating the config file ...";
420     fi
421   else
422     genConfigMake;
423     checkDependencies;
424     
425     if test -x $NGSTREAMS_DIR/configure; then
426       if test $ARG_BEQUIET != 1; then
427         echo -n "configuring NGStreams library .."
428         old="$PWD"
429         cd $NGSTREAMS_DIR
430         ./configure >$old/config-NGStreams.log
431         cd $old
432         echo ".. done (log in config-NGStreams.log)."
433       fi
434     fi
435   fi
436 }
437
438 # ******************** options ********************
439
440 function extractFuncValue() {
441   VALUE="`echo "$1" | sed "s/[^=]*=//g"`"
442 }
443
444 function processOption() {
445   case "x$1" in
446     "x--help"|"x-h")
447         usage;
448         ;;
449     "x--quiet"|"x--silent"|"x-q") ARG_BEQUIET=1;  ;;
450     "x--no-create"|"x-n")         ARG_NOCREATE=1; ;;
451     x--prefix=*)
452         extractFuncValue $1;
453         ARG_PREFIX="$VALUE";
454         ;;
455     x--frameworks=*)
456         extractFuncValue $1;
457         ARG_FRAMEWORK_DIR="$VALUE";
458         ;;
459     x--gsmake=*)
460         extractFuncValue $1;
461         ARG_GSMAKE="$VALUE";
462         ;;
463     x--configmake=*)
464         extractFuncValue $1;
465         ARG_CFGMAKE="$VALUE";
466         ;;
467     "x--with-gnustep")
468         ARG_WITH_GNUSTEP=1
469         DARG_IS_FHS=0
470         ;;
471     "x--without-gnustep")
472         ARG_WITH_GNUSTEP=0
473         DARG_IS_FHS=1
474         ;;
475     "x--enable-debug")
476         ARG_WITH_DEBUG=1
477         ;;
478     "x--disable-debug")
479         ARG_WITH_DEBUG=0
480         ;;
481     "x--enable-strip")
482         ARG_WITH_STRIP=1
483         ;;
484     "x--disable-strip")
485         ARG_WITH_STRIP=0
486         ;;
487
488     *) echo "error: cannot process argument: $1"; exit 1; ;;
489   esac
490 }
491
492 for i in $@; do
493   processOption $i;
494 done
495
496 # load GNUstep environment
497 validateGNUstepArgs
498 # first we load the GNUstep.sh environment
499 source $DARG_GNUSTEP_SH
500 if test $ARG_BEQUIET != 1; then
501   printGNUstepSetup;
502 fi
503
504 # setup some GNUstep dependend defaults
505 if test "x$GNUSTEP_HOST_VENDOR" = "xapple"; then
506   setupAppleArgs;
507 fi
508
509 # ensure the parameters make sense
510 validateArgs
511
512 # start it
513 runIt