]> err.no Git - sope/blob - configure
da814e3021890894deaf0a0762afeee5a5fc575f
[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=0
21
22 DARG_GNUSTEP_SH="$ARG_GSMAKE/GNUstep.sh"
23 DARG_IS_FHS=1
24
25 # ******************** usage ********************
26
27 function usage() {
28   cat <<_ACEOF
29 \`configure' configures a GNUstep-make based sourcetree for installation.
30
31 Usage: $0 [OPTION]...
32
33 Note: You do not need to configure this source tree, as another option
34       just ensure that the GNUstep.sh of your GNUstep make installation
35       is properly sourced prior running make.
36
37 Configuration:
38   -h, --help              display this help and exit
39   -q, --quiet, --silent   do not print \`checking...' messages
40   -n, --no-create         do not create output files
41
42 Installation directories:
43   --prefix=PREFIX         install files in PREFIX [/usr/local]
44   --gsmake=PATH           path to gnustep-make tree
45   --configmake=PATH       path to the config file being created
46   --with-gnustep          install in GNUstep tree
47   --enable-debug          turn on debugging and compile time warnings
48
49 _ACEOF
50
51   exit 0;
52 }
53
54 # ******************** running ********************
55
56 function printParas() {
57   echo "Configuration:"
58   if test $ARG_BEQUIET  = 1; then echo "  will be quite.";  fi
59   if test $ARG_NOCREATE = 1; then echo "  won't create files"; fi
60   if test $DARG_IS_FHS = 1;  then
61     echo "  FHS:    install in FHS root"; 
62   else
63     echo "  FHS:    install in GNUstep tree"; 
64   fi
65
66   if test $ARG_WITH_DEBUG = 1; then 
67     echo "  debug:  yes";
68   else
69     echo "  debug:  no";
70   fi
71   
72   echo "  prefix: $ARG_PREFIX"
73   echo "  gstep:  $ARG_GSMAKE"
74   echo "  config: $ARG_CFGMAKE"
75   echo "  script: $DARG_GNUSTEP_SH"
76   echo ""
77 }
78
79 function warnOnFHSPrefix() {
80   cat <<_ACEOFWARN
81 Warning: you are configuring for a non standard FHS style prefix.
82          prefix: $ARG_PREFIX
83
84 Some code in SOPE only looks in /usr and /usr/local for resources and is
85 therefore incompatible with arbitary install pathes.
86
87 If you want to have the flexibility of installation in arbitary pathes just
88 configure GNUstep-make and source the GNUstep.sh script prior executing tools
89 to ensure a proper environment.
90 All SOPE based code is completely relocatable when being used in a GNUstep
91 environment.
92
93 _ACEOFWARN
94 }
95
96 function validateGNUstepArgs() {
97   # GNUstep make
98   if test "x$ARG_GSMAKE" = "x"; then
99     if test -f $HOME/OGoRoot/Library/Makefiles/GNUstep.sh; then
100       ARG_GSMAKE="$HOME/OGoRoot/Library/Makefiles/"
101     elif test -f $HOME/GNUstep/Library/Makefiles/GNUstep.sh; then
102       ARG_GSMAKE="$HOME/GNUstep/Library/Makefiles/"
103     elif test -f /usr/GNUstep/System/Library/Makefiles/GNUstep.sh; then
104       ARG_GSMAKE="/usr/GNUstep/System/Library/Makefiles/"
105     else
106       echo "error: please specify a GNUstep make tree!"
107       exit 1
108     fi
109     DARG_GNUSTEP_SH="$ARG_GSMAKE/GNUstep.sh"
110   elif test -d $ARG_GSMAKE; then
111     if test -f $ARG_GSMAKE/GNUstep.sh; then
112       DARG_GNUSTEP_SH="$ARG_GSMAKE/GNUstep.sh"
113     elif test -f $ARG_GSMAKE/Library/Makefiles/GNUstep.sh; then
114       ARG_GSMAKE="$ARG_GSMAKE/Library/Makefiles"
115       DARG_GNUSTEP_SH="$ARG_GSMAKE/GNUstep.sh"
116     else
117       echo "error: specified directory contains no GNUstep.sh: $ARG_GSMAKE"
118       exit 1
119     fi
120   else
121     echo "error: specified GNUstep make tree does not exist: $ARG_GSMAKE"
122     exit 1
123   fi
124 }
125
126 function validateArgs() {
127   # validate prefix (could be better?)
128   case "x$ARG_PREFIX" in
129     "x/usr/local"|"x/usr/local/")
130         DARG_IS_FHS=1;
131         ;;
132     "x/usr"|"x/usr/")
133         DARG_IS_FHS=1;
134         ;;
135     "x$GNUSTEP_USER_ROOT"|"x$GNUSTEP_LOCAL_ROOT"|"x$GNUSTEP_SYSTEM_ROOT")
136         DARG_IS_FHS=0;
137         ARG_WITH_GNUSTEP=1;
138         ;;
139     "x")
140         if test $ARG_WITH_GNUSTEP = 1; then
141           DARG_IS_FHS=0;
142           ARG_PREFIX="$GNUSTEP_LOCAL_ROOT"
143           if test $ARG_BEQUIET != 1; then
144             echo "Note: will install in GNUSTEP_LOCAL_ROOT: $ARG_PREFIX"
145             echo ""
146           fi
147         else
148           DARG_IS_FHS=1;
149           ARG_PREFIX="/usr/local/"
150           echo "Note: will install in default location: $ARG_PREFIX"
151           echo ""
152         fi
153         ;;
154     *)
155         if test $ARG_WITH_GNUSTEP = 1; then
156           echo "error: specified --with-gnustep, but specified prefix is not"
157           echo "       a GNUstep root: '$ARG_PREFIX'"
158           exit 1
159         else
160           if test $ARG_BEQUIET != 1; then
161             warnOnFHSPrefix;
162           fi
163           DARG_IS_FHS=1;
164         fi
165         ;;
166   esac
167   
168   if test $ARG_WITH_GNUSTEP = 1; then
169     if test $DARG_IS_FHS = 1; then
170       echo "error: configured for FHS root _and_ GNUstep tree. Choose one!"
171       exit 1
172     fi
173   fi
174 }
175
176 function printGNUstepSetup() {
177   echo "GNUstep environment:"
178   echo "  system: ${GNUSTEP_SYSTEM_ROOT}"
179   echo "  local:  ${GNUSTEP_LOCAL_ROOT}"
180   echo "  user:   ${GNUSTEP_USER_ROOT}"
181   echo "  path:   ${GNUSTEP_PATHLIST}"
182   echo "  flat:   ${GNUSTEP_FLATTENED}"
183   echo "  arch:   ${GNUSTEP_HOST}"
184   echo "  combo:  ${LIBRARY_COMBO}"
185   echo ""
186 }
187
188 function cfgwrite() {
189   echo "$1" >> $ARG_CFGMAKE
190 }
191
192 function genConfigMake() {
193   # we ignore the following vars also patches by gstep-make:
194   #   PATH
195   #   DYLD_LIBRARY_PATH
196   #   GUILE_LOAD_PATH
197   #   CLASSPATH
198   
199   if test $ARG_BEQUIET != 1; then
200     echo "creating: $ARG_CFGMAKE"
201   fi
202   
203   echo "# GNUstep environment configuration" > $ARG_CFGMAKE
204   cfgwrite "#   created by: '$CFG_ARGS'"
205   cfgwrite ""
206   
207   cfgwrite "# Note: you can override any option as a 'make' parameter, eg:"
208   cfgwrite "#         make debug=yes"
209   cfgwrite ""
210   
211   cfgwrite "# print on the cmdline that this file is being used"
212   cfgwrite "all :: "
213   cfgwrite "    @echo Local GNUstep config.make is active"
214   cfgwrite ""
215   
216   # TODO: should be also write a GNUSTEP_INSTALLATION_DIR / BUNDLE_INSTALL_DIR?
217   
218   if test $DARG_IS_FHS = 1; then
219     cfgwrite "# configured for FHS install"
220     cfgwrite "FHS_INSTALL_ROOT:=$ARG_PREFIX"
221     cfgwrite ""
222   fi
223   
224   if test $ARG_WITH_DEBUG = 1; then
225     cfgwrite "# configured to produce debugging code";
226     cfgwrite "debug:=yes"
227   else
228     cfgwrite "# configured to produce non-debugging code";
229     cfgwrite "debug:=no"
230   fi
231   cfgwrite ""
232   
233   cfgwrite "# enforce shared libraries";
234   cfgwrite "shared:=yes"
235   cfgwrite ""
236   
237   cfgwrite "# GNUstep environment variables:";
238   for i in `env | grep GNUSTEP_ | sort`; do
239     MAKE_ASSI="`echo $i | sed s/=/:=/`"
240     cfgwrite "${MAKE_ASSI}";
241   done
242   cfgwrite "LIBRARY_COMBO=$LIBRARY_COMBO"
243 }
244
245 function runIt() {
246   if test $ARG_BEQUIET != 1; then
247     printParas;
248   fi
249   
250   if test $ARG_NOCREATE = 1; then 
251     if test $ARG_BEQUIET != 1; then
252       echo "not creating the config file ...";
253     fi
254   else
255     genConfigMake;
256   fi
257 }
258
259 # ******************** options ********************
260
261 function extractFuncValue() {
262   VALUE="`echo "$1" | sed "s/[^=]*=//g"`"
263 }
264
265 function processOption() {
266   case "x$1" in
267     "x--help"|"x-h")
268         usage;
269         ;;
270     "x--quiet"|"x--silent"|"x-q") ARG_BEQUIET=1;  ;;
271     "x--no-create"|"x-n")         ARG_NOCREATE=1; ;;
272     x--prefix=*)
273         extractFuncValue $1;
274         ARG_PREFIX="$VALUE";
275         ;;
276     x--gsmake=*)
277         extractFuncValue $1;
278         ARG_GSMAKE="$VALUE";
279         ;;
280     x--configmake=*)
281         extractFuncValue $1;
282         ARG_CFGMAKE="$VALUE";
283         ;;
284     "x--with-gnustep")
285         ARG_WITH_GNUSTEP=1
286         DARG_IS_FHS=0
287         ;;
288     "x--enable-debug")
289         ARG_WITH_DEBUG=1
290         ;;
291
292     *) echo "error: cannot process argument: $1"; exit 1; ;;
293   esac
294 }
295
296 for i in $@; do
297   processOption $i;
298 done
299
300 # load GNUstep environment
301 validateGNUstepArgs
302 # first we load the GNUstep.sh environment
303 source $DARG_GNUSTEP_SH
304 if test $ARG_BEQUIET != 1; then
305   printGNUstepSetup;
306 fi
307
308 # ensure the parameters make sense
309 validateArgs
310
311 # start it
312 runIt