aboutsummaryrefslogtreecommitdiff
path: root/Makefile
blob: 97c1baf6689c1fdb84e41c753f05c297d6b0975d (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
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 $@.sh"
	@$@.sh