diff options
| author | Mustafa Quraish <[email protected]> | 2022-01-30 02:18:57 -0500 |
|---|---|---|
| committer | Mustafa Quraish <[email protected]> | 2022-01-30 18:04:13 -0500 |
| commit | fe1febfc4b68c0494790d915c6247d98ed2205e9 (patch) | |
| tree | 3aa68d57f7a9df9963aadcda351fb41a1b08162e /Makefile | |
| parent | Rename `cup` directory to `src` (diff) | |
| download | cup-fe1febfc4b68c0494790d915c6247d98ed2205e9.tar.xz cup-fe1febfc4b68c0494790d915c6247d98ed2205e9.zip | |
Update build system to use Makefile
`make` to compile the compiler
`make XXX.out` to assemble/link `XXX.nasm` into an executable
`make test` to run all tests
`make tests/XXX` to run `tests/XXX.sh` test file
`./run.sh <cupcc args>` to build, compile, run and show exit code
Diffstat (limited to 'Makefile')
| -rw-r--r-- | Makefile | 56 |
1 files changed, 56 insertions, 0 deletions
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]" + |