ObjFW  Running on Omega2

# This script builds libobjfw-rt.so.0.0.0 and libobjfw-rt.so.0 for ObjFW
# Tested with Ubuntu 20.04, ObjFW 0.92, and Omega2 0.3.3
# Original copy here: https://gitlab.com/-/snippets/1682155

# First, setup the build system (based on directions here: https://docs.onion.io/omega2-docs/cross-compiling.html)

# Install requirements
sudo apt-get install git wget subversion build-essential libncurses5-dev zlib1g-dev gawk flex quilt git-core unzip libssl-dev python-dev python-pip libxml-parser-perl automake autotools-dev

# Download and prepare the build system 
git clone https://github.com/OnionIoT/source.git OnionIoT
sh scripts/onion-feed-setup.sh
python scripts/onion-setup-build.py
sh scripts/onion-minimal-build.sh

# Compile GCC with Objective-C language support
vim OnionIoT/toolchain/gcc/common.mk # add objc after c++, to TARGET_LANGUAGES

# Build the build system - the -j8 makes it go faster, select a number based on your cores
cd OnionIoT
make <-j8>
cd ..

# Set up crosscompiling
export BASE_DIR=$(pwd)
export STAGING_DIR=$BASE_DIR/OnionIoT/staging_dir
export TOOLCHAIN_DIR=$STAGING_DIR/toolchain-mipsel_24kc_gcc-7.3.0_musl
export LDCFLAGS=$TOOLCHAIN_DIR/usr/lib 
export LD_LIBRARY_PATH=$TOOLCHAIN_DIR/usr/lib 
export PATH=$TOOLCHAIN_DIR/bin:$PATH

# Download objfw
git clone https://github.com/ObjFW/ObjFW.git
cd ObjFW

# Build configure
./autogen.sh

# Configure objfw
# Note the gcc version may need changed
 ./configure --host=mipsel-openwrt-linux --prefix=$STAGING_DIR OBJC=$TOOLCHAIN_DIR/bin/mipsel-openwrt-linux-gcc

# Build objfw
make

# *** Manually copy $STAGING_DIR/lib/libobjfw-rt.so.0.0.0 to /usr/local/lib on Omega and link as libobjfw-rt.so.0 
# *** Manually copy $STAGING_DIR/lib/libobjfw.so.8.1.0 to /usr/local/lib on Omega and link as libobjfw.so.8 

# Build a test.m file
export PATH=$STAGING_DIR/bin:$PATH
mipsel-openwrt-linux-objfw-compile test.m -o test

# *** Manually copy test file and run it!