Skip to content

Instantly share code, notes, and snippets.

@mulle-nat
Last active June 12, 2020 17:26
Show Gist options
  • Save mulle-nat/47d67be5572c25f7b07d404fd74000e5 to your computer and use it in GitHub Desktop.
Save mulle-nat/47d67be5572c25f7b07d404fd74000e5 to your computer and use it in GitHub Desktop.
tcc -run <filename> for Objective-C (mulle-objc / Apple)
#! /usr/bin/env bash
#
# Coded by Nat! in 2020
# Public Domain
#
tmpdir=
mulle=
finish()
{
if [ ! -z "${tmpdir}" ]
then
chmod -R ug+wX "${tmpdir}" &&
rm -rf "${tmpdir}"
fi
}
trap finish EXIT
while [ $# -ne 0 ]
do
case "$1" in
--run)
shift
continue
;;
--mulle)
mulle=YES
shift
continue
;;
esac
break
done
if [ $# -eq 0 ]
then
echo "runobjc [--run] [--mulle] <filename> ..." >&2
exit 1
fi
filename="$1"
shift
tmpdir="`mktemp -d`" || exit 1
if [ -z "${mulle}" ]
then
cp "${filename}" "${tmpdir}/main.m" || exit 1
(
cd "${tmpdir}" &&
cc -o a.out main.m -framework Foundation
) || exit 1
executable="${tmpdir}/a.out"
else
mulle-sde -s init -d "${tmpdir}" -m foundation/objc-developer executable &&
cp "${filename}" "${tmpdir}/src/main.m"
(
cd "${tmpdir}" &&
mulle-sde -s craft --release
) || exit 1
projectname="`basename -- "${tmpdir}"`"
executable="${tmpdir}/kitchen/Release/${projectname}"
fi
"${executable}" "$@"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment