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