diff options
| -rw-r--r-- | .gitignore | 4 | ||||
| -rw-r--r-- | Makefile | 56 | ||||
| -rwxr-xr-x | assemble.sh | 25 | ||||
| -rwxr-xr-x | compile.sh | 9 | ||||
| -rwxr-xr-x | run.sh | 17 | ||||
| -rwxr-xr-x | test.sh | 12 | ||||
| -rw-r--r-- | tests/common.sh | 25 |
7 files changed, 75 insertions, 73 deletions
@@ -6,4 +6,6 @@ cupcc *.nasm *.o -*.out
\ No newline at end of file +*.out + +build
\ No newline at end of file diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..97c1baf --- /dev/null +++ b/Makefile @@ -0,0 +1,56 @@ +# No separable compilation here, the program is too small to bother + +CC = gcc +CFLAGS = -Wall -Wextra -Werror -ggdb3 +SRCS = $(wildcard src/*.c) + +.PHONY: compile test clean + + +build/cupcc: build FORCE + $(CC) $(CFLAGS) -o $@ $(SRCS) + +compile: build/cupcc + +FORCE: + +UNAME_S := $(shell uname -s) +ifeq ($(UNAME_S),Linux) + +%.o: %.nasm FORCE + nasm -felf64 $< -o $@ + +%.out: %.o FORCE + ld -o $@ $< + +endif +ifeq ($(UNAME_S),Darwin) + +%.o: %.nasm FORCE + nasm -fmacho64 $< -o $@ + +%.out: %.o FORCE + ld $< -o $@ -lSystem + +endif + +build: + @mkdir -p build + +clean: + rm -rf build + +test: compile + @for f in $(shell ls tests | grep -v "common"); \ + do echo "Running $${f}"; \ + ./tests/$${f}; \ + done + +tests/%.sh: compile + @echo "Running $@" + @$@ + +tests/%: compile + @echo "Running [email protected]" + diff --git a/assemble.sh b/assemble.sh deleted file mode 100755 index ed9b46e..0000000 --- a/assemble.sh +++ /dev/null @@ -1,25 +0,0 @@ -#!/bin/bash - -# NOTE: Only for macOS (intel) - -if [ -z "$1" ] -then - echo "Usage: $0 <path to nasm file>" - exit 1 -fi - - -case "$(uname -s)" in - Darwin) - set -xe - nasm -f macho64 -o $1.o $1 - ld -lSystem $1.o - set +xe - ;; - Linux) - set -xe - nasm -f elf64 -o $1.o $1 - ld $1.o - set +xe - ;; -esac
\ No newline at end of file diff --git a/compile.sh b/compile.sh deleted file mode 100755 index fa24474..0000000 --- a/compile.sh +++ /dev/null @@ -1,9 +0,0 @@ -#!/bin/bash - -CC=gcc -CFLAGS="-Wall -Wextra -Werror -ggdb3" -SRCS=src/*.c - -set -xe - -$CC $CFLAGS $SRCS -o cupcc @@ -1,18 +1,25 @@ #!/bin/bash +# This script does the following: +# 1. Builds the project +# 2. Compiles selected file +# 3. Assembles executable from compiled asm +# 4. Runs the executable +# 5. Echoes the output of the executable + if [ -z "$1" ] then - echo "Usage: $0 <path to .cup file>" + echo "Usage: $0 <arguments to cupcc>" exit 1 fi set -xe -./compile.sh -./cupcc "$@" -./assemble.sh output.nasm +make +build/cupcc "$@" +make build/output.out set +e -./a.out +build/output.out echo "Exit status: $?"
\ No newline at end of file diff --git a/test.sh b/test.sh deleted file mode 100755 index 091a2bb..0000000 --- a/test.sh +++ /dev/null @@ -1,12 +0,0 @@ -#!/bin/bash - -set -e -./compile.sh - -for i in `ls tests/*.sh | grep -v common.sh` -do - echo "Running $i" - bash $i -done - -set +e
\ No newline at end of file diff --git a/tests/common.sh b/tests/common.sh index f863826..575443c 100644 --- a/tests/common.sh +++ b/tests/common.sh @@ -1,28 +1,11 @@ #!/bin/bash -function assemble() { - case "$(uname -s)" in - Darwin) - set -e - nasm -f macho64 -o output.nasm.o output.nasm - ld -lSystem output.nasm.o - set +e - ;; - Linux) - set -e - nasm -f elf64 -o output.nasm.o output.nasm - ld output.nasm.o - set +e - ;; - esac -} - function assert_exit_status() { - ./cupcc -c "$1" - assemble + build/cupcc -c "$1" -o build/test.nasm + make build/test.out -s set +e - ./a.out + build/test.out res=$? set -e if [ $res -ne $2 ] @@ -45,7 +28,7 @@ function assert_exit_status_stdin() { function assert_compile_failure_stdin() { code=$(</dev/stdin) set +e - ./cupcc -c "$code" >/dev/null 2>&1 + build/cupcc -c "$code" -o build/test.nasm >/dev/null 2>&1 res=$? set -e if [ $res -eq 0 ] |