eb3a56605c3c60ffe6d95567b14060b91649c699
[feisty_meow.git] / scripts / generator / build_variables.sh
1 ##############
2 #
3 #  Name   : build variable calculator
4 #  Author : Chris Koeritz
5 #
6 #  Purpose:
7 #
8 #    This script sets up all the variables needed by the HOOPLE system for
9 #  building the source code.  It can either be run as a bash script directly
10 #  like so:
11 #
12 #      bash $FEISTY_MEOW_APEX/scripts/generator/build_variables.sh
13 #
14 #  which will establish a new shell containing all the variables, or you can
15 #  'source' the script like so:
16 #
17 #      build_vars=$FEISTY_MEOW_APEX/scripts/generator/build_variables.sh
18 #      source $build_vars $build_vars
19 #
20 #  to set all of the variables in your current shell.  The full path is
21 #  necessary in these commands to allow the script to easily find itself.
22 #  The 'source' version needs to be fed the actual path to the script
23 #  because bash 'source' commands cause the first parameter (called $0) to
24 #  be set to just the path to bash itself.
25 #
26 ##############
27 # Copyright (c) 2004-$now By Author.  This program is free software; you can
28 # redistribute it and/or modify it under the terms of the GNU General Public
29 # License as published by the Free Software Foundation; either version 2 of
30 # the License or (at your option) any later version.  This is online at:
31 #     http://www.fsf.org/copyleft/gpl.html
32 # Please send any updates to: fred@gruntose.com
33 ##############
34
35 # here is where we compute the locations for the build's pieces, based on
36 # where this script is located.  we currently assume that the build scripts
37 # like this one are at the same height in the hierarchy as the clam scripts
38 # that are used in the bootstrapping process.
39
40 # get the most important bits first; the directory this script lives in and
41 # the script's name.
42 PARM_0="$0"
43 PARM_1="$1"
44
45 ##############
46
47 # helpful build function zone.
48
49 source "$FEISTY_MEOW_SCRIPTS/core/functions.sh"
50
51 ##############
52
53 # outer check on whether this already was run or not.
54 if [ -z "$BUILD_VARS_LOADED" ]; then
55
56 # perform some calculations to get the right paths from our parameters.
57 if [ ! -z "$PARM_1" ]; then
58   # use the first real parameter since this is probably the 'source' version.
59   export BUILD_SCRIPTS_PATH="$(dirname "$PARM_1")"
60   THIS_TOOL_NAME="$(basename "$PARM_1")"
61 else
62   # use the zeroth parameter, since we know nothing more about our name.
63   export BUILD_SCRIPTS_PATH="$(dirname "$PARM_0")"
64   THIS_TOOL_NAME="$(basename "$PARM_0")"
65 fi
66 BUILD_SCRIPTS_PATH="$(cd $(echo $BUILD_SCRIPTS_PATH | tr '\\\\' '/' ); \pwd)"
67
68 # figure out the other paths based on where we found this script.
69 export BUILDING_HIERARCHY="$(echo "$BUILD_SCRIPTS_PATH" | sed -e 's/\(.*\)\/[^\/]*/\1/')"
70 export CLAM_SCRIPTS="$(cd $BUILD_SCRIPTS_PATH/../clam ; \pwd)"
71 # synonym to make other builds happy.
72 export BUILDER_PATH="$BUILDING_HIERARCHY"
73
74 # set some clam parameters for compilation.  if the script can't guess the
75 # right configuration, then you will need to set them in the last 'else'
76 # below.
77 if [ ! -z "$IS_UNIX" ]; then export OPERATING_SYSTEM=UNIX;
78 elif [ ! -z "$IS_DOS" ]; then export OPERATING_SYSTEM=WIN32;
79 else
80   # the system is unknown, so we give up on guessing.
81   export OPERATING_SYSTEM=unknown
82 fi
83 if [ ! -z "$DEBUG_FEISTY_MEOW" ]; then
84   echo "[OS is \"$OPERATING_SYSTEM\"]"
85 fi
86
87 if [ ! -z "$DEBUG_FEISTY_MEOW" ]; then
88   echo "[FEISTY_MEOW_APEX is $FEISTY_MEOW_APEX]"
89 fi
90
91 #if [ "$OPERATING_SYSTEM" == "WIN32" ]; then
92 #  # harsh on the paths and make them use backwards slashes.
93 #  export SERIOUS_SLASH_TREATMENT=true
94 #fi
95
96 # new BUILD_TOP variable points at the utter top-most level of any files
97 # in the building hierarchy.
98 export BUILD_TOP="$FEISTY_MEOW_APEX"
99
100 # the production directory is the location for all the scripts and setup
101 # code needed to produce the executables for feisty meow.
102 export PRODUCTION_STORE="$BUILD_TOP/production"
103
104 ## set up the top-level for all build creations and logs and such.
105 #export FEISTY_MEOW_GENERATED_STORE="$TMP/generated-feisty_meow"
106 #if [ ! -d "$FEISTY_MEOW_GENERATED_STORE" ]; then
107 #  mkdir -p "$FEISTY_MEOW_GENERATED_STORE"
108 #fi
109 ## set up our effluent outsourcing valves.
110 #export TEMPORARIES_PILE="$FEISTY_MEOW_GENERATED_STORE/temporaries"
111 #if [ ! -d "$TEMPORARIES_PILE" ]; then
112 #  mkdir -p "$TEMPORARIES_PILE"
113 #fi
114
115 # this variable points at a folder where we store the generated products of
116 # the build, such as the binaries and installer packages.
117 export RUNTIME_PATH="$FEISTY_MEOW_GENERATED_STORE/runtime"
118 if [ ! -d "$RUNTIME_PATH" ]; then
119   mkdir -p "$RUNTIME_PATH"
120 fi
121
122 # we define a log file storage area that can be relied on by the build.
123 export FEISTY_MEOW_LOGS="$FEISTY_MEOW_GENERATED_STORE/logs"
124 if [ ! -d "$FEISTY_MEOW_LOGS" ]; then
125   mkdir -p "$FEISTY_MEOW_LOGS"
126 fi
127
128 ##############
129
130 # debugging area where we say what we think we know.
131
132 if [ ! -z "$DEBUG_FEISTY_MEOW" ]; then
133   echo scripts: $BUILD_SCRIPTS_PATH
134   echo build tools hier: $BUILDING_HIERARCHY
135   echo this tool: $THIS_TOOL_NAME
136   echo repository: $FEISTY_MEOW_APEX
137   echo clam: $CLAM_SCRIPTS
138 fi
139
140 ##############
141
142 # test out our computed variables to make sure they look right.
143 pushd / &>/dev/null # jump to the root so relative paths are caught.
144
145 # flag for whether any checks have failed.
146 got_bad=
147
148 # first the scripts directory; do we find this script there?
149 if [ ! -f "$BUILD_SCRIPTS_PATH/$THIS_TOOL_NAME" ]; then
150   echo "This script cannot locate the proper build folders.  The crucial path"
151   echo "variable seems to be '$BUILD_SCRIPTS_PATH', which"
152   echo "does not seem to contain '$THIS_TOOL_NAME' (this"
153   echo "script's apparent name)."
154   got_bad=1
155 fi
156
157 # next the clam directory; is the main variables file present there?
158 if [ -z "$got_bad" -a ! -f "$CLAM_SCRIPTS/variables.def" ]; then
159   echo "The clam directory could not be located under our build tools hierarchy."
160   echo "Please examine the configuration and make sure that this script is in a"
161   echo "directory that resides at the same height as the 'clam' directory."
162   got_bad=1
163 fi
164
165 # now compute some more paths with a bit of "heuristics" for where we can
166 # find the source code.
167 export TOOL_SOURCES="$FEISTY_MEOW_APEX/nucleus/tools"
168 if [ -z "$got_bad" -a ! -d "$TOOL_SOURCES/dependency_tool" -o ! -d "$TOOL_SOURCES/clam_tools" ]; then
169   echo "This script cannot locate the tool source code folder.  This is where the"
170   echo "dependency_tool and clam_tools folders are expected to be."
171   got_bad=1
172 fi
173
174 ############################
175   
176 # we only run the rest of the script if we know we didn't have some kind of
177 # bad thing happen earlier.
178 if [ -z "$got_bad" ]; then
179
180   # where we store the binaries used for building the rest of the code base.
181   export CLAM_BINARIES="$RUNTIME_PATH/clam_bin"
182     # the final destination for the new binaries which provide the hoople
183     # build with all the applications it needs to get going.
184   export TARGETS_STORE="$RUNTIME_PATH/binaries"
185     # targets directory is meaningful to clam, which will use it for output.
186   export INTERMEDIATE_STORE="$TARGETS_STORE"
187     # where we are building the applications before they get promoted.
188
189 #hmmm: could allow override on this if already set.
190   # calculate which build ini file to use.
191   export BUILD_PARAMETER_FILE="$PRODUCTION_STORE/feisty_meow_config.ini"
192   if [ ! -f "$BUILD_PARAMETER_FILE" ]; then
193     echo "Cannot find a useful build configuration file."
194   fi
195   
196   # pick the executable's file ending based on the platform.
197   if [ "$OPERATING_SYSTEM" == "UNIX" ]; then export EXE_ENDING=;
198   elif [ "$OPERATING_SYSTEM" == "WIN32" ]; then export EXE_ENDING=.exe;
199   else
200     echo "The OPERATING_SYSTEM variable is unset or unknown.  Bailing out."
201   fi
202   
203   # we should have established our internal variables now, so let's try
204   # using them.
205   export PATH=$(dos_to_unix_path $CLAM_BINARIES):$PATH
206   
207   # load up the helper variables for visual studio on winders.
208   if [ "$OPERATING_SYSTEM" == "WIN32" ]; then
209     source "$BUILD_SCRIPTS_PATH/vis_stu_vars.sh"
210   else
211     export LD_LIBRARY_PATH="$TARGETS_STORE"
212   fi
213   
214   popd &>/dev/null # checking is over, jump back to the starting point.
215   
216   ############################
217   
218   # at this point, all the build related variables should be valid.
219   
220   if [ -z "$INCLUDED_FROM_BOOTSTRAP" \
221       -a -z "$PARM_1" ]; then
222     # we are running as a stand-alone script, so we stay resident with our
223     # current set of variables.
224     bash
225   fi
226
227   # sentinel that tells us this script was pulled in.
228   export BUILD_VARS_LOADED=true
229
230 fi
231
232 fi  # outer wrapper for already ran build vars check.
233
234 ##############
235
236 # hook clam into the compilation system.
237 # this always needs to be defined since functions aren't exported.
238 function make()
239 {
240   /usr/bin/make -I "$CLAM_SCRIPTS" $*
241 }
242
243