]> err.no Git - sope/blob - configure
check for empty gstep-make tree var
[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     echo "error: did not specify a GNUstep make tree!"
100     exit 1
101   elif test -d $ARG_GSMAKE; then
102     if test -f $ARG_GSMAKE/GNUstep.sh; then
103       DARG_GNUSTEP_SH="$ARG_GSMAKE/GNUstep.sh"
104     elif test -f $ARG_GSMAKE/Library/Makefiles/GNUstep.sh; then
105       ARG_GSMAKE="$ARG_GSMAKE/Library/Makefiles"
106       DARG_GNUSTEP_SH="$ARG_GSMAKE/GNUstep.sh"
107     else
108       echo "error: specified directory contains no GNUstep.sh: $ARG_GSMAKE"
109       exit 1
110     fi
111   else
112     echo "error: specified GNUstep make tree does not exist: $ARG_GSMAKE"
113     exit 1
114   fi
115 }
116
117 function validateArgs() {
118   # validate prefix (could be better?)
119   case "x$ARG_PREFIX" in
120     "x/usr/local"|"x/usr/local/")
121         DARG_IS_FHS=1;
122         ;;
123     "x/usr"|"x/usr/")
124         DARG_IS_FHS=1;
125         ;;
126     "x$GNUSTEP_USER_ROOT"|"x$GNUSTEP_LOCAL_ROOT"|"x$GNUSTEP_SYSTEM_ROOT")
127         DARG_IS_FHS=0;
128         ARG_WITH_GNUSTEP=1;
129         ;;
130     "x")
131         if test $ARG_WITH_GNUSTEP = 1; then
132           DARG_IS_FHS=0;
133           ARG_PREFIX="$GNUSTEP_LOCAL_ROOT"
134           if test $ARG_BEQUIET != 1; then
135             echo "Note: will install in GNUSTEP_LOCAL_ROOT: $ARG_PREFIX"
136             echo ""
137           fi
138         else
139           DARG_IS_FHS=1;
140           ARG_PREFIX="/usr/local/"
141           echo "Note: will install in default location: $ARG_PREFIX"
142           echo ""
143         fi
144         ;;
145     *)
146         if test $ARG_WITH_GNUSTEP = 1; then
147           echo "error: specified --with-gnustep, but specified prefix is not"
148           echo "       a GNUstep root: '$ARG_PREFIX'"
149           exit 1
150         else
151           if test $ARG_BEQUIET != 1; then
152             warnOnFHSPrefix;
153           fi
154           DARG_IS_FHS=1;
155         fi
156         ;;
157   esac
158   
159   if test $ARG_WITH_GNUSTEP = 1; then
160     if test $DARG_IS_FHS = 1; then
161       echo "error: configured for FHS root _and_ GNUstep tree. Choose one!"
162       exit 1
163     fi
164   fi
165 }
166
167 function printGNUstepSetup() {
168   echo "GNUstep environment:"
169   echo "  system: ${GNUSTEP_SYSTEM_ROOT}"
170   echo "  local:  ${GNUSTEP_LOCAL_ROOT}"
171   echo "  user:   ${GNUSTEP_USER_ROOT}"
172   echo "  path:   ${GNUSTEP_PATHLIST}"
173   echo "  flat:   ${GNUSTEP_FLATTENED}"
174   echo "  arch:   ${GNUSTEP_HOST}"
175   echo "  combo:  ${LIBRARY_COMBO}"
176   echo ""
177 }
178
179 function cfgwrite() {
180   echo "$1" >> $ARG_CFGMAKE
181 }
182
183 function genConfigMake() {
184   # we ignore the following vars also patches by gstep-make:
185   #   PATH
186   #   DYLD_LIBRARY_PATH
187   #   GUILE_LOAD_PATH
188   #   CLASSPATH
189   
190   if test $ARG_BEQUIET != 1; then
191     echo "creating: $ARG_CFGMAKE"
192   fi
193   
194   echo "# GNUstep environment configuration" > $ARG_CFGMAKE
195   cfgwrite "#   created by: '$CFG_ARGS'"
196   cfgwrite ""
197   
198   cfgwrite "# Note: you can override any option as a 'make' parameter, eg:"
199   cfgwrite "#         make debug=yes"
200   cfgwrite ""
201   
202   cfgwrite "# print on the cmdline that this file is being used"
203   cfgwrite "before-all :: "
204   cfgwrite "    @echo Local GNUstep config.make is active"
205   cfgwrite ""
206   
207   # TODO: should be also write a GNUSTEP_INSTALLATION_DIR / BUNDLE_INSTALL_DIR?
208   
209   if test $DARG_IS_FHS = 1; then
210     cfgwrite "# configured for FHS install"
211     cfgwrite "FHS_INSTALL_ROOT:=$ARG_PREFIX"
212     cfgwrite ""
213   fi
214   
215   if test $ARG_WITH_DEBUG = 1; then
216     cfgwrite "# configured to produce debugging code";
217     cfgwrite "debug:=yes"
218   else
219     cfgwrite "# configured to produce non-debugging code";
220     cfgwrite "debug:=no"
221   fi
222   cfgwrite ""
223   
224   cfgwrite "# enforce shared libraries";
225   cfgwrite "shared:=yes"
226   cfgwrite ""
227   
228   cfgwrite "# GNUstep environment variables:";
229   for i in `env | grep GNUSTEP_ | sort`; do
230     MAKE_ASSI="`echo $i | sed s/=/:=/`"
231     cfgwrite "${MAKE_ASSI}";
232   done
233   cfgwrite "LIBRARY_COMBO=$LIBRARY_COMBO"
234 }
235
236 function runIt() {
237   if test $ARG_BEQUIET != 1; then
238     printParas;
239   fi
240   
241   if test $ARG_NOCREATE = 1; then 
242     if test $ARG_BEQUIET != 1; then
243       echo "not creating the config file ...";
244     fi
245   else
246     genConfigMake;
247   fi
248 }
249
250 # ******************** options ********************
251
252 function extractFuncValue() {
253   VALUE="`echo "$1" | sed "s/[^=]*=//g"`"
254 }
255
256 function processOption() {
257   case "x$1" in
258     "x--help"|"x-h")
259         usage;
260         ;;
261     "x--quiet"|"x--silent"|"x-q") ARG_BEQUIET=1;  ;;
262     "x--no-create"|"x-n")         ARG_NOCREATE=1; ;;
263     x--prefix=*)
264         extractFuncValue $1;
265         ARG_PREFIX="$VALUE";
266         ;;
267     x--gsmake=*)
268         extractFuncValue $1;
269         ARG_GSMAKE="$VALUE";
270         ;;
271     x--configmake=*)
272         extractFuncValue $1;
273         ARG_CFGMAKE="$VALUE";
274         ;;
275     "x--with-gnustep")
276         ARG_WITH_GNUSTEP=1
277         DARG_IS_FHS=0
278         ;;
279     "x--enable-debug")
280         ARG_WITH_DEBUG=1
281         ;;
282
283     *) echo "error: cannot process argument: $1"; exit 1; ;;
284   esac
285 }
286
287 for i in $@; do
288   processOption $i;
289 done
290
291 # load GNUstep environment
292 validateGNUstepArgs
293 # first we load the GNUstep.sh environment
294 source $DARG_GNUSTEP_SH
295 if test $ARG_BEQUIET != 1; then
296   printGNUstepSetup;
297 fi
298
299 # ensure the parameters make sense
300 validateArgs
301
302 # start it
303 runIt