7466031b3cf0664d7776626805f417051e4ab89e
[feisty_meow.git] / scripts / generator / produce_feisty_meow.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
29 # signals that we're doing a fresh build to the variables script.
30 export INCLUDED_FROM_BOOTSTRAP=true
31
32 # pull in our build variables using the path to this script.
33 export BUILD_SCRIPTS_PATH="$( \cd "$(\dirname "$0")" && /bin/pwd )"
34 #echo build scripts dir initial value: $BUILD_SCRIPTS_PATH
35 BUILD_SCRIPTS_PATH="$(echo $BUILD_SCRIPTS_PATH | tr '\\\\' '/' )"
36 #hmmm: why four backslashes above?  trying two in our unix virtual root code below.
37 #echo build scripts dir after chewing: $BUILD_SCRIPTS_PATH
38
39 # load in feisty meow basic scripts, if not already loaded.
40 if [ -z "$FEISTY_MEOW_SCRIPTS_LOADED" ]; then
41   bash "$BUILD_SCRIPTS_PATH/../core/reconfigure_feisty_meow.sh"
42   source "$BUILD_SCRIPTS_PATH/../core/launch_feisty_meow.sh"
43 fi
44
45 source "$FEISTY_MEOW_SCRIPTS/core/functions.sh"
46
47 # translate to dos format if there's a cygdrive in there; otherwise microsoft's tools
48 # will hose up completely due to unknown paths.
49 export FEISTY_MEOW_APEX="$(unix_to_dos_path $FEISTY_MEOW_APEX)"
50
51 # load in build variables based on our deduced paths.
52 source "$BUILD_SCRIPTS_PATH/build_variables.sh" "$BUILD_SCRIPTS_PATH/build_variables.sh"
53
54 ##############
55
56 # creates the directory for our binaries and gives it a reasonable paths configuration.
57 function prepare_binaries_dir()
58 {
59   # we'll store binaries here from the bootstrap process.
60   if [ ! -d "$CLAM_BINARIES" ]; then
61     echo "creating binary dir now in $CLAM_BINARIES"
62     mkdir -p "$CLAM_BINARIES"
63   fi
64   if [ ! -f "$CLAM_BINARIES/paths.ini" ]; then
65     cp "$PRODUCTION_STORE/paths.ini" "$CLAM_BINARIES"
66     echo "copied paths.ini to binary dir."
67   fi
68   # set the cygwin root path if we're on cygwin.
69   whichable cygpath
70   if [ $? -eq 0 ]; then
71     # found cygpath, so run it now to get the dossy path of the root ('/' folder).
72     found_root="$(cygpath -w -m /)"
73     if [ $? -ne 0 ]; then
74       echo "Failure to find virtual Unix root folder with cygpath."
75       exit 1322
76     fi
77 echo "found root as '$found_root'"
78     # translate any backslashes to forward thinking slashes.    
79     found_root=$(echo $found_root | tr '\\' '/')
80 echo "processed root is now: '$found_root'"
81     # edit the entry in place to correct the default path.
82     sed -i -e "s%VirtualUnixRoot=.*%VirtualUnixRoot=$found_root%" "$CLAM_BINARIES/paths.ini" 
83 echo "paths file now has:"
84 cat "$CLAM_BINARIES/paths.ini" 
85   fi
86 }
87
88 ##############
89
90 # turn off sounds to avoid running the sound player that's not been built yet.
91 unset CLAM_ERROR_SOUND
92 unset CLAM_FINISH_SOUND
93
94 ##############
95
96 echo "Build bootstrap process has started."
97
98 # preconditions for the build process...
99
100 # set up our output directories etc.
101 prepare_binaries_dir
102
103 # set a flag for this process so we can omit certain compilations as necessary.
104 export BOOT_STRAPPING=true
105
106 # enable this macro to get a much noisier build.
107 #export BE_NOISY=NOISY=t
108
109 ##############
110
111 # these default flags turn off unnecessary support when we're rebuilding the
112 # minimal toolset needed for a successful build of hoople.
113 declare -a BUILD_DEFAULTS=( "BOOT_STRAPPING=t" "OPTIMIZE=t" "REBUILD=t" "DEBUG=" )
114   # bootstrapping is always turned on for this particular script.
115   # we also always optimize these builds and turn off the debug flag.
116   # rebuild ensures that the new applications are made fresh: "REBUILD=t"
117   #   it can be turned off when the build bootstrapper is being tested.
118   # noisy can be added to spew lots of text: "NOISY=t"
119   #   this can help with compilation issues by showing all the flags.
120
121 function make_code {
122   make $* $BE_NOISY ${BUILD_DEFAULTS[@]}
123   if [ $? != 0 ]; then
124     echo "Failed to make on: $*"
125     exit 2323
126   fi
127 }
128
129 # removes pcdos eol from any scripts.  that assumes that the bootstrap script
130 # itself isn't polluted with them.
131 function strip_cr {
132   ctrl_m=$'\015'
133   for i in $*; do
134     tempgrep="$(mktemp "$TEMPORARIES_PILE/tempgrep.XXXXXX")"
135     grep -l "$ctrl_m" "$i" >$tempgrep
136     if [ ! -z "$(cat $tempgrep)" ]; then
137       temp="$(mktemp "$TEMPORARIES_PILE/tempsed.XXXXXX")"
138       sed -e "s/$ctrl_m$//" <$i >$temp
139       mv -f $temp $i
140     fi
141     rm "$tempgrep"
142   done
143 }
144
145 # the promote function moves a file from the exe directory into the build's
146 # bin directory.  it performs the copy step and makes the file executable.
147 # the original name should just be the root of the filename without any
148 # extension.
149 # NOTE: this depends on the operating system having been chosen above!
150 if [ "$OPERATING_SYSTEM" = "UNIX" ]; then
151   function promote {
152     prepare_binaries_dir
153
154     if [ ! -f "$INTERMEDIATE_STORE/$1" ]; then
155       echo "Failed to build the application $1--quitting now."
156       exit 1892
157     fi
158     cp "$INTERMEDIATE_STORE/$1" "$CLAM_BINARIES/$1"
159     strip "$CLAM_BINARIES/$1"
160     chmod 755 "$CLAM_BINARIES/$1"
161   }
162 elif [ "$OPERATING_SYSTEM" = "WIN32" ]; then
163   function promote {
164     prepare_binaries_dir
165
166     if [ ! -f "$INTERMEDIATE_STORE/$1.exe" ]; then
167       echo "Failed to build the application $1.exe--quitting now."
168       exit 1892
169     fi
170     cp "$INTERMEDIATE_STORE/$1.exe" "$CLAM_BINARIES"
171     chmod 755 "$CLAM_BINARIES/$1.exe"
172   }
173 else
174   echo "The OPERATING_SYSTEM variable is unset or unknown.  Bailing out."
175   exit 1822
176 fi
177
178 ##############
179
180 # start the actual build process now...
181
182 # load in the feisty meow building environment.
183 source "$BUILD_SCRIPTS_PATH/build_variables.sh" "$BUILD_SCRIPTS_PATH/build_variables.sh"
184
185 # clean out any current contents.
186 bash "$BUILD_SCRIPTS_PATH/whack_build.sh" clean
187
188 # make this again so no one gets cranky.
189 mkdir -p "$FEISTY_MEOW_LOGS"
190
191 toolset_names=(makedep value_tagger version_stamper vsts_version_fixer write_build_config short_path sleep_ms zap_process playsound create_guid)
192
193 if [ -z "$SAVE_BINARIES" ]; then
194   for i in ${toolset_names[*]}; do
195     whack_name="$CLAM_BINARIES/$i$EXE_ENDING"
196 #echo removing "$whack_name"
197     rm -f "$whack_name"
198   done
199 fi
200
201 # rebuild the dependency tool.  needed by everything, pretty much, but
202 # since it's from the xfree project, it doesn't need any of our libraries.
203 if [ ! -f "$CLAM_BINARIES/makedep$EXE_ENDING" ]; then
204   pushd "$TOOL_SOURCES/dependency_tool" &>/dev/null
205   make_code pre_compilation NO_DEPS=t OMIT_VERSIONS=t
206   make_code NO_DEPS=t OMIT_VERSIONS=t
207   if [ ! -f "$INTERMEDIATE_STORE/makedep$EXE_ENDING" ]; then
208     echo ""
209     echo ""
210     echo "The build of the makedep tool has failed.  Unknown causes...  Argh."
211     echo ""
212     exit 1820
213   fi
214   # make the tool available for the rest of the build.
215   promote makedep
216   popd &>/dev/null
217 fi
218
219 # rebuild the version tools and other support applications.
220 if [ ! -f "$CLAM_BINARIES/value_tagger$EXE_ENDING" \
221     -o ! -f "$CLAM_BINARIES/version_stamper$EXE_ENDING" \
222     -o ! -f "$CLAM_BINARIES/vsts_version_fixer$EXE_ENDING" \
223     -o ! -f "$CLAM_BINARIES/write_build_config$EXE_ENDING" ]; then
224   pushd "$TOOL_SOURCES/clam_tools" &>/dev/null
225   make_code pre_compilation OMIT_VERSIONS=t
226   make_code OMIT_VERSIONS=t
227
228 #hmmm: really this should check all the expected applications.
229 #      nice to just have an array of the things built by this guy.
230   if [ ! -f "$INTERMEDIATE_STORE/version_stamper$EXE_ENDING" ]; then
231     echo ""
232     echo ""
233     echo "The build of the version_stamper tool has failed.  Unknown causes...  Argh."
234     echo ""
235     exit 1821
236   fi
237
238   promote value_tagger # tool scrambles through headers to standardize outcomes.
239   promote version_stamper  # used for version stamping.
240   promote vsts_version_fixer  # used for version stamping.
241   promote write_build_config  # creates a header of build-specific config info.
242
243   popd &>/dev/null
244 fi
245
246 # build a few other utilities.
247 if [ ! -f "$CLAM_BINARIES/short_path$EXE_ENDING" \
248     -o ! -f "$CLAM_BINARIES/sleep_ms$EXE_ENDING" \
249     -o ! -f "$CLAM_BINARIES/create_guid$EXE_ENDING" \
250     -o ! -f "$CLAM_BINARIES/zap_process$EXE_ENDING" \
251     -o ! -f "$CLAM_BINARIES/playsound$EXE_ENDING" ]; then
252   pushd "$TOOL_SOURCES/simple_utilities" &>/dev/null
253   make_code pre_compilation OMIT_VERSIONS=t
254   make_code OMIT_VERSIONS=t
255
256   promote create_guid  # globally unique ID creator.
257   promote playsound  # sound playback tool.
258   promote short_path  # provides short path names for exes on windows.
259   promote sleep_ms  # sleep tool is used in some scripts.
260   promote zap_process  # kills a process in the task list.
261
262   popd &>/dev/null
263 fi
264
265 echo "The build binaries have been re-created (or were already present)."
266
267 # we won't do the full build if they told us to just do the bootstrap.
268 if [ -z "$JUST_BOOTSTRAP_APPS" ]; then
269   echo Cleaning up the temporary files that were built.
270   bash "$BUILD_SCRIPTS_PATH/whack_build.sh" 
271 #wrong!  we don't want to whack it all. clean
272
273   # recreate our useful junk directories...
274   mkdir -p "$FEISTY_MEOW_GENERATED_STORE"
275   mkdir -p "$TEMPORARIES_PILE"
276   mkdir -p "$FEISTY_MEOW_LOGS"
277
278   echo Now starting a normal build of the repository source code.
279   pushd "$FEISTY_MEOW_APEX" &>/dev/null
280   unset BUILD_DEFAULTS
281   declare -a BUILD_DEFAULTS=( "BOOT_STRAPPING=" "OPTIMIZE=t" "DEBUG=t" "REBUILD=t" )
282   make_code
283
284   popd &>/dev/null
285 fi
286