version 1.40.130 release
[feisty_meow.git] / scripts / generator / build_variables.sh
index 6773ac56ffa2b8fcd39b74e7e3404feb17361f4d..6e8fa38e93d7367060b3561a09c8d5eac1aab471 100644 (file)
@@ -1,43 +1,38 @@
-###############################################################################
-#                                                                             #
-#  Name   : build variable calculator                                         #
-#  Author : Chris Koeritz                                                     #
-#                                                                             #
-#  Purpose:                                                                   #
-#                                                                             #
-#    This script sets up all the variables needed by the HOOPLE system for    #
-#  building the source code.  It can either be run as a bash script directly  #
-#  like so:                                                                   #
-#                                                                             #
-#      bash ~/feisty_meow/scripts/generator/build_variables.sh                #
-#                                                                             #
-#  which will establish a new shell containing all the variables, or you can  #
-#  'source' the script like so:                                               #
-#                                                                             #
-#      build_vars=~/feisty_meow/scripts/generator/build_variables.sh          #
-#      source $build_vars $build_vars                                         #
-#                                                                             #
-#  to set all of the variables in your current shell.  The full path is       #
-#  necessary in these commands to allow the script to easily find itself.     #
-#  The 'source' version needs to be fed the actual path to the script         #
-#  because bash 'source' commands cause the first parameter (called $0) to    #
-#  be set to just the path to bash itself.                                    #
-#                                                                             #
-###############################################################################
-# Copyright (c) 2004-$now By Author.  This program is free software; you can  #
-# redistribute it and/or modify it under the terms of the GNU General Public  #
-# License as published by the Free Software Foundation; either version 2 of   #
-# the License or (at your option) any later version.  This is online at:      #
-#     http://www.fsf.org/copyleft/gpl.html                                    #
-# Please send any updates to: fred@gruntose.com                               #
-###############################################################################
-
-# prerequisites for this script:
+#!/bin/bash
+
+##############
+#
+#  Name   : build variable calculator
+#  Author : Chris Koeritz
+#
+#  Purpose:
+#
+#    This script sets up all the variables needed by the HOOPLE system for
+#  building the source code.  It can either be run as a bash script directly
+#  like so:
+#
+#      bash $FEISTY_MEOW_APEX/scripts/generator/build_variables.sh
+#
+#  which will establish a new shell containing all the variables, or you can
+#  'source' the script like so:
 #
-# (1) the script should be run with a full path, so that it can decide where
-#     it lives with minimal fuss.
-# (2) on windows, the msys bin directory should already be in the path so that
-#     tools like dirname are already available.
+#      build_vars=$FEISTY_MEOW_APEX/scripts/generator/build_variables.sh
+#      source $build_vars $build_vars
+#
+#  to set all of the variables in your current shell.  The full path is
+#  necessary in these commands to allow the script to easily find itself.
+#  The 'source' version needs to be fed the actual path to the script
+#  because bash 'source' commands cause the first parameter (called $0) to
+#  be set to just the path to bash itself.
+#
+##############
+# Copyright (c) 2004-$now By Author.  This program is free software; you can
+# redistribute it and/or modify it under the terms of the GNU General Public
+# License as published by the Free Software Foundation; either version 2 of
+# the License or (at your option) any later version.  This is online at:
+#     http://www.fsf.org/copyleft/gpl.html
+# Please send any updates to: fred@gruntose.com
+##############
 
 # here is where we compute the locations for the build's pieces, based on
 # where this script is located.  we currently assume that the build scripts
@@ -53,59 +48,30 @@ PARM_1="$1"
 
 # helpful build function zone.
 
