Skip to content

Commit

Permalink
sources/ham: Cleanup build scripts ;
Browse files Browse the repository at this point in the history
  • Loading branch information
prenaux committed Oct 23, 2022
1 parent ef602e6 commit 3d62d56
Show file tree
Hide file tree
Showing 27 changed files with 195 additions and 173 deletions.
2 changes: 0 additions & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,8 @@ jobs:
run: |
source _env.sh
. hat repos default
shell: bash
- name: Run_ci
run: |
source _env.sh
./_run_ci.sh
shell: bash
25 changes: 14 additions & 11 deletions _env.sh
Original file line number Diff line number Diff line change
@@ -1,22 +1,26 @@
#!/bin/bash
#!/bin/bash -e
#
# This is a simple environment setup to start using ham:
# source ./ham/_env.sh
#

# Don't `set -e` in a script that's sourced, otherwise will die as soon as any
# command returns an error code.
# set -e

SCRIPT_SOURCED=$((return 0 2>/dev/null) && echo yes || echo "")
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
if [ -z "$SCRIPT_SOURCED" ]; then
echo "W/Should only be used while sourced."
fi
export HAM_HOME="$SCRIPT_DIR"
export WORK="$( cd "$SCRIPT_DIR/.." && pwd )"
if [ -z "$BASH_START_PATH" ]; then
export BASH_START_PATH="$PATH"
fi
#
# You dont want BASH_START_PATH since it will leak your local machine's
# environment into ham. It is there as an escape hatch to include user only
# scripts used for work, only use when you know the consequences - your CI and
# prod machine generally won't have this.
#
# if [ -z "$BASH_START_PATH" ]; then
# export BASH_START_PATH="$PATH"
# fi
if [ -z "$EDITOR" ]; then
export EDITOR=ham-editor
Expand All @@ -26,5 +30,4 @@ fi
. "$HAM_HOME/bin/ham-bash-setenv.sh"
# Setup the tools that we want by default, just repos/git.
. hat repos
HAM_DIE_SHOULD_RETURN=$SCRIPT_SOURCED errcheck $? ham_env "Can't import toolsets." || return 1
toolset_import_list repos || return 1
27 changes: 16 additions & 11 deletions bin/ham-bash-lib.sh
Original file line number Diff line number Diff line change
Expand Up @@ -277,24 +277,29 @@ dl_file() {
}

toolset_import() {
export PATH=$PATH
. ham-toolset-import.sh $1
if [ $? != 0 ]; then
return 1
ALREADY_IMPORTED=`ni-hget HAM_IMPORTS_TOOLSETS $1`
if [[ "$ALREADY_IMPORTED" = "1" ]]; then
echo "W/Already imported '$1', skipped."
else
. ham-toolset-do-import.sh $1
fi
}

toolset_import_once() {
ALREADY_IMPORTED=`ni-hget HAM_IMPORTS_TOOLSETS $1`
if [[ $ALREADY_IMPORTED = "1" ]]; then
if [ "$2" != "silent" ]; then
echo "I/Already imported '$1'."
fi
else
. ham-toolset-import.sh $1
if [[ $ALREADY_IMPORTED != "1" ]]; then
. ham-toolset-do-import.sh $1
fi
}

toolset_import_force() {
. ham-toolset-do-import.sh force $1
}

toolset_import_strict() {
. ham-toolset-do-import.sh $1
}

toolset_unquarantine_dir() {
case $HAM_OS in
OSX*)
Expand Down Expand Up @@ -377,7 +382,7 @@ toolset_info() {
toolset_import_list() {
for ARG in $@
do
. ham-toolset-import.sh $ARG || return 1
. ham-toolset-do-import.sh force $ARG || return 1
export HAM_IMPORTED_TOOLSET=$ARG
done
}
Expand Down
2 changes: 1 addition & 1 deletion bin/ham-bash-setenv.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ if [ "${HAM_ENV_SETUP}" != 1 ]; then
case $HAM_OS in
NT*)
pathenv_remove_add "`unxpath $WINDIR`/System32" after
pathenv_add "$HAM_HOME/bin/nt"
pathenv_add "$HAM_HOME/bin/nt-x86"
;;
OSX)
pathenv_remove_add /opt/homebrew/bin after
Expand Down
46 changes: 46 additions & 0 deletions bin/ham-toolset-do-import.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
if [ "$1" == "force" ]; then
shift
if [ "$1" == "silent" ]; then
shift
else
ALREADY_IMPORTED=`ni-hget HAM_IMPORTS_TOOLSETS $1`
if [[ "$ALREADY_IMPORTED" = "1" ]]; then
echo "W/Toolset already imported '$1', force reimported."
fi
fi
else
ALREADY_IMPORTED=`ni-hget HAM_IMPORTS_TOOLSETS $1`
if [[ "$ALREADY_IMPORTED" = "1" ]]; then
echo "E/Toolset already imported '$1'."
return 1
fi
fi

FOUND_SETUP_SCRIPT=no
if [ "$FOUND_SETUP_SCRIPT" == "no" ]; then
export DIR="${HAM_HOME}/specs/toolsets/$1"
export SETUP_SCRIPT="$DIR/setup-toolset.sh"
if [ -f "$SETUP_SCRIPT" ]; then
FOUND_SETUP_SCRIPT="from GLOBAL."
fi
fi

if [ "$FOUND_SETUP_SCRIPT" == "no" ]; then
echo "E/Can't find the toolset '$1'"
return 1
fi

export PATH=$PATH
HAM_DIE_SHOULD_RETURN=yes source "$SETUP_SCRIPT"
if [ $? != 0 ]; then
echo "E/Toolset '$1' import failed !"
return 1
else
if [[ -z $HAM_IMPORTED_TOOLSETS ]]; then
export HAM_IMPORTED_TOOLSETS="$1"
else
export HAM_IMPORTED_TOOLSETS="$HAM_IMPORTED_TOOLSETS $1"
fi
ni-hput HAM_IMPORTS_TOOLSETS $1 1
echo -e "I/Imported toolset '$1' ${FOUND_SETUP_SCRIPT}"
fi
33 changes: 0 additions & 33 deletions bin/ham-toolset-import.sh

This file was deleted.

52 changes: 31 additions & 21 deletions sources/ham/build-lin-x64.sh
Original file line number Diff line number Diff line change
@@ -1,30 +1,40 @@
#!/bin/bash
. ham-bash-lib.sh
. ham-toolset default
#!/bin/bash -e
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
HAM_NO_VER_CHECK=1 . "$SCRIPT_DIR/../../_env.sh"
HAM_NO_VER_CHECK=1 . ham-toolset default
errcheck $? build-ham-lin-x64 "Can't setup toolset"

cd src

echo == Configure
if [[ ! -e ./Makefile ]]; then
chmod +x ./configure
./configure
if [[ -e "./Makefile" ]]; then
echo "I/Already configured"
else
echo "I/Configure"
(set -x ;
chmod +x ./configure ;
./configure)
fi

echo == Create output unix folder
mkdir -p bin.unix
echo "I/Create output unix folder"
(set -x ;
mkdir -p bin.unix)

echo == Building jambase.c...
gcc -o bin.unix/mkjambase mkjambase.c
./bin.unix/mkjambase jambase.c jambase
echo "I/Building jambase.c..."
(set -x ;
gcc -o bin.unix/mkjambase mkjambase.c ;
./bin.unix/mkjambase jambase.c Jambase)

echo == Building Ham
make clean
make
mkdir -p "$HAM_HOME/bin/lin-x64/"
cp -f ./bin.unix/ham.x64 "$HAM_HOME/bin/lin-x64/ham"
echo "I/Building Ham"
(set -x ;
make ;
mkdir -p "$HAM_HOME/bin/lin-x64" ;
cp -f "./bin.unix/ham.x64" "$HAM_HOME/bin/lin-x64/ham")

echo == Cleaning up temporary build files
rm -f ham0
rm -Rf bin.unix/
rm -Rf ham0.dSYM/
echo "I/Cleaning up temporary build files"
(set -x ;
make clean ;
rm -f ham0 ;
rm -Rf bin.unix/ ;
rm -Rf ham0.dSYM/)

echo "I/Done."
41 changes: 24 additions & 17 deletions sources/ham/build-nt-x86.sh
Original file line number Diff line number Diff line change
@@ -1,23 +1,30 @@
#!/bin/bash
. ham-bash-lib.sh
. ham-toolset msvc_19_x86
#!/bin/bash -e
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
HAM_NO_VER_CHECK=1 . "$SCRIPT_DIR/../../_env.sh"
HAM_NO_VER_CHECK=1 . ham-toolset msvc_19_x86
errcheck $? build-ham-nt-x86 "Can't setup msvc_19_x86 toolset"

cd src
echo == Requires the VC DevEnv
mkdir -p bin.ntx86
echo == Building jambase.c...
cl -nologo mkjambase.c

echo == Building Ham
rm -f ham0 # Make sure any unix ham0 is cleaned up
./mkjambase.exe jambase.c jambase
nmake -f builds/win32-visualc.mk
errcheck $? build-ham-nt-x86 "Ham build failed"
echo "I/Create output ntx86 folder"
(set -x ;
mkdir -p bin.ntx86)

cp bin.ntx86/ham.exe "${HAM_HOME}/bin/nt-x86/ham.exe"
errcheck $? build-ham-nt-x86 "Ham copy failed"
echo "I/Building jambase.c..."
(set -x ;
"${MSVCDIR_BIN}/cl.exe" -nologo mkjambase.c ;
./mkjambase.exe jambase.c Jambase)

echo == Cleaning up temporary build files
rm -f *.obj *.lib *.exe ham ham0 *.pdb
rm -Rf bin.ntx86/
echo "I/Building Ham"
(set -x ;
# Make sure any unix ham0 is cleaned up
rm -f ham0 ;
nmake -f builds/win32-visualc.mk ;
cp bin.ntx86/ham.exe "${HAM_HOME}/bin/nt-x86/ham.exe")

echo "I/Cleaning up temporary build files"
(set -x ;
rm -f *.obj *.lib *.exe ham ham0 *.pdb ;
rm -Rf bin.ntx86/)

echo "I/Done."
64 changes: 35 additions & 29 deletions sources/ham/build-osx.sh
Original file line number Diff line number Diff line change
@@ -1,42 +1,48 @@
#!/bin/bash -e
. ham-bash-lib.sh
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
HAM_NO_VER_CHECK=1 . "$SCRIPT_DIR/../../_env.sh"

BIN_LOA=${HAM_TARGET_BIN_LOA:-$HAM_BIN_LOA}
case $BIN_LOA in
osx-arm64)
. ham-toolset macos_arm64 || return 1
HAM_NO_VER_CHECK=1 . ham-toolset macos_arm64 || exit 1
;;
osx-x64)
. ham-toolset macos_x64 || return 1
HAM_NO_VER_CHECK=1 . ham-toolset macos_x64 || exit 1
;;
*)
echo "E/Toolset: Unsupported target '$BIN_LOA'."
return 1
exit 1
;;
esac
errcheck $? build-ham-osx "Can't setup toolset"

cd src

echo == Create output unix folder
mkdir -p bin.unix

echo == Building jambase.c...
gcc -o bin.unix/mkjambase mkjambase.c
./bin.unix/mkjambase jambase.c Jambase
errcheck $? build-ham-osx "Can't build jambase"

echo == Building Ham
make -f builds/Makefile.osx clean
make -f builds/Makefile.osx
errcheck $? build-ham-osx "Can't build ham"

mkdir -p "$HAM_HOME/bin/$BIN_LOA"
echo == Copying output to "$HAM_HOME/bin/$BIN_LOA/ham"
# Explicitly remove the file first otherwise macOS will quarantine the file
rm -f "$HAM_HOME/bin/$BIN_LOA/ham"
cp -f ./bin.unix/ham "$HAM_HOME/bin/$BIN_LOA/ham"
errcheck $? build-ham-osx "Can't output ham to final directory"

echo == Cleaning up temporary build files
rm -f ham0
rm -Rf bin.unix/
rm -Rf ham0.dSYM/
echo "I/Create output unix folder"
(set -x ;
mkdir -p bin.unix)

echo "I/Building jambase.c..."
(set -x ;
gcc -o bin.unix/mkjambase mkjambase.c ;
./bin.unix/mkjambase jambase.c Jambase)

echo "I/Building Ham"
(set -x ;
make -f builds/Makefile.osx clean ;
make -f builds/Makefile.osx)

echo "I/Copying output to '$HAM_HOME/bin/$BIN_LOA/ham'"
(set -x ;
mkdir -p "$HAM_HOME/bin/$BIN_LOA" ;
# Explicitly remove the file first otherwise macOS will quarantine the file
rm -f "$HAM_HOME/bin/$BIN_LOA/ham" ;
cp -f ./bin.unix/ham "$HAM_HOME/bin/$BIN_LOA/ham")

echo "I/Cleaning up temporary build files"
(set -x ;
rm -f ham0 ;
rm -Rf bin.unix/ ;
rm -Rf ham0.dSYM/)

echo "I/Done."
3 changes: 1 addition & 2 deletions specs/toolsets/ant/setup-toolset.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#!/bin/bash
. ham-toolset-import.sh java_jdk
if [ $? != 0 ]; then return 1; fi
toolset_import_once java_jdk || return 1

# toolset
export HAM_TOOLSET=ANT
Expand Down
4 changes: 2 additions & 2 deletions specs/toolsets/aws/setup-toolset.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/bash
. ham-toolset-import.sh repos
. ham-toolset-import.sh python_3
toolset_import_once repos || return 1
toolset_import_once python_3 || return 1

# toolset
export HAM_TOOLSET=AWS
Expand Down
Loading

0 comments on commit 3d62d56

Please sign in to comment.