86 lines
2.7 KiB
Bash
Executable file
86 lines
2.7 KiB
Bash
Executable file
#!/bin/bash
|
|
|
|
#
|
|
# Copyright (c) 2024 Scott Duensing, scott@kangaroopunch.com
|
|
#
|
|
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
# of this software and associated documentation files (the "Software"), to deal
|
|
# in the Software without restriction, including without limitation the rights
|
|
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
# copies of the Software, and to permit persons to whom the Software is
|
|
# furnished to do so, subject to the following conditions:
|
|
#
|
|
# The above copyright notice and this permission notice shall be included in
|
|
# all copies or substantial portions of the Software.
|
|
#
|
|
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
# SOFTWARE.
|
|
#
|
|
|
|
#
|
|
# This script is intended for use on Linux and MacOS.
|
|
#
|
|
|
|
|
|
SCRIPT_PATH="${BASH_SOURCE}"
|
|
while [ -L "${SCRIPT_PATH}" ]; do
|
|
SCRIPT_DIR="$(cd -P "$(dirname "${SCRIPT_PATH}")" >/dev/null 2>&1 && pwd)"
|
|
SCRIPT_PATH="$(readlink "${SCRIPT_PATH}")"
|
|
[[ ${SCRIPT_PATH} != /* ]] && SCRIPT_PATH="${SCRIPT_DIR}/${SCRIPT_PATH}"
|
|
done
|
|
SCRIPT_PATH="$(readlink -f "${SCRIPT_PATH}")"
|
|
SCRIPT_DIR="$(cd -P "$(dirname -- "${SCRIPT_PATH}")" >/dev/null 2>&1 && pwd)"
|
|
|
|
ROOT=${SCRIPT_DIR}
|
|
|
|
if [[ -z ${1} ]]; then
|
|
echo No project folder provided.
|
|
exit 1
|
|
fi
|
|
|
|
if ! compgen -G "${1}/src/*.c" > /dev/null; then
|
|
echo No src folder containing C files found.
|
|
exit 1
|
|
fi
|
|
|
|
PYTHON=$(which python)
|
|
if [[ $? == 1 ]]; then
|
|
PYTHON=$(which python3)
|
|
if [[ $? == 1 ]]; then
|
|
echo "Unable to find Python 3.x. Exiting."
|
|
exit 1
|
|
fi
|
|
fi
|
|
|
|
PROJECT="$(cd "$(dirname "$1")"; pwd)/$(basename "$1")"
|
|
SOURCE=${PROJECT}/src
|
|
BUILD=${PROJECT}/.builddir
|
|
NAME=$(basename ${PROJECT})
|
|
pushd "${PROJECT}" > /dev/null
|
|
if [[ -d .builddir ]]; then
|
|
rm -rf .builddir
|
|
fi
|
|
mkdir -p .builddir
|
|
cd .builddir
|
|
"${ROOT}/overlay" 5 "${BUILD}" "${SOURCE}"
|
|
if [[ -f "${PROJECT}/f256.ld" ]]; then
|
|
cp -f "${PROJECT}/f256.ld" f256.ld
|
|
fi
|
|
if [[ ! -f f256.ld ]]; then
|
|
cp -f "${ROOT}/llvm-mos/mos-platform/f256/lib/link.ld" f256.ld
|
|
fi
|
|
export PATH=${ROOT}/llvm-mos/bin:${PATH}
|
|
mos-f256-clang -T f256.ld -Wl,-Map=${NAME}.map -o ${NAME} -I"${ROOT}" -Os -Wall -lm *.c
|
|
if [[ $? == 0 ]]; then
|
|
mv ${NAME} ${NAME}.pgz
|
|
llvm-nm ${NAME}.elf > ${NAME}.sym
|
|
llvm-objdump --syms -d --print-imm-hex ${NAME}.elf > ${NAME}.lst
|
|
${PYTHON} ${ROOT}/pgz-thunk.py ${NAME}.pgz
|
|
mv ${NAME}.pgz ../.
|
|
fi
|
|
popd > /dev/null
|