-# switches from a /X/path form to an X:/ form.
-function msys_to_dos_path() {
-  # we always remove dos slashes in favor of forward slashes.
-  echo "$1" | sed -e 's/\\/\//g' | sed -e 's/\/\([a-zA-Z]\)\/\(.*\)/\1:\/\2/'
-}
-
-# switches from an X:/ form to an /X/path form.
-function dos_to_msys_path() {
-  # we always remove dos slashes in favor of forward slashes.
-  echo "$1" | sed -e 's/\\/\//g' | sed -e 's/\([a-zA-Z]\):\/\(.*\)/\/\1\/\2/'
-}
-
-###hmmm: move test suite out to the functions file in yeti, where the definitive versions
-#        of dos to msys etc live.
-# test suite for above functions.
-#echo this should go from msys to dos:
-#  prior='/c/bogart\dingle'
-#  latter=$(msys_to_dos_path "$prior")
-#  echo went from $prior to $latter
-#echo this should go from dos to msys:
-#  prior='D:\bogart\dingle'
-#  latter=$(dos_to_msys_path "$prior")
-#  echo went from $prior to $latter
+source "$FEISTY_MEOW_SCRIPTS/core/functions.sh"
 
 ##############
 
+# outer check on whether this already was run or not.
+if [ -z "$BUILD_VARS_LOADED" ]; then
+
 # perform some calculations to get the right paths from our parameters.
 if [ ! -z "$PARM_1" ]; then
   # use the first real parameter since this is probably the 'source' version.
-  export BUILD_SCRIPTS_DIR="$(dirname "$PARM_1")"
+  export BUILD_SCRIPTS_PATH="$(dirname "$PARM_1")"
   THIS_TOOL_NAME="$(basename "$PARM_1")"
-echo sourced version buildscriptsdir is $BUILD_SCRIPTS_DIR
 else
   # use the zeroth parameter, since we know nothing more about our name.
-  export BUILD_SCRIPTS_DIR="$(dirname "$PARM_0")"
+  export BUILD_SCRIPTS_PATH="$(dirname "$PARM_0")"
   THIS_TOOL_NAME="$(basename "$PARM_0")"
-echo bashed version buildscriptsdir is $BUILD_SCRIPTS_DIR
 fi
-BUILD_SCRIPTS_DIR="$(echo $BUILD_SCRIPTS_DIR | tr '\\\\' '/' )"
-echo post tr buildscriptsdir is $BUILD_SCRIPTS_DIR
+BUILD_SCRIPTS_PATH="$(cd $(echo $BUILD_SCRIPTS_PATH | tr '\\\\' '/' ); \pwd)"
 
 # figure out the other paths based on where we found this script.
-export BUILDING_HIERARCHY="$(echo "$BUILD_SCRIPTS_DIR" | sed -e 's/\(.*\)\/[^\/]*/\1/')"
-export CLAM_DIR="$BUILD_SCRIPTS_DIR/../clam"
+export BUILDING_HIERARCHY="$(echo "$BUILD_SCRIPTS_PATH" | sed -e 's/\(.*\)\/[^\/]*/\1/')"
+export CLAM_SCRIPTS="$(cd $BUILD_SCRIPTS_PATH/../clam ; \pwd)"
 # synonym to make other builds happy.
-export BUILDER_DIR="$BUILDING_HIERARCHY"
-
-# guess the current platform.
-IS_UNIX=$(uname | grep -i linux)
-if [ -z "$IS_UNIX" ]; then IS_UNIX=$(uname | grep -i unix); fi
-if [ -z "$IS_UNIX" ]; then IS_UNIX=$(uname | grep -i darwin); fi
-IS_DOS=$(uname | grep -i ming)
-if [ -z "$IS_DOS" ]; then IS_DOS=$(uname | grep -i cygwin); fi
+export BUILDER_PATH="$BUILDING_HIERARCHY"
 
 # set some clam parameters for compilation.  if the script can't guess the
 # right configuration, then you will need to set them in the last 'else'
@@ -116,159 +82,164 @@ else
   # the system is unknown, so we give up on guessing.
   export OPERATING_SYSTEM=unknown
 fi
-if [ ! -z "$SHELL_DEBUG" ]; then
+if [ ! -z "$DEBUG_FEISTY_MEOW" ]; then
   echo "[OS is \"$OPERATING_SYSTEM\"]"
 fi
 
