summary refs log tree commit diff
path: root/Makefile
blob: 090f5cbc67aeef4c32999ae3e075340fb85b55a7 (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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
.POSIX:
.SUFFIXES: .o .c

PREFIX = /usr/local
BINDIR = $(PREFIX)/bin

SRC      = main.c util.c parse.c cfg.c mem.c ssa.c alias.c load.c copy.c \
           fold.c live.c spill.c rega.c gas.c
AMD64SRC = amd64/targ.c amd64/sysv.c amd64/isel.c amd64/emit.c
ARM64SRC = arm64/targ.c arm64/abi.c arm64/isel.c arm64/emit.c
RV64SRC  = rv64/targ.c rv64/abi.c rv64/isel.c rv64/emit.c
SRCALL   = $(SRC) $(AMD64SRC) $(ARM64SRC) $(RV64SRC)

AMD64OBJ = $(AMD64SRC:.c=.o)
ARM64OBJ = $(ARM64SRC:.c=.o)
RV64OBJ  = $(RV64SRC:.c=.o)
OBJ      = $(SRC:.c=.o) $(AMD64OBJ) $(ARM64OBJ) $(RV64OBJ)

CFLAGS = $(CPPFLAGS) -Wall -Wextra -std=c99 -g -Wpedantic

qbe: $(OBJ)
	$(CC) $(LDFLAGS) $(OBJ) -o $@

.c.o:
	$(CC) $(CFLAGS) -c $< -o $@

$(OBJ): all.h ops.h
$(AMD64OBJ): amd64/all.h
$(ARM64OBJ): arm64/all.h
$(RV64OBJ): rv64/all.h
main.o: config.h

config.h:
	@case `uname` in                               \
	*Darwin*)                                      \
		echo "#define Defasm Gasmacho";        \
		echo "#define Deftgt T_amd64_sysv";    \
		;;                                     \
	*)                                             \
		echo "#define Defasm Gaself";          \
		case `uname -m` in                     \
		*aarch64*)                             \
			echo "#define Deftgt T_arm64"; \
			;;                             \
		*riscv64*)                             \
			echo "#define Deftgt T_rv64";  \
			;;                             \
		*)                                     \
			echo "#define Deftgt T_amd64_sysv";\
			;;                             \
		esac                                   \
		;;                                     \
	esac > $@

install: qbe
	mkdir -p "$(DESTDIR)/$(BINDIR)"
	cp qbe "$(DESTDIR)/$(BINDIR)/qbe"

uninstall:
	rm -f "$(DESTDIR)/$(BINDIR)/qbe"

clean:
	rm -f *.o */*.o qbe

clean-gen: clean
	rm -f config.h

check: qbe
	tools/test.sh all

check-arm64: qbe
	TARGET=arm64 tools/test.sh all

check-rv64: qbe
	TARGET=rv64 tools/test.sh all

src:
	@echo $(SRCALL)

80:
	@for F in $(SRCALL);                       \
	do                                         \
		awk "{                             \
			gsub(/\\t/, \"        \"); \
			if (length(\$$0) > $@)     \
				printf(\"$$F:%d: %s\\n\", NR, \$$0); \
		}" < $$F;                          \
	done

.PHONY: clean clean-gen check check-arm64 src 80 install uninstall