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