DEADSOFTWARE

cpmake: add options for bootstrapping
[cpc.git] / make-bootstrap.sh
index 3c7f446a84f1303afaf0a7430e83a0e32ce10ecc..c3a36e66e3e699c3e28dc0cdec84ab8d4e5f6a3d 100755 (executable)
@@ -1,19 +1,40 @@
-#! /bin/sh
+#! /bin/bash
 
 set -e
 
+abspath() {
+  [[ "$1" == /* ]] && echo "$1" || echo "$(pwd)/$1"
+}
+
 ###^^^^^^^^^^^^^^^^^^###
 ### Global variables ###
 ###__________________###
 
 _exec="make-bootstrap.sh"
-_this="$(dirname "$(readlink -f "$0")")"
-_version="v0.2"
+_this="$(dirname "$(abspath "$0")")"
+_version="v0.3"
+_sign=false
+
+export CPCFLAGS="-no-use-time $CPCFLAGS"
+export CPLFLAGS="$CPLFLAGS"
 
 ###^^^^^^^^^^^###
 ### Functions ###
 ###___________###
 
+usage() {
+  echo "Usage: make-bootstrap.sh [options]"
+  echo "Options:"
+  echo "    -v version        Set build version"
+  echo "    -S                Sign build"
+  echo "Environment variables:"
+  echo "    CC                C compiler binary"
+  echo "    CFLAGS            C compiler options"
+  echo "    CPCFLAGS          CPC compiler options"
+  echo "    CPLFLAGS          CPL linker options"
+  exit 2
+}
+
 make_bootstrap() {
   local _cpu="$1"
   local _target="$2"
@@ -24,6 +45,28 @@ make_bootstrap() {
     -type d -name 'CodeC' -prune -o -exec rm -rf {} +
 }
 
+error() {
+  echo "$_exec:" "$@"
+  exit 1
+}
+
+###^^^^^^^^^^^^^^^###
+### Parse options ###
+###_______________###
+
+while getopts v:Sh _name
+do
+  case "$_name" in
+    v) _version="$OPTARG" ;;
+    S) _sign=true ;;
+    h|?) usage ;;
+  esac
+done
+
+if [ -z "$_version" ] || echo "$_version" | grep " " > /dev/null; then
+  error "version not specified or contain spaces"
+fi
+
 ###^^^^^^^^^^^^^^^^^^^^###
 ### Prebuild C sources ###
 ###____________________###
@@ -31,6 +74,15 @@ make_bootstrap() {
 rm -rf "$_this/bootstrap"
 mkdir -p "$_this/bootstrap"
 make_bootstrap 486 cpfront linux
+#make_bootstrap 486 cpfront cygwin
+#make_bootstrap arm cpfront linux
+#make_bootstrap powerpc cpfront osx
+
+###^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^###
+### Hack: remove temp files from v0.1 ###
+###___________________________________###
+
+find "$_this/bootstrap" -type f -name '.new*' -delete
 
 ###^^^^^^^^^^^^^^^^^^^^^^###
 ### Package dist sources ###
@@ -38,7 +90,7 @@ make_bootstrap 486 cpfront linux
 
 rm -rf "$_this/cpc-$_version"
 mkdir -p "$_this/cpc-$_version"
-cp -rt "$_this/cpc-$_version" -- \
+cp -r \
   "$_this/CHANGELOG" \
   "$_this/LICENSE" \
   "$_this/README" \
@@ -49,5 +101,14 @@ cp -rt "$_this/cpc-$_version" -- \
   "$_this/make-bootstrap.sh" \
   "$_this/bootstrap" \
   "$_this/src" \
-  "$_this/C"
+  "$_this/C" \
+  "$_this/cpc-$_version"
 tar czf "cpc-$_version.src.tar.gz" "cpc-$_version"
+
+###^^^^^^^^^^^^^^^^###
+### Make signature ###
+###________________###
+
+if $_sign; then
+  gpg --yes --armor --detach-sig "cpc-$_version.src.tar.gz"
+fi