updated to remove some msys refs.
[feisty_meow.git] / scripts / generator / bootstrap_build.sh
1 ##############
2 #  Name   : initial setup script for HOOPLE
3 #  Author : Chris Koeritz
4 #  Purpose:
5 #    This script can bootstrap the HOOPLE libraries from a state where none   #
6 #  of the required binaries are built yet.  It will build the tools that the  #
7 #  CLAM system and HOOPLE need to get a build done.  Then the script builds   #
8 #  the whole source tree as a test of the code's overall health.              #
9 ##############
10 # Copyright (c) 2004-$now By Author.  This program is free software; you can  #
11 # redistribute it and/or modify it under the terms of the GNU General Public  #
12 # License as published by the Free Software Foundation; either version 2 of   #
13 # the License or (at your option) any later version.  This is online at:      #
14 #     http://www.fsf.org/copyleft/gpl.html                                    #
15 # Please send any updates to: fred@gruntose.com                               #
16 ##############
17
18 # prerequisites for this script:
19 #
20 # (1) the script should be run with a full path, so that it can decide where
21 #     it lives with minimal fuss.
22 # (2) on windows, the unix tools bin directory should already be in the path
23 #     so that tools like dirname are already available.  use msys or cygwin
24 #     at your discretion and your own risk.
25
26 # make sure we know how to find our bash bins.
27 export PATH=/bin:$PATH
28 # signals that we're doing a fresh build to the variables script.
29 export INCLUDED_FROM_BOOTSTRAP=true
30 # pull in our build variables using the path to this script.
31 export BUILD_SCRIPTS_DIR="$( \cd "$(\dirname "$0")" && \pwd )"
32 echo build script initial from bootstrap: $BUILD_SCRIPTS_DIR
33 BUILD_SCRIPTS_DIR="$(echo $BUILD_SCRIPTS_DIR | tr '\\\\' '/' )"
34 echo build script after: $BUILD_SCRIPTS_DIR
35 # load in feisty meow basic scripts, if not already loaded.
36 source "$BUILD_SCRIPTS_DIR/../core/launch_feisty_meow.sh"
37 # load in build variables based on our deduced paths.
38 source "$BUILD_SCRIPTS_DIR/build_variables.sh" "$BUILD_SCRIPTS_DIR/build_variables.sh"
39
40 ##############
41
42 # creates the directory for our binaries and gives it a reasonable paths configuration.
43 function prepare_binaries_dir()
44 {
45   # we'll store binaries here from the bootstrap process.
46   if [ ! -d "$BINARY_DIR" ]; then
47     echo "creating binary dir now in $BINARY_DIR"
48     mkdir "$BINARY_DIR"
49   fi
50   if [ ! -f "$BINARY_DIR/paths.ini" ]; then
51     echo "copied paths.ini to binary dir."
52     cp "$PRODUCTION_DIR/paths.ini" "$BINARY_DIR"
53   fi
54 }
55
56 ##############
57
58 # turn off sounds to avoid running the sound player that's not been built yet.
59 unset CLAM_ERROR_SOUND
60 unset CLAM_FINISH_SOUND
61
62 ##############
63
64 echo "Build bootstrap process has started."
65
66 # preconditions for the build process...
67
68 # set up our output directories etc.
69 prepare_binaries_dir
70
71 # set a flag for this process so we can omit certain compilations as necessary.
72 export BOOT_STRAPPING=true
73
74 # enable this macro to get a much noisier build.
75 #export BE_NOISY=NOISY=t
76
77 ##############
78
79 # these default flags turn off unnecessary support when we're rebuilding the
80 # minimal toolset needed for a successful build of hoople.
81 declare -a BUILD_DEFAULTS=( "BOOT_STRAPPING=t" "OPTIMIZE=t" "REBUILD=t" "DEBUG=" )
82   # bootstrapping is always turned on for this particular script.
83   # we also always optimize these builds and turn off the debug flag.
84   # rebuild ensures that the new apps are made fresh: "REBUILD=t"
85   #   it can be turned off when the build bootstrapper is being tested.
86   # noisy can be added to spew lots of text: "NOISY=t"
87   #   this can help with compilation issues by showing all the flags.
88
89 function make_code {
90   make $* $BE_NOISY ${BUILD_DEFAULTS[@]}
91   if [ $? != 0 ]; then
92     echo "Failed to make on: $*"
93     exit 2323
94   fi
95 }
96
97 # removes pcdos eol from any scripts.  that assumes that the bootstrap script
98 # itself isn't polluted with them.
99 function strip_cr {
100   ctrl_m=$'\015'
101   for i in $*; do
102     tempgrep="$(mktemp "$TEMPORARIES_DIR/tempgrep.XXXXXX")"
103     grep -l "$ctrl_m" "$i" >$tempgrep
104     if [ ! -z "$(cat $tempgrep)" ]; then
105       temp="$(mktemp "$TEMPORARIES_DIR/tempsed.XXXXXX")"
106       sed -e "s/$ctrl_m$//" <$i >$temp
107       mv -f $temp $i
108     fi
109     rm "$tempgrep"
110   done
111 }
112
113 # the promote function moves a file from the exe directory into the build's
114 # bin directory.  it performs the copy step and makes the file executable.
115 # the original name should just be the root of the filename without any
116 # extension.
117 # NOTE: this depends on the operating system having been chosen above!
118 if [ "$OPERATING_SYSTEM" = "UNIX" ]; then
119   function promote {
120     prepare_binaries_dir
121
122     if [ ! -f "$INTERMEDIATE_EXE_DIR/$1" ]; then
123       echo "Failed to build the application $1--quitting now."
124       exit 1892
125     fi
126     cp "$INTERMEDIATE_EXE_DIR/$1" "$BINARY_DIR/$1"
127     strip "$BINARY_DIR/$1"
128     chmod 755 "$BINARY_DIR/$1"
129   }
130 elif [ "$OPERATING_SYSTEM" = "WIN32" ]; then
131   function promote {
132     prepare_binaries_dir
133
134     if [ ! -f "$INTERMEDIATE_EXE_DIR/$1.exe" ]; then
135       echo "Failed to build the application $1.exe--quitting now."
136       exit 1892
137     fi
138     cp "$INTERMEDIATE_EXE_DIR/$1.exe" "$BINARY_DIR"
139     chmod 755 "$BINARY_DIR/$1.exe"
140   }
141 else
142   echo "The OPERATING_SYSTEM variable is unset or unknown.  Bailing out."
143   exit 1822
144 fi
145
146 ##############
147
148 # start the actual build process now...
149
150 # recreate our useful waste directories and other things...
151 source "$BUILD_SCRIPTS_DIR/build_variables.sh" "$BUILD_SCRIPTS_DIR/build_variables.sh"
152
153 # clean out any current contents.
154 bash "$BUILD_SCRIPTS_DIR/whack_build.sh" clean
155
156 # make this again so no one gets cranky.
157 mkdir -p "$LOGS_DIR"
158
159 toolset_names=(makedep value_tagger version_stamper vsts_version_fixer write_build_config short_path sleep_ms zap_process playsound create_guid)
160
161 if [ -z "$SAVE_BINARIES" ]; then
162   for i in ${toolset_names[*]}; do
163     whack_name="$BINARY_DIR/$i$EXE_ENDING"
164 #echo removing "$whack_name"
165     rm -f "$whack_name"
166   done
167 fi
168
169 # make the clam shell scripts executable.
170 chmod 755 "$CLAM_DIR"/*.sh
171 chmod 755 "$CLAM_DIR"/cpp/*.sh
172 #chmod 755 "$CLAM_DIR"/csharp/*.sh
173
174 # rebuild the dependency tool.  needed by everything, pretty much, but
175 # since it's from the xfree project, it doesn't need any of our libraries.
176 if [ ! -f "$BINARY_DIR/makedep$EXE_ENDING" ]; then
177   pushd "$TOOL_SOURCES/dependency_tool" &>/dev/null
178   make_code pre_compilation NO_DEPS=t OMIT_VERSIONS=t
179   make_code NO_DEPS=t OMIT_VERSIONS=t
180   if [ ! -f "$INTERMEDIATE_EXE_DIR/makedep$EXE_ENDING" ]; then
181     echo ""
182     echo ""
183     echo "The build of the makedep tool has failed.  Unknown causes...  Argh."
184     echo ""
185     exit 1820
186   fi
187   # make the tool available for the rest of the build.
188   promote makedep
189   popd &>/dev/null
190 fi
191
192 # rebuild the version tools and other support apps.
193 if [ ! -f "$BINARY_DIR/value_tagger$EXE_ENDING" \
194     -o ! -f "$BINARY_DIR/version_stamper$EXE_ENDING" \
195     -o ! -f "$BINARY_DIR/vsts_version_fixer$EXE_ENDING" \
196     -o ! -f "$BINARY_DIR/write_build_config$EXE_ENDING" ]; then
197   pushd "$TOOL_SOURCES/clam_tools" &>/dev/null
198   make_code pre_compilation OMIT_VERSIONS=t
199   make_code OMIT_VERSIONS=t
200
201 #hmmm: really this should check all the expected apps.
202 #      nice to just have an array of the things built by this guy.
203   if [ ! -f "$INTERMEDIATE_EXE_DIR/version_stamper$EXE_ENDING" ]; then
204     echo ""
205     echo ""
206     echo "The build of the version_stamper tool has failed.  Unknown causes...  Argh."
207     echo ""
208     exit 1821
209   fi
210
211   promote value_tagger # tool scrambles through headers to standardize outcomes.
212   promote version_stamper  # used for version stamping.
213   promote vsts_version_fixer  # used for version stamping.
214   promote write_build_config # creates a header of build-specific config info.
215
216   popd &>/dev/null
217 fi
218
219 # build a few other utilities.
220 if [ ! -f "$BINARY_DIR/short_path$EXE_ENDING" \
221     -o ! -f "$BINARY_DIR/sleep_ms$EXE_ENDING" \
222     -o ! -f "$BINARY_DIR/create_guid$EXE_ENDING" \
223     -o ! -f "$BINARY_DIR/zap_process$EXE_ENDING" \
224     -o ! -f "$BINARY_DIR/playsound$EXE_ENDING" ]; then
225   pushd "$TOOL_SOURCES/simple_utilities" &>/dev/null
226   make_code pre_compilation OMIT_VERSIONS=t
227   make_code OMIT_VERSIONS=t
228
229   promote create_guid  # globally unique ID creator.
230   promote playsound  # sound playback tool.
231   promote short_path  # provides short path names for exes on windows.
232   promote sleep_ms  # sleep tool is used in some scripts.
233   promote zap_process  # kills a process in the task list.
234
235   popd &>/dev/null
236 fi
237
238 echo "The build binaries have been re-created (or were already present)."
239
240 # we won't do the full build if they told us to just do the bootstrap.
241 if [ -z "$JUST_BOOTSTRAP_APPS" ]; then
242   echo Cleaning up the temporary files that were built.
243   bash "$BUILD_SCRIPTS_DIR/whack_build.sh" clean
244
245   # recreate our useful junk directories...
246   mkdir -p "$WASTE_DIR"
247   mkdir -p "$TEMPORARIES_DIR"
248   mkdir -p "$LOGS_DIR"
249
250   echo Now starting a normal build of the repository source code.
251   pushd "$FEISTY_MEOW_DIR" &>/dev/null
252   unset BUILD_DEFAULTS
253   declare -a BUILD_DEFAULTS=( "BOOT_STRAPPING=" "OPTIMIZE=t" "DEBUG=t" "REBUILD=t" )
254   make_code
255
256   popd &>/dev/null
257 fi
258