isolated debug noise
[feisty_meow.git] / scripts / generator / build_variables.sh
1 #!/bin/bash
2
3 ##############
4 #
5 #  Name   : build variable calculator
6 #  Author : Chris Koeritz
7 #
8 #  Purpose:
9 #
10 #    This script sets up all the variables needed by the HOOPLE system for
11 #  building the source code.  It can either be run as a bash script directly
12 #  like so:
13 #
14 #      bash $FEISTY_MEOW_APEX/scripts/generator/build_variables.sh
15 #
16 #  which will establish a new shell containing all the variables, or you can
17 #  'source' the script like so:
18 #
19 #      build_vars=$FEISTY_MEOW_APEX/scripts/generator/build_variables.sh
20 #      source $build_vars $build_vars
21 #
22 #  to set all of the variables in your current shell.  The full path is
23 #  necessary in these commands to allow the script to easily find itself.
24 #  The 'source' version needs to be fed the actual path to the script
25 #  because bash 'source' commands cause the first parameter (called $0) to
26 #  be set to just the path to bash itself.
27 #
28 ##############
29 # Copyright (c) 2004-$now By Author.  This program is free software; you can
30 # redistribute it and/or modify it under the terms of the GNU General Public
31 # License as published by the Free Software Foundation; either version 2 of
32 # the License or (at your option) any later version.  This is online at:
33 #     http://www.fsf.org/copyleft/gpl.html
34 # Please send any updates to: fred@gruntose.com
35 ##############
36
37 # here is where we compute the locations for the build's pieces, based on
38 # where this script is located.  we currently assume that the build scripts
39 # like this one are at the same height in the hierarchy as the clam scripts
40 # that are used in the bootstrapping process.
41
42 # get the most important bits first; the directory this script lives in and
43 # the script's name.
44 PARM_0="$0"
45 PARM_1="$1"
46
47 ##############
48
49 # helpful build function zone.
50
51 source "$FEISTY_MEOW_SCRIPTS/core/functions.sh"
52
53 ##############
54
55 # outer check on whether this already was run or not.
56 if [ -z "$BUILD_VARS_LOADED" ]; then
57
58 if [ ! -z "$DEBUG_FEISTY_MEOW" ]; then
59   echo recalculating feisty meow build variables.
60   echo
61 fi
62
63 # perform some calculations to get the right paths from our parameters.
64 if [ ! -z "$PARM_1" ]; then
65   # use the first real parameter since this is probably the 'source' version.
66   export BUILD_SCRIPTS_PATH="$(dirname "$PARM_1")"
67   THIS_TOOL_NAME="$(basename "$PARM_1")"
68 else
69   # use the zeroth parameter, since we know nothing more about our name.
70   export BUILD_SCRIPTS_PATH="$(dirname "$PARM_0")"
71   THIS_TOOL_NAME="$(basename "$PARM_0")"
72 fi
73 BUILD_SCRIPTS_PATH="$(cd $(echo $BUILD_SCRIPTS_PATH | tr '\\\\' '/' ); \pwd)"
74
75 # figure out the other paths based on where we found this script.
76 export BUILDING_HIERARCHY="$(echo "$BUILD_SCRIPTS_PATH" | sed -e 's/\(.*\)\/[^\/]*/\1/')"
77 export CLAM_SCRIPTS="$(cd $BUILD_SCRIPTS_PATH/../clam ; \pwd)"
78 # synonym to make other builds happy.
79 export BUILDER_PATH="$BUILDING_HIERARCHY"
80
81 # set some clam parameters for compilation.  if the script can't guess the
82 # right configuration, then you will need to set them in the last 'else'
83 # below.
84 if [ ! -z "$IS_UNIX" ]; then export OPERATING_SYSTEM=UNIX;
85 elif [ ! -z "$IS_DOS" ]; then export OPERATING_SYSTEM=WIN32;
86 else
87   # the system is unknown, so we give up on guessing.
88   export OPERATING_SYSTEM=unknown
89 fi
90 if [ ! -z "$DEBUG_FEISTY_MEOW" ]; then
91   echo "[OS is \"$OPERATING_SYSTEM\"]"
92 fi
93
94 if [ ! -z "$DEBUG_FEISTY_MEOW" ]; then
95   echo "[FEISTY_MEOW_APEX is $FEISTY_MEOW_APEX]"
96 fi
97
98 # set some extra variables that clam uses.
99
100 # CLAM_ON_UNIX or CLAM_ON_DOS might get defined here.
101 # we also can set OS_SUBCLASS if we detect darwin.
102 if [ $OPERATING_SYSTEM == UNIX ]; then
103   export CLAM_ON_UNIX=$(uname)
104   if [[ $CLAM_ON_UNIX =~ .*[Dd]arwin.* ]]; then
105     # pick the subclass now that we know this is darwin.
106     export CLAM_OS_SUBCLASS=darwin
107   fi
108 elif [ $OPERATING_SYSTEM == WIN32 ]; then
109   export CLAM_ON_DOS=$(uname)
110 else
111   echo "Unknown operating system--clam will not build well here."
112 fi
113
114 # CLAM_BASE_CPU is a flag that distinguishes the type of processor, if necessary.
115 export CLAM_BASE_CPU="$(uname -m 2>/dev/null || arch 2>/dev/null || echo i686)"
116 #ugh, machine gives us an odd answer on macos.  machine 2>/dev/null || 
117
118 # "FEISTY_MEOW_CPP_HEADERS" are folders where our C and C++ header files can be found.
119 # we'll compute the set of folders as best we can below.
120 if [ -d "$FEISTY_MEOW_APEX/nucleus" ]; then
121   # just assumes we're at home and know our header locations under the feisty meow hierarchy.
122   export LOCUS_LIBRARY_HEADERS="$FEISTY_MEOW_APEX/nucleus $FEISTY_MEOW_APEX/octopi $FEISTY_MEOW_APEX/graphiq"
123 else
124   export LOCUS_LIBRARY_HEADERS=
125 fi 
126    ####blech!  maybe not needed now?  was involved above.  | tr "\\\\" / | sed -e "s/\([a-zA-Z]\):\/\([^ ]*\)/\/cygdrive\/\1\/\2/g" ')
127 export FEISTY_MEOW_CPP_HEADERS=$(find $LOCUS_LIBRARY_HEADERS -mindepth 1 -maxdepth 1 -type d | grep -v "\.settings" )
128
129 # the root name of the version file.  This is currently irrelevant on
130 # non-windoze platforms.
131 export CLAM_VERSION_RC_ROOT=$(bash $CLAM_SCRIPTS/cpp/rc_name.sh)
132
133 # CLAM_COMPILER is the C/C++ compiler application that builds our code.
134 # The variable is mainly used within CLAM itself for determining the proper
135 # compiler flags.
136 export CLAM_COMPILER
137 if [ "$OPERATING_SYSTEM" == UNIX ]; then
138   if [ "$CLAM_OS_SUBCLASS" == darwin ]; then
139     CLAM_COMPILER=GNU_DARWIN
140   else
141     CLAM_COMPILER=GNU_LINUX
142   fi
143 elif [ "$OPERATING_SYSTEM" == WIN32 ]; then
144   CLAM_COMPILER=GNU_WINDOWS
145 fi
146 if [ -z "$CLAM_COMPILER" ]; then
147   # if we get into this case, we have no idea how to set the default compiler.
148   # so... pick a fun default.
149   CLAM_COMPILER=GNU_LINUX
150 fi
151
152 # "CLAM_COMPILER_ROOT_DIR" is the top-level for the C++ compiler location.
153 # it is generally the top of the OS, although some variants may need this
154 # modified (e.g., gnu arm linux, but we haven't built on that in a bit).
155 export CLAM_COMPILER_ROOT_DIR="/"
156
157 # CLAM_COMPILER_VERSION specifies the version of the particular compiler we're using.
158 # this is sometimes needed to distinguish how the code is built or where headers/libraries are found.
159 export CLAM_COMPILER_VERSION=$(bash $CLAM_SCRIPTS/cpp/get_version.sh $CLAM_COMPILER $CLAM_COMPILER_ROOT_DIR )
160
161 # new BUILD_TOP variable points at the utter top-most level of any files
162 # in the building hierarchy.
163 export BUILD_TOP="$FEISTY_MEOW_APEX"
164
165 # the production directory is the location for all the scripts and setup
166 # code needed to produce the executables for feisty meow.
167 export PRODUCTION_STORE="$BUILD_TOP/production"
168
169 ## set up the top-level for all build creations and logs and such.
170 #export FEISTY_MEOW_GENERATED_STORE="$TMP/generated-feisty_meow"
171 #if [ ! -d "$FEISTY_MEOW_GENERATED_STORE" ]; then
172 #  mkdir -p "$FEISTY_MEOW_GENERATED_STORE"
173 #fi
174 ## set up our effluent outsourcing valves.
175 #export TEMPORARIES_PILE="$FEISTY_MEOW_GENERATED_STORE/temporaries"
176 #if [ ! -d "$TEMPORARIES_PILE" ]; then
177 #  mkdir -p "$TEMPORARIES_PILE"
178 #fi
179
180 # this variable points at a folder where we store the generated products of
181 # the build, such as the binaries and installer packages.
182 export RUNTIME_PATH="$FEISTY_MEOW_GENERATED_STORE/runtime"
183 if [ ! -d "$RUNTIME_PATH" ]; then
184   mkdir -p "$RUNTIME_PATH"
185 fi
186
187 # we define a log file storage area that can be relied on by the build.
188 export FEISTY_MEOW_LOGS="$FEISTY_MEOW_GENERATED_STORE/logs"
189 if [ ! -d "$FEISTY_MEOW_LOGS" ]; then
190   mkdir -p "$FEISTY_MEOW_LOGS"
191 fi
192
193 ##############
194
195 # debugging area where we say what we think we know.
196
197 if [ ! -z "$DEBUG_FEISTY_MEOW" ]; then
198   echo scripts: $BUILD_SCRIPTS_PATH
199   echo build tools hier: $BUILDING_HIERARCHY
200   echo this tool: $THIS_TOOL_NAME
201   echo repository: $FEISTY_MEOW_APEX
202   echo clam: $CLAM_SCRIPTS
203 fi
204
205 ##############
206
207 # test out our computed variables to make sure they look right.
208 pushd / &>/dev/null # jump to the root so relative paths are caught.
209
210 # flag for whether any checks have failed.
211 got_bad=
212
213 # first the scripts directory; do we find this script there?
214 if [ ! -f "$BUILD_SCRIPTS_PATH/$THIS_TOOL_NAME" ]; then
215   echo "This script cannot locate the proper build folders.  The crucial path"
216   echo "variable seems to be '$BUILD_SCRIPTS_PATH', which"
217   echo "does not seem to contain '$THIS_TOOL_NAME' (this"
218   echo "script's apparent name)."
219   got_bad=1
220 fi
221
222 # next the clam directory; is the main variables file present there?
223 if [ -z "$got_bad" -a ! -f "$CLAM_SCRIPTS/variables.def" ]; then
224   echo "The clam directory could not be located under our build tools hierarchy."
225   echo "Please examine the configuration and make sure that this script is in a"
226   echo "directory that resides at the same height as the 'clam' directory."
227   got_bad=1
228 fi
229
230 # now compute some more paths with a bit of "heuristics" for where we can
231 # find the source code.
232 export TOOL_SOURCES="$FEISTY_MEOW_APEX/nucleus/tools"
233 if [ -z "$got_bad" -a ! -d "$TOOL_SOURCES/dependency_tool" -o ! -d "$TOOL_SOURCES/clam_tools" ]; then
234   echo "This script cannot locate the tool source code folder.  This is where the"
235   echo "dependency_tool and clam_tools folders are expected to be."
236   got_bad=1
237 fi
238
239 ############################
240   
241 # we only run the rest of the script if we know we didn't have some kind of
242 # bad thing happen earlier.
243 if [ -z "$got_bad" ]; then
244
245   # where we store the binaries used for building the rest of the code base.
246   export CLAM_BINARIES="$RUNTIME_PATH/clam_bin"
247     # the final destination for the new binaries which provide the
248     # build with all the applications it needs to get going.
249   export TARGETS_STORE="$RUNTIME_PATH/binaries"
250     # targets directory is meaningful to clam, which will use it for output.
251   export INTERMEDIATE_STORE="$TARGETS_STORE"
252     # where we are building the applications before they get promoted.
253
254 #hmmm: could allow override on this if already set.
255   # calculate which build ini file to use.
256   export BUILD_PARAMETER_FILE="$PRODUCTION_STORE/feisty_meow_config.ini"
257   if [ ! -f "$BUILD_PARAMETER_FILE" ]; then
258     echo "Cannot find a useful build configuration file."
259   fi
260   
261   # pick the executable's file ending based on the platform.
262   if [ "$OPERATING_SYSTEM" == "UNIX" ]; then export EXE_ENDING=;
263   elif [ "$OPERATING_SYSTEM" == "WIN32" ]; then export EXE_ENDING=.exe;
264   else
265     echo "The OPERATING_SYSTEM variable is unset or unknown.  Bailing out."
266   fi
267   
268   # we should have established our internal variables now, so let's try
269   # using them.
270   export PATH=$(dos_to_unix_path $CLAM_BINARIES):$PATH
271   
272   # load up the helper variables for visual studio on winders.
273   if [ "$OPERATING_SYSTEM" == "WIN32" ]; then
274     # moved back to the good path of using gcc, not visual studio.
275 #what vars needed?
276 #trying just unixy ones, since we're doing cygwin on doze.
277 export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:$TARGETS_STORE"
278   else
279     export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:$TARGETS_STORE"
280   fi
281   
282   popd &>/dev/null # checking is over, jump back to the starting point.
283   
284   ############################
285   
286   # at this point, all the build related variables should be valid.
287   
288   if [ -z "$INCLUDED_FROM_BOOTSTRAP" \
289       -a -z "$PARM_1" ]; then
290     # we are running as a stand-alone script, so we stay resident with our
291     # current set of variables.
292     bash
293   fi
294
295   # sentinel that tells us this script was pulled in.
296   export BUILD_VARS_LOADED=true
297
298 fi
299
300 fi  # outer wrapper for already ran build vars check.
301
302 ##############
303
304 # hook clam into the compilation system.
305 # this always needs to be defined since functions aren't exported.
306 function make()
307 {
308   /usr/bin/make -I "$CLAM_SCRIPTS" $*
309 }
310
311