Skip to content

Instantly share code, notes, and snippets.

@herrhotzenplotz
Created January 21, 2023 16:03
Show Gist options
  • Save herrhotzenplotz/3c1cf10ecd7397c993fa4b04de83b5b4 to your computer and use it in GitHub Desktop.
Save herrhotzenplotz/3c1cf10ecd7397c993fa4b04de83b5b4 to your computer and use it in GitHub Desktop.
Patch to make ndless sort of build on FreeBSD (gdb is still broken however)
diff --git a/ndless-sdk/bin/arm-none-eabi-ld.gold b/ndless-sdk/bin/arm-none-eabi-ld.gold
index ae0dd67..c8cb7f4 100755
--- a/ndless-sdk/bin/arm-none-eabi-ld.gold
+++ b/ndless-sdk/bin/arm-none-eabi-ld.gold
@@ -1,4 +1,4 @@
-#!/bin/bash
+#!/usr/bin/env bash
# New ld which produces ELF binaries for use with genzehn
# It is invoked instead of "arm-none-eabi-ld" (or the default linker of the ARM toolchain) to replace the default crt* with ndless compatible ones and also adds some more libs
diff --git a/ndless-sdk/bin/make-prg b/ndless-sdk/bin/make-prg
index 5ed68a6..485b806 100755
--- a/ndless-sdk/bin/make-prg
+++ b/ndless-sdk/bin/make-prg
@@ -1,4 +1,4 @@
-#!/bin/bash
+#!/bin/sh
# Adds the resources-loader at the top of the given binary for backwards-compatibility
# Validate the Zehn file
diff --git a/ndless-sdk/bin/nspire-tools b/ndless-sdk/bin/nspire-tools
index ef97f1d..61baaf5 100755
--- a/ndless-sdk/bin/nspire-tools
+++ b/ndless-sdk/bin/nspire-tools
@@ -1,6 +1,6 @@
-#!/bin/bash
+#!/bin/sh
-function usage() {
+usage() {
echo "Usage: nspire-tools <command> <args>"
echo " new <program>: Generate a standard Makefile for <program>.tns"
echo " main: Create an empty main.c"
@@ -66,13 +66,13 @@ case "$cmd" in
echo "$SDKROOT/"
;;
_toolchainpath)
- if [[ -z $_NDLESS_TOOLCHAIN_PATH ]]; then
+ if [ -z $_NDLESS_TOOLCHAIN_PATH ]; then
_NDLESS_TOOLCHAIN_PATH="$SDKROOT/toolchain/install/bin"
fi
echo "$_NDLESS_TOOLCHAIN_PATH"
;;
_zehn_loader_path)
- if [[ -z $_NDLESS_ZEHN_PATH ]]; then
+ if [ -z $_NDLESS_ZEHN_PATH ]; then
MAKEFLAGS='' make -C "${SDKROOT}/tools/zehn_loader" -s all
_NDLESS_ZEHN_PATH="$SDKROOT/tools/zehn_loader/"
fi
diff --git a/ndless-sdk/toolchain/build_toolchain.sh b/ndless-sdk/toolchain/build_toolchain.sh
index 91d12ca..09fc4b4 100755
--- a/ndless-sdk/toolchain/build_toolchain.sh
+++ b/ndless-sdk/toolchain/build_toolchain.sh
@@ -17,7 +17,7 @@ set -eu
TARGET=arm-none-eabi
PREFIX="${PWD}/install" # or the directory where the toolchain should be installed in
PARALLEL="${PARALLEL--j4}" # or "-j<number of build jobs>"
-PYTHON="${PYTHON-$(which python3 2>/dev/null)}" # or the full path to the python interpreter
+PYTHON="${PYTHON-$(which python3.9 2>/dev/null)}" # or the full path to the python interpreter
BINUTILS=binutils-2.38 # https://www.gnu.org/software/binutils/
GCC=gcc-11.2.0 # https://gcc.gnu.org/
@@ -65,7 +65,7 @@ mkdir -p build download
downloadAndExtract() {
url="$1"
target="download/$(basename "${url}")"
- if ! wget -c "$url" -O "${target}"; then
+ if ! fetch -o "${target}" "$url"; then
rm -f "${target}"
return 1
fi
@@ -85,8 +85,8 @@ if [ "$(cat .built_binutils 2>/dev/null)" != "${BINUTILS}" ]; then
rm -rf build; mkdir build
cd build
../download/${BINUTILS}/configure ${OPTIONS_BINUTILS}
- make $PARALLEL all
- make install
+ gmake $PARALLEL all
+ gmake install
cd ..
echo -n "${BINUTILS}" > .built_binutils
fi
@@ -112,8 +112,8 @@ if [ "$(cat .built_gcc_step1 2>/dev/null)" != "${GCC}" ]; then
rm -rf build; mkdir build
cd build
../download/${GCC}/configure ${OPTIONS_GCC} --with-headers=../download/${NEWLIB}/newlib/libc/include
- make $PARALLEL all-gcc
- make install-gcc
+ gmake $PARALLEL all-gcc
+ gmake install-gcc
cd ..
# Some of the headers copied from newlib are autogenerated, but newlib didn't
# build yet so it's just dummy content.
@@ -134,8 +134,8 @@ if [ "$(cat .built_newlib 2>/dev/null)" != "${NEWLIB}" ]; then
rm -rf build; mkdir build
cd build
../download/${NEWLIB}/configure ${OPTIONS_NEWLIB}
- make $PARALLEL
- make install
+ gmake $PARALLEL
+ gmake install
cd ..
echo -n "${NEWLIB}" > .built_newlib
fi
@@ -152,8 +152,8 @@ if [ "$(cat .built_gcc_step2 2>/dev/null)" != "${GCC}" ]; then
rm -rf build; mkdir build
cd build
../download/${GCC}/configure ${OPTIONS_GCC}
- make $PARALLEL
- make install
+ gmake $PARALLEL
+ gmake install
cd ..
echo -n "${GCC}" > .built_gcc_step2
fi
@@ -169,9 +169,9 @@ if [ "$(cat .built_gdb 2>/dev/null)" != "${GDB}" ]; then
echo "Building GDB..."
rm -rf build; mkdir build
cd build
- ../download/${GDB}/configure ${OPTIONS_GDB}
- make $PARALLEL
- make install
+ LDFLAGS='-fuse-ld=/usr/local/bin/ld.gold' ../download/${GDB}/configure ${OPTIONS_GDB}
+ gmake $PARALLEL
+ gmake install
cd ..
echo -n "${GDB}" > .built_gdb
fi
diff --git a/ndless-sdk/tools/genzehn/Makefile b/ndless-sdk/tools/genzehn/Makefile
index 91869cb..214f133 100644
--- a/ndless-sdk/tools/genzehn/Makefile
+++ b/ndless-sdk/tools/genzehn/Makefile
@@ -1,7 +1,7 @@
all: ../../bin/genzehn
../../bin/genzehn: genzehn.cpp
- g++ -Wall -Wextra -std=c++11 -I elfio-3.2 $^ -lboost_program_options -lz -o $@ || g++ -Wall -Wextra -std=c++11 -I elfio-3.2 $^ -lboost_program_options-mt -lz -o $@
+ c++ -Wall -Wextra -std=c++11 -I/usr/local/include -L/usr/local/lib -I elfio-3.2 $^ -lboost_program_options -lz -o $@ || g++ -Wall -Wextra -std=c++11 -I elfio-3.2 $^ -lboost_program_options-mt -lz -o $@
clean:
rm -f ../../bin/genzehn
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment