bootstrap-toolchain/builder

170 lines
4.5 KiB
Plaintext
Raw Normal View History

2023-03-24 16:29:26 +00:00
#! /bin/bash
# Toolchain builder for the Serene programming language
#
# Copyright (c) 2019-2023 Sameer Rahmani <lxsameer@gnu.org>
#
# 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, version 2.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# -----------------------------------------------------------------------------
# Commentary
# -----------------------------------------------------------------------------
# This is the builder script for the Serene project. It makes it easier to
# interact with the CMake build scripts.
#
# In order to define a subcommand all you need to do is to define a function
# with the following syntax:
#
# function subcommand-name() { ## DESCRIPTION
# .. subcommand body ..
# }
#
# Make sure to provid one line of DESCRIPTION for the subcommand and use two "#"
# characters to start the description following by a space. Otherwise, your
# subcommand won't be registered
#
set -e
command=$1
VERSION="0.9.0"
2023-04-12 19:13:04 +01:00
LLVM_VERSION="0e0db0a4d7fd606ee58595f997142f7f2476cbe6"
LLVM_MAJOR_VERSION="17"
CMAKE_VERSION="3.26.0"
NINJA_VERSION="1.11.1"
ZLIB_VERSION="1.2.13"
ZSTD_VERSION="1.5.4"
KERNEL_VERSION="6.0"
2023-04-12 19:13:04 +01:00
MUSL_VERSION="1.2.3"
TARGET=x86_64-pc-linux-musl
export LLVM_VERSION \
CMAKE_VERSION \
NINJA_VERSION \
ZLIB_VERSION \
ZSTD_VERSION \
KERNEL_VERSION \
LLVM_MAJOR_VERSION \
MUSL_VERSION \
TARGET
2023-04-12 19:13:04 +01:00
2023-03-24 16:29:26 +00:00
ME=$(cd "$(dirname "$0")/." >/dev/null 2>&1 ; pwd -P)
# shellcheck source=./scripts/utils.sh
source "$ME/scripts/utils.sh"
user="serene"
channel="stable"
2023-04-16 17:33:41 +01:00
function _conan() { ## A conan wrapper
2023-03-24 16:29:26 +00:00
PYTHONPATH="$ME:$PYTHONPATH" conan "$@"
}
function _create() {
_conan create --user "$user" --channel "$channel" \
--profile:host="../../profiles/stage$1" \
2023-03-25 15:28:15 +00:00
--profile:build="../../profiles/stage$1" \
2023-03-24 16:29:26 +00:00
. "${@:2}"
}
2023-03-24 20:11:50 +00:00
function _build() {
_push "packages/$1/"
_create "${@:2}"
_pop
}
2023-04-16 17:33:41 +01:00
function graph() { ## Generate the dependency graph
_push "packages/$1/"
_conan graph info \
--user "$user" --channel "$channel" -v \
--profile:host="../../profiles/stage$2" \
--profile:build="../../profiles/stage$2" \
conanfile.py \
"${@:3}"
_pop
}
2023-03-24 16:29:26 +00:00
function llvm-source() { ## Build the llvm source pkg
_push "packages/sources/llvm/"
_conan create --user "$user" --channel "$channel" \
--profile:host="../../../profiles/stage$1" \
--profile:build="../../../profiles/stage$1" \
. "${@:2}"
2023-03-24 16:29:26 +00:00
_pop
}
function cmake() { ## Build the cmake package
_push "packages/cmake/"
_create "$@"
_pop
}
function gcc() { ## Build the gcc package
_push "packages/gcc/"
_create "$@"
_pop
}
2023-03-24 20:11:50 +00:00
function ninja() { ## Build the gcc package
_build ninja "$@"
}
function zlib() { ## Build the zlib package
_build zlib "$@"
}
function zstd() { ## Build the zstd package
_build zstd "$@"
}
function clang-bootstrap() { ## Build the gcc package
_build clang-bootstrap "$@"
}
2023-03-24 16:29:26 +00:00
function help() { ## Print out this help message
echo "Commands:"
grep -E '^function [a-zA-Z0-9_-]+\(\) \{ ## .*$$' "$0" | \
sort | \
sed 's/^function \([a-zA-Z0-9_-]*\)() { ## \(.*\)/\1:\2/' | \
awk 'BEGIN {FS=":"}; {printf "\033[36m%-30s\033[0m %s\n", $1, $2}'
}
# -----------------------------------------------------------------------------
# Main logic
# -----------------------------------------------------------------------------
echo -e "\nSerene Builder Version $VERSION"
echo -e "\nCopyright (C) 2019-2023"
echo -e "Sameer Rahmani <lxsameer@gnu.org>"
echo -e "Serene comes with ABSOLUTELY NO WARRANTY;"
echo -e "This is free software, and you are welcome"
echo -e "to redistribute it under certain conditions;"
echo -e "for details take a look at the LICENSE file.\n"
2023-04-12 19:13:04 +01:00
if [[ -d "$ME/packages/$command" ]]; then
_build "$command" "${@:2}"
exit $?
fi
2023-03-24 16:29:26 +00:00
# Find the subcommand in the functions and run we find it.
for fn in $(fn-names); do
if [[ $fn == "$command" ]]; then
eval "$fn ${*:2}"
exit $?
fi
done
# If we couldn't find the command print out the help message
help