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