updated to remove some msys refs.
[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/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/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 # perform some calculations to get the right paths from our parameters.
54 if [ ! -z "$PARM_1" ]; then
55   # use the first real parameter since this is probably the 'source' version.
56   export BUILD_SCRIPTS_DIR="$(dirname "$PARM_1")"
57   THIS_TOOL_NAME="$(basename "$PARM_1")"
58 echo ==sourced version buildscriptsdir is $BUILD_SCRIPTS_DIR
59 else
60   # use the zeroth parameter, since we know nothing more about our name.
61   export BUILD_SCRIPTS_DIR="$(dirname "$PARM_0")"
62   THIS_TOOL_NAME="$(basename "$PARM_0")"
63 echo ==bashed version buildscriptsdir is $BUILD_SCRIPTS_DIR
64 fi
65 BUILD_SCRIPTS_DIR="$(cd $(echo $BUILD_SCRIPTS_DIR | tr '\\\\' '/' ); \pwd)"
66 echo "==buildvars buildscriptsdir is $BUILD_SCRIPTS_DIR"
67
68 # figure out the other paths based on where we found this script.
69 export BUILDING_HIERARCHY="$(echo "$BUILD_SCRIPTS_DIR" | sed -e 's/\(.*\)\/[^\/]*/\1/')"
70 export CLAM_DIR="$(cd $BUILD_SCRIPTS_DIR/../clam ; \pwd)"
71 echo "==buildvars clamdir is $CLAM_DIR"
72 # synonym to make other builds happy.
73 export BUILDER_DIR="$BUILDING_HIERARCHY"
74
75 # guess the current platform.
76 IS_UNIX=$(uname | grep -i linux)
77 if [ -z "$IS_UNIX" ]; then IS_UNIX=$(uname | grep -i unix); fi
78 if [ -z "$IS_UNIX" ]; then IS_UNIX=$(uname | grep -i darwin); fi
79 IS_DOS=$(uname | grep -i ming)
80 if [ -z "$IS_DOS" ]; then IS_DOS=$(uname | grep -i cygwin); fi
81
82 # set some clam parameters for compilation.  if the script can't guess the
83 # right configuration, then you will need to set them in the last 'else'
84 # below.
85 if [ ! -z "$IS_UNIX" ]; then export OPERATING_SYSTEM=UNIX;
86 elif [ ! -z "$IS_DOS" ]; then export OPERATING_SYSTEM=WIN32;
87 else
88   # the system is unknown, so we give up on guessing.
89   export OPERATING_SYSTEM=unknown
90 fi
91 if [ ! -z "$SHELL_DEBUG" ]; then
92   echo "[OS is \"$OPERATING_SYSTEM\"]"
93 fi
94
95 if [ ! -z "$SHELL_DEBUG" ]; then
96   echo "[FEISTY_MEOW_DIR is $FEISTY_MEOW_DIR]"
97 fi
98
99 # new BUILD_TOP variable points at the utter top-most level of any files
100 # in the building hierarchy.
101 export BUILD_TOP="$FEISTY_MEOW_DIR"
102 echo build top is $BUILD_TOP
103
104 # this variable points at a folder where we store most of the generated products
105 # of the build.  these tend to be the things that will be used for packaging into
106 # different types of products.
107 export PRODUCTION_DIR="$BUILD_TOP/production"
108
109 # we define a log file storage area that can be relied on by the build.
110 export LOGS_DIR="$PRODUCTION_DIR/logs"
111 if [ ! -d "$LOGS_DIR" ]; then
112   mkdir -p "$LOGS_DIR"
113 fi
114
115 # hook clam into the compilation system.
116 function make()
117 {
118   /usr/bin/make -I "$CLAM_DIR" $*
119 }
120
121 ##############
122
123 # debugging area where we say what we think we know.
124
125 #echo scripts: $BUILD_SCRIPTS_DIR
126 #echo build tools hier: $BUILDING_HIERARCHY
127 #echo this tool: $THIS_TOOL_NAME
128 #echo repository: $FEISTY_MEOW_DIR
129 #echo clam: $CLAM_DIR
130 #echo makeflags: $MAKEFLAGS
131
132 ##############
133
134 # test out our computed variables to make sure they look right.
135 pushd / &>/dev/null # jump to the root so relative paths are caught.
136
137 # flag for whether any checks have failed.
138 got_bad=
139
140 # first the scripts directory; do we find this script there?
141 if [ ! -f "$BUILD_SCRIPTS_DIR/$THIS_TOOL_NAME" ]; then
142   echo "This script cannot locate the proper build folders.  The crucial path"
143   echo "variable seems to be '$BUILD_SCRIPTS_DIR', which"
144   echo "does not seem to contain '$THIS_TOOL_NAME' (this"
145   echo "script's apparent name)."
146   got_bad=1
147 fi
148
149 # next the clam directory; is the main variables file present there?
150 if [ -z "$got_bad" -a ! -f "$CLAM_DIR/variables.def" ]; then
151   echo "The clam directory could not be located under our build tools hierarchy."
152   echo "Please examine the configuration and make sure that this script is in a"
153   echo "directory that resides at the same height as the 'clam' directory."
154   got_bad=1
155 fi
156
157 # now compute some more paths with a bit of "heuristics" for where we can
158 # find the source code.
159 export TOOL_SOURCES="$FEISTY_MEOW_DIR/nucleus/tools"
160 echo "==tool source is $TOOL_SOURCES"
161 if [ -z "$got_bad" -a ! -d "$TOOL_SOURCES/dependency_tool" -o ! -d "$TOOL_SOURCES/clam_tools" ]; then
162   echo "This script cannot locate the tool source code folder.  This is where the"
163   echo "dependency_tool and clam_tools folders are expected to be."
164   got_bad=1
165 fi
166
167 ############################
168   
169 # we only run the rest of the script if we know we didn't have some kind of
170 # bad thing happen earlier.
171 if [ -z "$got_bad" ]; then
172
173   # where we store the binaries used for building the rest of the code base.
174   export BINARY_DIR="$PRODUCTION_DIR/clam_bin"
175     # the final destination for the new binaries which provide the hoople
176     # build with all the apps it needs to get going.
177   export TARGETS_DIR="$PRODUCTION_DIR/binaries"
178     # targets directory is meaningful to clam, which will use it for output.
179   export INTERMEDIATE_EXE_DIR="$TARGETS_DIR"
180     # where we are building the apps before they get promoted.
181
182   export WASTE_DIR="$PRODUCTION_DIR/waste"
183   if [ ! -d "$WASTE_DIR" ]; then
184     mkdir -p "$WASTE_DIR"
185   fi
186   export TEMPORARIES_DIR="$WASTE_DIR/temporaries"
187   if [ ! -d "$TEMPORARIES_DIR" ]; then
188     mkdir -p "$TEMPORARIES_DIR"
189   fi
190   
191   # calculate which build ini file to use.
192   export BUILD_PARAMETER_FILE="$PRODUCTION_DIR/feisty_meow_config.ini"
193   if [ ! -f "$BUILD_PARAMETER_FILE" ]; then
194     echo "Cannot find a useful build configuration file."
195   fi
196   
197   # pick the executable's file ending based on the platform.
198   if [ "$OPERATING_SYSTEM" == "UNIX" ]; then export EXE_ENDING=;
199   elif [ "$OPERATING_SYSTEM" == "WIN32" ]; then export EXE_ENDING=.exe;
200   else
201     echo "The OPERATING_SYSTEM variable is unset or unknown.  Bailing out."
202   fi
203   
204   # we should have established our internal variables now, so let's try
205   # using them.
206   export PATH=$BINARY_DIR:$PATH
207   
208   # load up the helper variables for visual studio on winders.
209   if [ "$OPERATING_SYSTEM" == "WIN32" ]; then
210     source "$BUILD_SCRIPTS_DIR/vis_stu_vars.sh"
211   else
212     export LD_LIBRARY_PATH="$TARGETS_DIR"
213   fi
214   
215   popd &>/dev/null # checking is over, jump back to the starting point.
216   
217   ############################
218   
219   # at this point, all the build related variables should be valid.
220   
221   if [ -z "$INCLUDED_FROM_BOOTSTRAP" \
222       -a -z "$PARM_1" ]; then
223     # we are running as a stand-alone script, so we stay resident with our
224     # current set of variables.
225     bash
226   fi
227
228 fi
229