-# the impact of always redoing the repository directory below means that we
-# will always expect the build scripts to be located within the build they're
-# building.  that's fundamentally broken for some usages.
-# but just using the existing repository directory is fundamentally broken
-# too, since then the build variables will never re-adapt to the repository
-# you want.
-# maybe just documentation; if you are changing your repository and the build
-# scripts are in the right place, then you should unset REPOSITORY_DIR.
-# we at least check that the folder still exists now too, but that's not exact
-# knowledge that it's still the right directory.
-
-if [ -z "$REPOSITORY_DIR" -o ! -d "$REPOSITORY_DIR" ]; then
-  # we create the variable repository dir, but we keep the idiotic dos form of
-  # the path, because otherwise lots of bad things happens when passing the
-  # folders around to visual studio commands that don't allow a space after them.
-  if [ -d "$BUILDING_HIERARCHY/source" ]; then
-    # old style repository is same height as building hierarchy.
-    export REPOSITORY_DIR="$BUILDING_HIERARCHY"
-  else
-    # new style repository is a level above the build hierarchy.
-    export REPOSITORY_DIR="$(echo "$BUILDING_HIERARCHY" | sed -e 's/\(.*\)\/[^\/]*/\1/')"
-  fi
+if [ ! -z "$DEBUG_FEISTY_MEOW" ]; then
+  echo "[FEISTY_MEOW_APEX is $FEISTY_MEOW_APEX]"
 fi
 
-if [ "$OPERATING_SYSTEM" = "WIN32" ]; then
-  # make sure repository dir looks right on windoze.
-  export REPOSITORY_DIR="$(msys_to_dos_path "$REPOSITORY_DIR")"
-fi
-
-if [ ! -z "$SHELL_DEBUG" ]; then
-  echo "[REPOSITORY_DIR is $REPOSITORY_DIR]"
-fi
+#if [ "$OPERATING_SYSTEM" == "WIN32" ]; then
+#  # harsh on the paths and make them use backwards slashes.
+#  export SERIOUS_SLASH_TREATMENT=true
+#fi
 
 # new BUILD_TOP variable points at the utter top-most level of any files
 # in the building hierarchy.
-export BUILD_TOP="$REPOSITORY_DIR"
-
-# this variable points at a folder where we store most of the generated products
-# of the build.  these tend to be the things that will be used for packaging into
-# different types of products.
-export PRODUCTION_DIR="$BUILD_TOP/production"
+export BUILD_TOP="$FEISTY_MEOW_APEX"
+
+# the production directory is the location for all the scripts and setup
+# code needed to produce the executables for feisty meow.
+export PRODUCTION_STORE="$BUILD_TOP/production"
+
+## set up the top-level for all build creations and logs and such.
+#export FEISTY_MEOW_GENERATED_STORE="$TMP/generated-feisty_meow"
+#if [ ! -d "$FEISTY_MEOW_GENERATED_STORE" ]; then
+#  mkdir -p "$FEISTY_MEOW_GENERATED_STORE"
+#fi
+## set up our effluent outsourcing valves.
+#export TEMPORARIES_PILE="$FEISTY_MEOW_GENERATED_STORE/temporaries"
+#if [ ! -d "$TEMPORARIES_PILE" ]; then
+#  mkdir -p "$TEMPORARIES_PILE"
+#fi
+
+# this variable points at a folder where we store the generated products of
+# the build, such as the binaries and installer packages.
+export RUNTIME_PATH="$FEISTY_MEOW_GENERATED_STORE/runtime"
+if [ ! -d "$RUNTIME_PATH" ]; then
+  mkdir -p "$RUNTIME_PATH"
+fi
 
 # we define a log file storage area that can be relied on by the build.
-export LOGS_DIR="$PRODUCTION_DIR/logs"
-if [ ! -d "$LOGS_DIR" ]; then
-  mkdir -p "$LOGS_DIR"
+export FEISTY_MEOW_LOGS="$FEISTY_MEOW_GENERATED_STORE/logs"
+if [ ! -d "$FEISTY_MEOW_LOGS" ]; then
+  mkdir -p "$FEISTY_MEOW_LOGS"
 fi
 
-# hook clam into the compilation system.
-function make()
-{
-  /usr/bin/make -I "$CLAM_DIR" $*
-}
-
 ##############
 
 # debugging area where we say what we think we know.
 
