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