Cleaned up build script

This commit is contained in:
Devine Lu Linvega 2023-04-10 10:16:17 -07:00
parent 416f37c71a
commit 02f2769153
2 changed files with 31 additions and 28 deletions

View File

@ -2,8 +2,9 @@
RELEASE_FLAGS="-Os -DNDEBUG -g0 -s" RELEASE_FLAGS="-Os -DNDEBUG -g0 -s"
DEBUG_FLAGS="-std=c89 -D_POSIX_C_SOURCE=199309L -DDEBUG -Wall -Wno-unknown-pragmas -Wpedantic -Wshadow -Wextra -Werror=implicit-int -Werror=incompatible-pointer-types -Werror=int-conversion -Wvla -g -Og -fsanitize=address -fsanitize=undefined" DEBUG_FLAGS="-std=c89 -D_POSIX_C_SOURCE=199309L -DDEBUG -Wall -Wno-unknown-pragmas -Wpedantic -Wshadow -Wextra -Werror=implicit-int -Werror=incompatible-pointer-types -Werror=int-conversion -Wvla -g -Og -fsanitize=address -fsanitize=undefined"
EMU_INC="src/uxn.c src/devices/system.c src/devices/console.c src/devices/screen.c src/devices/controller.c src/devices/mouse.c src/devices/file.c src/devices/datetime.c src/uxn11.c -o bin/uxn11 -lX11" CORE_DEVICES="src/uxn.c src/devices/system.c src/devices/console.c src/devices/file.c src/devices/datetime.c"
CLI_INC="src/uxn.c src/devices/system.c src/devices/console.c src/devices/file.c src/devices/datetime.c src/uxncli.c -o bin/uxncli" EMU_INC="${CORE_DEVICES} src/devices/screen.c src/devices/controller.c src/devices/mouse.c src/uxn11.c -o bin/uxn11 -lX11"
CLI_INC="${CORE_DEVICES} src/uxncli.c -o bin/uxncli"
# find X11 libs on various systems # find X11 libs on various systems
if [ -e /usr/X11R6 ]; then if [ -e /usr/X11R6 ]; then
@ -12,31 +13,20 @@ if [ -e /usr/X11R6 ]; then
DEBUG_FLAGS="-L/usr/X11R6/lib/ -I/usr/X11R6/include/ $DEBUG_FLAGS" DEBUG_FLAGS="-L/usr/X11R6/lib/ -I/usr/X11R6/include/ $DEBUG_FLAGS"
fi fi
if [ "${1}" = '--format' ]; if [ "${1}" = '--format' ];
then then
echo "Formatting.."
clang-format -i src/uxn11.c clang-format -i src/uxn11.c
clang-format -i src/uxnasm.c clang-format -i src/uxnasm.c
clang-format -i src/uxncli.c clang-format -i src/uxncli.c
clang-format -i src/devices/* clang-format -i src/devices/*
fi fi
echo "Cleaning.."
rm -f bin/* rm -f bin/*
mkdir -p bin mkdir -p bin
echo "Building.." cc ${RELEASE_FLAGS} src/uxnasm.c -o bin/uxnasm
cc -DNDEBUG -Os -g0 -s src/uxnasm.c -o bin/uxnasm
if [ "${1}" = '--install' ]; if [ "${1}" = '--release' ];
then
echo "Installing.."
gcc ${C_FLAGS} ${LD_FLAGS} ${RELEASE_FLAGS} ${EMU_INC}
gcc ${C_FLAGS} ${LD_FLAGS} ${RELEASE_FLAGS} ${CLI_INC}
cp bin/uxnasm ~/bin
cp bin/uxncli ~/bin
cp bin/uxn11 ~/bin
elif [ "${1}" = '--release' ];
then then
gcc ${C_FLAGS} ${LD_FLAGS} ${RELEASE_FLAGS} ${EMU_INC} gcc ${C_FLAGS} ${LD_FLAGS} ${RELEASE_FLAGS} ${EMU_INC}
gcc ${C_FLAGS} ${LD_FLAGS} ${RELEASE_FLAGS} ${CLI_INC} gcc ${C_FLAGS} ${LD_FLAGS} ${RELEASE_FLAGS} ${CLI_INC}
@ -45,10 +35,6 @@ else
gcc ${C_FLAGS} ${LD_FLAGS} ${DEBUG_FLAGS} ${CLI_INC} gcc ${C_FLAGS} ${LD_FLAGS} ${DEBUG_FLAGS} ${CLI_INC}
fi fi
echo "Assembling.."
bin/uxnasm etc/polycat.tal bin/polycat.rom bin/uxnasm etc/polycat.tal bin/polycat.rom
echo "Running.."
bin/uxn11 bin/polycat.rom bin/uxn11 bin/polycat.rom
echo "Done."

View File

@ -39,7 +39,7 @@ typedef struct {
Uint16 llen, mlen, rlen; Uint16 llen, mlen, rlen;
Label labels[0x400]; Label labels[0x400];
Macro macros[0x100]; Macro macros[0x100];
Reference refs[0x400]; Reference refs[0x800];
char scope[0x40]; char scope[0x40];
} Program; } Program;
@ -179,7 +179,7 @@ makereference(char *scope, char *label, char rune, Uint16 addr)
{ {
char subw[0x40], parent[0x40]; char subw[0x40], parent[0x40];
Reference *r; Reference *r;
if(p.rlen == 0x1000) if(p.rlen >= 0x800)
return error("References limit exceeded", label); return error("References limit exceeded", label);
r = &p.refs[p.rlen++]; r = &p.refs[p.rlen++];
if(label[0] == '&') { if(label[0] == '&') {
@ -253,6 +253,7 @@ parse(char *w, FILE *f)
{ {
int i; int i;
char word[0x40], subw[0x40], c; char word[0x40], subw[0x40], c;
Label *l;
Macro *m; Macro *m;
if(slen(w) >= 63) if(slen(w) >= 63)
return error("Invalid token", w); return error("Invalid token", w);
@ -278,14 +279,30 @@ parse(char *w, FILE *f)
return error("Invalid macro", w); return error("Invalid macro", w);
break; break;
case '|': /* pad-absolute */ case '|': /* pad-absolute */
if(!sihx(w + 1)) if(sihx(w + 1))
return error("Invalid padding", w); p.ptr = shex(w + 1);
p.ptr = shex(w + 1); else if(w[1] == '&') {
if(!sublabel(subw, p.scope, w + 2) || !(l = findlabel(subw)))
return error("Invalid sublabel", w);
p.ptr = l->addr;
} else {
if(!(l = findlabel(w + 1)))
return error("Invalid label", w);
p.ptr = l->addr;
}
break; break;
case '$': /* pad-relative */ case '$': /* pad-relative */
if(!sihx(w + 1)) if(sihx(w + 1))
return error("Invalid padding", w); p.ptr += shex(w + 1);
p.ptr += shex(w + 1); else if(w[1] == '&') {
if(!sublabel(subw, p.scope, w + 2) || !(l = findlabel(subw)))
return error("Invalid sublabel", w);
p.ptr += l->addr;
} else {
if(!(l = findlabel(w + 1)))
return error("Invalid label", w);
p.ptr += l->addr;
}
break; break;
case '@': /* label */ case '@': /* label */
if(!makelabel(w + 1)) if(!makelabel(w + 1))