-#echo scripts: $BUILD_SCRIPTS_DIR
-#echo build tools hier: $BUILDING_HIERARCHY
-#echo this tool: $THIS_TOOL_NAME
-#echo repository: $REPOSITORY_DIR
-#echo clam: $CLAM_DIR
-#echo makeflags: $MAKEFLAGS
+if [ ! -z "$DEBUG_FEISTY_MEOW" ]; then
+  echo scripts: $BUILD_SCRIPTS_PATH
+  echo build tools hier: $BUILDING_HIERARCHY
+  echo this tool: $THIS_TOOL_NAME
+  echo repository: $FEISTY_MEOW_APEX
+  echo clam: $CLAM_SCRIPTS
+fi
 
 ##############
 
 # test out our computed variables to make sure they look right.
 pushd / &>/dev/null # jump to the root so relative paths are caught.
 
+# flag for whether any checks have failed.
+got_bad=
+
 # first the scripts directory; do we find this script there?
-if [ ! -f "$BUILD_SCRIPTS_DIR/$THIS_TOOL_NAME" ]; then
+if [ ! -f "$BUILD_SCRIPTS_PATH/$THIS_TOOL_NAME" ]; then
   echo "This script cannot locate the proper build folders.  The crucial path"
-  echo "variable seems to be '$BUILD_SCRIPTS_DIR', which"
+  echo "variable seems to be '$BUILD_SCRIPTS_PATH', which"
   echo "does not seem to contain '$THIS_TOOL_NAME' (this"
   echo "script's apparent name)."
+  got_bad=1
 fi
 
 # next the clam directory; is the main variables file present there?
-if [ ! -f "$CLAM_DIR/variables.def" ]; then
+if [ -z "$got_bad" -a ! -f "$CLAM_SCRIPTS/variables.def" ]; then
   echo "The clam directory could not be located under our build tools hierarchy."
   echo "Please examine the configuration and make sure that this script is in a"
   echo "directory that resides at the same height as the 'clam' directory."
+  got_bad=1
 fi
 
 # now compute some more paths with a bit of "heuristics" for where we can
 # find the source code.
-export TOOL_SOURCES="$REPOSITORY_DIR/core/tools"
-if [ ! -d "$TOOL_SOURCES/dependency_tool" -o ! -d "$TOOL_SOURCES/clam_tools" ]; then
-  if [ ! -d "$TOOL_SOURCES/dependency_tool" -o ! -d "$TOOL_SOURCES/clam_tools" ]; then
-    echo "This script cannot locate the tool source code folder.  This is where the"
-    echo "dependency_tool and clam_tools folders are expected to be."
+export TOOL_SOURCES="$FEISTY_MEOW_APEX/nucleus/tools"
+if [ -z "$got_bad" -a ! -d "$TOOL_SOURCES/dependency_tool" -o ! -d "$TOOL_SOURCES/clam_tools" ]; then
+  echo "This script cannot locate the tool source code folder.  This is where the"
+  echo "dependency_tool and clam_tools folders are expected to be."
+  got_bad=1
+fi
+
+############################
+  
+# we only run the rest of the script if we know we didn't have some kind of
+# bad thing happen earlier.
+if [ -z "$got_bad" ]; then
+
+  # where we store the binaries used for building the rest of the code base.
+  export CLAM_BINARIES="$RUNTIME_PATH/clam_bin"
+    # the final destination for the new binaries which provide the
+    # build with all the applications it needs to get going.
+  export TARGETS_STORE="$RUNTIME_PATH/binaries"
+    # targets directory is meaningful to clam, which will use it for output.
+  export INTERMEDIATE_STORE="$TARGETS_STORE"
+    # where we are building the applications before they get promoted.
+
+#hmmm: could allow override on this if already set.
+  # calculate which build ini file to use.
+  export BUILD_PARAMETER_FILE="$PRODUCTION_STORE/feisty_meow_config.ini"
+  if [ ! -f "$BUILD_PARAMETER_FILE" ]; then
+    echo "Cannot find a useful build configuration file."
+  fi
+  
+  # pick the executable's file ending based on the platform.
+  if [ "$OPERATING_SYSTEM" == "UNIX" ]; then export EXE_ENDING=;
+  elif [ "$OPERATING_SYSTEM" == "WIN32" ]; then export EXE_ENDING=.exe;
+  else
+    echo "The OPERATING_SYSTEM variable is unset or unknown.  Bailing out."
+  fi
+  
+  # we should have established our internal variables now, so let's try
+  # using them.
+  export PATH=$(dos_to_unix_path $CLAM_BINARIES):$PATH
+  
+  # load up the helper variables for visual studio on winders.
+  if [ "$OPERATING_SYSTEM" == "WIN32" ]; then
+    source "$BUILD_SCRIPTS_PATH/vis_stu_vars.sh"
+  else
+    export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:$TARGETS_STORE"
+  fi
+  
+  popd &>/dev/null # checking is over, jump back to the starting point.
+  
+  ############################
+  
+  # at this point, all the build related variables should be valid.
+  
+  if [ -z "$INCLUDED_FROM_BOOTSTRAP" \
+      -a -z "$PARM_1" ]; then
+    # we are running as a stand-alone script, so we stay resident with our
+    # current set of variables.
+    bash
   fi
-fi
-
-# where we store the binaries used for building the rest of the code base.
-export BINARY_DIR="$PRODUCTION_DIR/clam_bin"
-  # the final destination for the new binaries which provide the hoople
-  # build with all the apps it needs to get going.
-export TARGETS_DIR="$PRODUCTION_DIR/binaries"
-  # targets directory is meaningful to clam, which will use it for output.
-export INTERMEDIATE_EXE_DIR="$TARGETS_DIR"
-  # where we are building the apps before they get promoted.
-
-export WASTE_DIR="$PRODUCTION_DIR/waste"
-if [ ! -d "$WASTE_DIR" ]; then
-  mkdir -p "$WASTE_DIR"
-fi
-export TEMPORARIES_DIR="$WASTE_DIR/temporaries"
-if [ ! -d "$TEMPORARIES_DIR" ]; then
-  mkdir -p "$TEMPORARIES_DIR"
-fi
-
-# calculate which build ini file to use.
-export BUILD_PARAMETER_FILE="$PRODUCTION_DIR/feisty_meow_config.ini"
-if [ ! -f "$BUILD_PARAMETER_FILE" ]; then
-  echo "Cannot find a useful build configuration file."
-fi
-
-# pick the executable's file ending based on the platform.
-if [ "$OPERATING_SYSTEM" == "UNIX" ]; then export EXE_ENDING=;
-elif [ "$OPERATING_SYSTEM" == "WIN32" ]; then export EXE_ENDING=.exe;
-else
-  echo "The OPERATING_SYSTEM variable is unset or unknown.  Bailing out."
-fi
 
-# we should have established our internal variables now, so let's try
-# using them.
-export PATH=$BINARY_DIR:$PATH
+  # sentinel that tells us this script was pulled in.
+  export BUILD_VARS_LOADED=true
 
-# load up the helper variables for visual studio on winders.
-if [ "$OPERATING_SYSTEM" == "WIN32" ]; then
-  source "$BUILD_SCRIPTS_DIR/vis_stu_vars.sh"
-else
-  export LD_LIBRARY_PATH="$TARGETS_DIR"
 fi
 
-popd &>/dev/null # checking is over, jump back to the starting point.
-
-############################################################################
+fi  # outer wrapper for already ran build vars check.
 
-# at this point, all the build related variables should be valid.
+##############
 
-if [ -z "$INCLUDED_FROM_BOOTSTRAP" \
-    -a -z "$PARM_1" ]; then
-  # we are running as a stand-alone script, so we stay resident with our
-  # current set of variables.
-  bash
-fi
+# hook clam into the compilation system.
+# this always needs to be defined since functions aren't exported.
+function make()
+{
+  /usr/bin/make -I "$CLAM_SCRIPTS" $*
+}
 
-############################################################################