version 1.40.130 release
[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 # perform some calculations to get the right paths from our parameters.
59 if [ ! -z "$PARM_1" ]; then
60   # use the first real parameter since this is probably the 'source' version.
61   export BUILD_SCRIPTS_PATH="$(dirname "$PARM_1")"
62   THIS_TOOL_NAME="$(basename "$PARM_1")"
63 else
64   # use the zeroth parameter, since we know nothing more about our name.
65   export BUILD_SCRIPTS_PATH="$(dirname "$PARM_0")"
66   THIS_TOOL_NAME="$(basename "$PARM_0")"
67 fi
68 BUILD_SCRIPTS_PATH="$(cd $(echo $BUILD_SCRIPTS_PATH | tr '\\\\' '/' ); \pwd)"
69
70 # figure out the other paths based on where we found this script.
71 export BUILDING_HIERARCHY="$(echo "$BUILD_SCRIPTS_PATH" | sed -e 's/\(.*\)\/[^\/]*/\1/')"
72 export CLAM_SCRIPTS="$(cd $BUILD_SCRIPTS_PATH/../clam ; \pwd)"
73 # synonym to make other builds happy.
74 export BUILDER_PATH="$BUILDING_HIERARCHY"
75
76 # set some clam parameters for compilation.  if the script can't guess the
77 # right configuration, then you will need to set them in the last 'else'
78 # below.
79 if [ ! -z "$IS_UNIX" ]; then export OPERATING_SYSTEM=UNIX;
80 elif [ ! -z "$IS_DOS" ]; then export OPERATING_SYSTEM=WIN32;
81 else
82   # the system is unknown, so we give up on guessing.
83   export OPERATING_SYSTEM=unknown
84 fi
85 if [ ! -z "$DEBUG_FEISTY_MEOW" ]; then
86   echo "[OS is \"$OPERATING_SYSTEM\"]"
87 fi
88
89 if [ ! -z "$DEBUG_FEISTY_MEOW" ]; then
90   echo "[FEISTY_MEOW_APEX is $FEISTY_MEOW_APEX]"
91 fi
92
93 #if [ "$OPERATING_SYSTEM" == "WIN32" ]; then
94 #  # harsh on the paths and make them use backwards slashes.
95 #  export SERIOUS_SLASH_TREATMENT=true
96 #fi
97
98 # new BUILD_TOP variable points at the utter top-most level of any files
99 # in the building hierarchy.
100 export BUILD_TOP="$FEISTY_MEOW_APEX"
101
102 # the production directory is the location for all the scripts and setup
103 # code needed to produce the executables for feisty meow.
104 export PRODUCTION_STORE="$BUILD_TOP/production"
105
106 ## set up the top-level for all build creations and logs and such.
107 #export FEISTY_MEOW_GENERATED_STORE="$TMP/generated-feisty_meow"
108 #if [ ! -d "$FEISTY_MEOW_GENERATED_STORE" ]; then
109 #  mkdir -p "$FEISTY_MEOW_GENERATED_STORE"
110 #fi
111 ## set up our effluent outsourcing valves.
112 #export TEMPORARIES_PILE="$FEISTY_MEOW_GENERATED_STORE/temporaries"
113 #if [ ! -d "$TEMPORARIES_PILE" ]; then
114 #  mkdir -p "$TEMPORARIES_PILE"
115 #fi
116
117 # this variable points at a folder where we store the generated products of
118 # the build, such as the binaries and installer packages.
119 export RUNTIME_PATH="$FEISTY_MEOW_GENERATED_STORE/runtime"
120 if [ ! -d "$RUNTIME_PATH" ]; then
121   mkdir -p "$RUNTIME_PATH"
122 fi
123
124 # we define a log file storage area that can be relied on by the build.
125 export FEISTY_MEOW_LOGS="$FEISTY_MEOW_GENERATED_STORE/logs"
126 if [ ! -d "$FEISTY_MEOW_LOGS" ]; then
127   mkdir -p "$FEISTY_MEOW_LOGS"
128 fi
129
130 ##############
131
132 # debugging area where we say what we think we know.
133
134 if [ ! -z "$DEBUG_FEISTY_MEOW" ]; then
135   echo scripts: $BUILD_SCRIPTS_PATH
136   echo build tools hier: $BUILDING_HIERARCHY
137   echo this tool: $THIS_TOOL_NAME
138   echo repository: $FEISTY_MEOW_APEX
139   echo clam: $CLAM_SCRIPTS
140 fi
141
142 ##############
143
144 # test out our computed variables to make sure they look right.
145 pushd / &>/dev/null # jump to the root so relative paths are caught.
146
147 # flag for whether any checks have failed.
148 got_bad=
149
150 # first the scripts directory; do we find this script there?
151 if [ ! -f "$BUILD_SCRIPTS_PATH/$THIS_TOOL_NAME" ]; then
152   echo "This script cannot locate the proper build folders.  The crucial path"
153   echo "variable seems to be '$BUILD_SCRIPTS_PATH', which"
154   echo "does not seem to contain '$THIS_TOOL_NAME' (this"
155   echo "script's apparent name)."
156   got_bad=1
157 fi
158
159 # next the clam directory; is the main variables file present there?
160 if [ -z "$got_bad" -a ! -f "$CLAM_SCRIPTS/variables.def" ]; then
161   echo "The clam directory could not be located under our build tools hierarchy."
162   echo "Please examine the configuration and make sure that this script is in a"
163   echo "directory that resides at the same height as the 'clam' directory."
164   got_bad=1
165 fi
166
167 # now compute some more paths with a bit of "heuristics" for where we can
168 # find the source code.
169 export TOOL_SOURCES="$FEISTY_MEOW_APEX/nucleus/tools"
170 if [ -z "$got_bad" -a ! -d "$TOOL_SOURCES/dependency_tool" -o ! -d "$TOOL_SOURCES/clam_tools" ]; then
171   echo "This script cannot locate the tool source code folder.  This is where the"
172   echo "dependency_tool and clam_tools folders are expected to be."
173   got_bad=1
174 fi
175
176 ############################
177   
178 # we only run the rest of the script if we know we didn't have some kind of
179 # bad thing happen earlier.
180 if [ -z "$got_bad" ]; then
181
182   # where we store the binaries used for building the rest of the code base.
183   export CLAM_BINARIES="$RUNTIME_PATH/clam_bin"
184     # the final destination for the new binaries which provide the
185     # build with all the applications it needs to get going.
186   export TARGETS_STORE="$RUNTIME_PATH/binaries"
187     # targets directory is meaningful to clam, which will use it for output.
188   export INTERMEDIATE_STORE="$TARGETS_STORE"
189     # where we are building the applications before they get promoted.
190
191 #hmmm: could allow override on this if already set.
192   # calculate which build ini file to use.
193   export BUILD_PARAMETER_FILE="$PRODUCTION_STORE/feisty_meow_config.ini"
194   if [ ! -f "$BUILD_PARAMETER_FILE" ]; then
195     echo "Cannot find a useful build configuration file."
196   fi
197   
198   # pick the executable's file ending based on the platform.
199   if [ "$OPERATING_SYSTEM" == "UNIX" ]; then export EXE_ENDING=;
200   elif [ "$OPERATING_SYSTEM" == "WIN32" ]; then export EXE_ENDING=.exe;
201   else
202     echo "The OPERATING_SYSTEM variable is unset or unknown.  Bailing out."
203   fi
204   
205   # we should have established our internal variables now, so let's try
206   # using them.
207   export PATH=$(dos_to_unix_path $CLAM_BINARIES):$PATH
208   
209   # load up the helper variables for visual studio on winders.
210   if [ "$OPERATING_SYSTEM" == "WIN32" ]; then
211     source "$BUILD_SCRIPTS_PATH/vis_stu_vars.sh"
212   else
213     export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:$TARGETS_STORE"
214   fi
215   
216   popd &>/dev/null # checking is over, jump back to the starting point.
217   
218   ############################
219   
220   # at this point, all the build related variables should be valid.
221   
222   if [ -z "$INCLUDED_FROM_BOOTSTRAP" \
223       -a -z "$PARM_1" ]; then
224     # we are running as a stand-alone script, so we stay resident with our
225     # current set of variables.
226     bash
227   fi
228
229   # sentinel that tells us this script was pulled in.
230   export BUILD_VARS_LOADED=true
231
232 fi
233
234 fi  # outer wrapper for already ran build vars check.
235
236 ##############
237
238 # hook clam into the compilation system.
239 # this always needs to be defined since functions aren't exported.
240 function make()
241 {
242   /usr/bin/make -I "$CLAM_SCRIPTS" $*
243 }
244
245