uxn/build.sh

91 lines
2.5 KiB
Bash
Raw Normal View History

2021-08-18 19:23:15 -04:00
#!/bin/sh -e
2021-01-29 14:17:59 -05:00
2021-03-22 22:04:31 -04:00
echo "Cleaning.."
2021-05-11 14:42:12 -04:00
rm -f ./bin/uxnasm
2021-05-11 23:30:03 -04:00
rm -f ./bin/uxnemu
rm -f ./bin/uxncli
2021-11-08 12:19:45 -05:00
rm -f ./bin/boot.rom
2021-11-08 10:51:09 -05:00
rm -f ./bin/asma.rom
2021-01-29 14:17:59 -05:00
# When clang-format is present
2021-08-27 14:00:34 -04:00
if [ "${1}" = '--format' ];
then
echo "Formatting.."
clang-format -i src/uxn.h
clang-format -i src/uxn.c
clang-format -i src/devices/system.c
2021-12-28 16:37:26 -05:00
clang-format -i src/devices/screen.h
clang-format -i src/devices/screen.c
2021-12-28 16:47:35 -05:00
clang-format -i src/devices/audio.h
clang-format -i src/devices/audio.c
clang-format -i src/devices/file.h
clang-format -i src/devices/file.c
2021-12-27 00:02:24 -05:00
clang-format -i src/devices/mouse.h
clang-format -i src/devices/mouse.c
clang-format -i src/devices/controller.h
clang-format -i src/devices/controller.c
clang-format -i src/uxnasm.c
clang-format -i src/uxnemu.c
clang-format -i src/uxncli.c
fi
2021-03-22 22:04:31 -04:00
mkdir -p bin
CC="${CC:-cc}"
2021-11-17 08:12:02 -05:00
CFLAGS="${CFLAGS:--std=c89 -Wall -Wno-unknown-pragmas}"
2021-10-10 15:07:40 -04:00
case "$(uname -s 2>/dev/null)" in
MSYS_NT*|MINGW*) # MSYS2 on Windows
if [ "${1}" = '--console' ];
then
UXNEMU_LDFLAGS="-static $(sdl2-config --cflags --static-libs | sed -e 's/ -mwindows//g')"
else
UXNEMU_LDFLAGS="-static $(sdl2-config --cflags --static-libs)"
fi
2021-10-10 15:07:40 -04:00
;;
Darwin) # macOS
CFLAGS="${CFLAGS} -Wno-typedef-redefinition"
UXNEMU_LDFLAGS="$(brew --prefix)/lib/libSDL2.a $(sdl2-config --cflags --static-libs | sed -e 's/-lSDL2 //')"
2021-10-10 15:07:40 -04:00
;;
Linux|*)
UXNEMU_LDFLAGS="-L/usr/local/lib $(sdl2-config --cflags --libs)"
2021-10-10 15:07:40 -04:00
;;
esac
2021-03-22 22:04:31 -04:00
if [ "${1}" = '--debug' ];
then
echo "[debug]"
2021-06-25 18:04:43 -04:00
CFLAGS="${CFLAGS} -DDEBUG -Wpedantic -Wshadow -Wextra -Werror=implicit-int -Werror=incompatible-pointer-types -Werror=int-conversion -Wvla -g -Og -fsanitize=address -fsanitize=undefined"
2021-06-25 18:30:40 -04:00
CORE='src/uxn.c'
2021-03-22 22:04:31 -04:00
else
2021-06-25 18:04:43 -04:00
CFLAGS="${CFLAGS} -DNDEBUG -Os -g0 -s"
CORE='src/uxn.c'
2021-05-11 23:30:03 -04:00
fi
2021-06-27 13:56:21 -04:00
echo "Building.."
${CC} ${CFLAGS} src/uxnasm.c -o bin/uxnasm
${CC} ${CFLAGS} ${CORE} src/devices/system.c src/devices/file.c src/devices/mouse.c src/devices/controller.c src/devices/screen.c src/devices/audio.c src/uxnemu.c ${UXNEMU_LDFLAGS} -o bin/uxnemu
${CC} ${CFLAGS} ${CORE} src/devices/system.c src/devices/file.c src/uxncli.c -o bin/uxncli
2021-05-11 23:30:03 -04:00
2021-08-19 01:08:09 -04:00
if [ -d "$HOME/bin" ]
2021-05-11 23:30:03 -04:00
then
echo "Installing in $HOME/bin"
2021-08-19 01:08:09 -04:00
cp bin/uxnemu bin/uxnasm bin/uxncli $HOME/bin/
2021-03-22 22:04:31 -04:00
fi
2021-02-09 13:06:55 -05:00
2021-11-08 10:51:09 -05:00
echo "Assembling(boot).."
2021-11-08 12:19:45 -05:00
./bin/uxnasm projects/software/boot.tal bin/boot.rom
2021-10-07 21:28:06 -04:00
echo "Assembling(asma).."
./bin/uxnasm projects/software/asma.tal bin/asma.rom
if [ "${1}" = '--no-run' ]; then exit; fi
2021-10-07 21:28:06 -04:00
echo "Assembling(piano).."
2021-10-13 17:58:17 -04:00
bin/uxncli bin/asma.rom projects/examples/demos/piano.tal bin/piano.rom 2> bin/piano.log
2021-01-29 14:17:59 -05:00
2021-03-22 22:04:31 -04:00
echo "Running.."
2021-11-08 12:19:45 -05:00
cd bin
./uxnemu piano.rom
2021-03-22 19:51:12 -04:00
2021-05-18 09:31:05 -04:00
echo "Done."
2021-11-08 12:19:45 -05:00
cd ..