Makefile 4.41 KB
Newer Older
Camil Staps's avatar
Camil Staps committed
1
SHELL:=bash
2
CPM:=cpm
3
override CFLAGS:=\
4
	-std=c99\
5
	-Wall\
6
	-Wno-strict-aliasing\
7 8
	-Werror\
	$(CFLAGS)
Camil Staps's avatar
Camil Staps committed
9
override CLIBS+=-lm
Camil Staps's avatar
Camil Staps committed
10

11 12 13 14 15
ifeq ($(MINGW),1)
OS:=Windows_NT
AS:=x86_64-w64-mingw32-as
CC:=x86_64-w64-mingw32-gcc
LD:=x86_64-w64-mingw32-ld
Camil Staps's avatar
Camil Staps committed
16
override LDFLAGS+=--unique=* # Clean linker does not accept split sections
17 18
endif

Camil Staps's avatar
Camil Staps committed
19
USING_CLANG:=0
Camil Staps's avatar
Camil Staps committed
20
ifeq ($(shell $(CC) --version | grep -o clang),clang)
21
USING_CLANG:=1
Camil Staps's avatar
Camil Staps committed
22
ifndef OS
23
OS:=Mac
Camil Staps's avatar
Camil Staps committed
24
endif
25 26
endif

27 28
ifeq ($(OS),Mac)
override CFLAGS+=-DMACH_O64
29 30 31
SRC_INTERFACE:=interface.macos64.s
else
SRC_INTERFACE:=interface.linux64.s
Camil Staps's avatar
Camil Staps committed
32
endif
33 34 35
ifeq ($(OS),Windows_NT)
override CFLAGS+=-DWINDOWS
else
36
override CFLAGS+=-DPOSIX -D_POSIX_C_SOURCE=199309L -D_XOPEN_SOURCE=500 -D_C99_SOURCE
Camil Staps's avatar
Camil Staps committed
37
endif
Camil Staps's avatar
Camil Staps committed
38 39
ifeq ($(USING_CLANG),0)
override CFLAGS+=-Wno-misleading-indentation
40 41
else
override CFLAGS+=-Wno-parentheses-equality
Camil Staps's avatar
Camil Staps committed
42
endif
Camil Staps's avatar
Camil Staps committed
43

44 45 46 47
ifeq ($(filter optimized,$(MAKECMDGOALS)),optimized)
override CFLAGS+=-DCOMPUTED_GOTOS -Ofast -fno-unsafe-math-optimizations
endif

48 49 50 51
ifeq ($(OS),Windows_NT)
ABCOPT:=ABCOptimiser.exe
BCGEN:=ByteCodeGenerator.exe
BCLINK:=ByteCodeLinker.exe
Camil Staps's avatar
Camil Staps committed
52
BCPRELINK:=ByteCodePrelinker.exe
53
BCSTRIP:=ByteCodeStripper.exe
54 55 56 57 58
INTERP:=interpret.exe
else
ABCOPT:=abcopt
BCGEN:=bcgen
BCLINK:=bclink
Camil Staps's avatar
Camil Staps committed
59
BCPRELINK:=bcprelink
60
BCSTRIP:=bcstrip
61 62 63
INTERP:=interpret
endif

Camil Staps's avatar
Camil Staps committed
64
BINARIES:=$(ABCOPT) $(BCGEN) $(BCLINK) $(BCPRELINK) $(BCSTRIP) $(INTERP)
Camil Staps's avatar
Camil Staps committed
65

66
SRC_BCGEN:=\
Camil Staps's avatar
Camil Staps committed
67
	abc_instructions.c\
68 69 70
	bcgen.c\
	bcgen_instructions.c\
	bcgen_instruction_table.c\
71
	bytecode.c\
72
	parse_abc.c\
Camil Staps's avatar
Camil Staps committed
73
	util.c
74
DEP_BCGEN:=$(subst .c,.h,$(SRC_BCGEN)) settings.h
Camil Staps's avatar
Camil Staps committed
75

76
SRC_BCLINK:=\
Camil Staps's avatar
Camil Staps committed
77
	abc_instructions.c\
78
	bcgen_instructions.c\
79
	bclink.c\
Camil Staps's avatar
Camil Staps committed
80
	bytecode.c\
Camil Staps's avatar
Camil Staps committed
81
	parse.c\
Camil Staps's avatar
Camil Staps committed
82
	util.c
83
DEP_BCLINK:=$(subst .c,.h,$(SRC_BCLINK)) settings.h
Camil Staps's avatar
Camil Staps committed
84

Camil Staps's avatar
Camil Staps committed
85
SRC_BCPRELINK:=\
86
	abc_instructions.c\
Camil Staps's avatar
Camil Staps committed
87
	bcprelink.c\
88 89 90
	bytecode.c\
	parse.c\
	util.c
Camil Staps's avatar
Camil Staps committed
91
DEP_BCPRELINK:=$(subst .c,.h,$(SRC_BCPRELINK)) settings.h
92

Camil Staps's avatar
Camil Staps committed
93
SRC_BCSTRIP:=\
94
	abc_instructions.c\
Camil Staps's avatar
Camil Staps committed
95 96
	bcgen_instructions.c\
	bcstrip.c\
97 98
	bytecode.c\
	parse.c\
Camil Staps's avatar
Camil Staps committed
99
	strip.c\
100
	util.c
Camil Staps's avatar
Camil Staps committed
101
DEP_BCSTRIP:=$(subst .c,.h,$(SRC_BCSTRIP)) settings.h
102

103 104 105
SRC_INTERPRET:=\
	abc_instructions.c\
	bytecode.c\
106
	debug_find_nodes.c\
107
	gc.c\
108 109
	interpret.c\
	parse.c\
Camil Staps's avatar
Camil Staps committed
110
	util.c
111
DEP_INTERPRET:=$(subst .c,.h,$(SRC_INTERPRET))\
112
	interpret_instructions.h\
113
	interpret_instructions_interworking.h\
114 115 116
	settings.h

SRC_INTERPRET_LIB:=$(SRC_INTERPRET)\
117
	bcgen_instructions.c\
118 119
	copy_host_to_interpreter.c\
	copy_interpreter_to_host.c\
Camil Staps's avatar
Camil Staps committed
120 121
	finalizers.c\
	strip.c
Camil Staps's avatar
Camil Staps committed
122
ASM_INTERPRET_LIB:=$(subst .c,.s,$(SRC_INTERPRET_LIB))
Camil Staps's avatar
Camil Staps committed
123
OBJ_INTERPRET_LIB:=$(subst .c,.o,$(SRC_INTERPRET_LIB))
124
DEP_INTERPRET_LIB:=$(subst .c,.h,$(SRC_INTERPRET_LIB))\
125
	interpret_instructions.h\
126
	interpret_instructions_interworking.h\
127
	settings.h
Camil Staps's avatar
Camil Staps committed
128

Camil Staps's avatar
Camil Staps committed
129 130 131 132 133 134
ifneq ($(OS),Windows_NT)
override BINARIES+=debug
endif

all: $(BINARIES)

135 136
optimized:

Camil Staps's avatar
Camil Staps committed
137 138 139 140 141 142 143 144 145 146 147 148 149 150
ifeq ($(OS),Windows_NT)
$(ABCOPT): abcopt_win.prj.default .FORCE
else
$(ABCOPT): abcopt.prj.default .FORCE
endif
	cp $< abcopt.prj
	$(CPM) project abcopt.prj build

$(BCGEN): $(SRC_BCGEN) $(DEP_BCGEN)
	$(CC) $(CFLAGS) $(CLIBS) $(SRC_BCGEN) -DBCGEN -o $@

$(BCLINK): $(SRC_BCLINK) $(DEP_BCLINK)
	$(CC) $(CFLAGS) $(CLIBS) -UCOMPUTED_GOTOS $(SRC_BCLINK) -DLINKER -o $@

Camil Staps's avatar
Camil Staps committed
151 152 153
$(BCPRELINK): $(SRC_BCPRELINK) $(DEP_BCPRELINK)
	$(CC) $(CFLAGS) $(CLIBS) -UCOMPUTED_GOTOS -DPRELINKER -UWORD_WIDTH -DWORD_WIDTH=64 $(SRC_BCPRELINK) -o $@

154 155 156
$(BCSTRIP): $(SRC_BCSTRIP) $(DEP_BCSTRIP)
	$(CC) $(CFLAGS) $(CLIBS) -UCOMPUTED_GOTOS $(SRC_BCSTRIP) -o $@

157
$(INTERP): $(SRC_INTERPRET) $(DEP_INTERPRET)
Camil Staps's avatar
Camil Staps committed
158
	$(CC) $(CFLAGS) $(CLIBS) -DINTERPRETER $(SRC_INTERPRET) -o $@
159

Camil Staps's avatar
Camil Staps committed
160
library: $(OBJ_INTERPRET_LIB) interface.o
161
	cp $^ ../lib/Clean\ System\ Files
Camil Staps's avatar
Camil Staps committed
162

Camil Staps's avatar
Camil Staps committed
163
$(OBJ_INTERPRET_LIB): %.o: %.s
Camil Staps's avatar
Camil Staps committed
164 165
	$(AS) $(ASFLAGS) $< -o $@

166 167 168
interface.o: $(SRC_INTERFACE)
	$(AS) $(ASFLAGS) $< -o $@

Camil Staps's avatar
Camil Staps committed
169
$(ASM_INTERPRET_LIB): %.s: %.c $(DEP_INTERPRET_LIB)
Camil Staps's avatar
Camil Staps committed
170
	$(CC) -DINTERPRETER -DLINK_CLEAN_RUNTIME -fno-pie $(CFLAGS) -S $< -o $@
Camil Staps's avatar
Camil Staps committed
171 172 173
ifeq ($(OS),Mac)
	sed -i '' -f mac_fix_underscores.sed $@
endif
174

175 176
interpret_instructions.h: .FORCE
	$(MAKE) -C ../tools interpretergenc
177
	../tools/interpretergenc > $@
178

179
debug: $(SRC_INTERPRET) $(DEP_INTERPRET) debug_curses.c debug_curses.h
Camil Staps's avatar
Camil Staps committed
180 181
	$(CC) $(CFLAGS) $(CLIBS) -UCOMPUTED_GOTOS -DINTERPRETER -DDEBUG_CURSES -lcurses $(SRC_INTERPRET) debug_curses.c -o $@

182
AUXILIARIES:=$(INTERPRET_LIB)\
Camil Staps's avatar
Camil Staps committed
183
	$(ASM_INTERPRET_LIB)\
Camil Staps's avatar
Camil Staps committed
184 185
	$(OBJ_INTERPRET_LIB)\
	interface.o
186

Camil Staps's avatar
Camil Staps committed
187
clean:
188
	$(RM) $(BINARIES) $(AUXILIARIES)
189 190 191 192 193 194
	find . \
		-name '*.abc' -delete \
		-or -name '*.o' -delete -or -name '*.obj' -delete \
		-or -name '*.prp' -delete \
		-or -name '*.obc' -delete -or -name '*.bc' -delete \
		-or -name 'Clean System Files' -empty -delete
Camil Staps's avatar
Camil Staps committed
195 196

.FORCE:
197
.PHONY: all clean library optimized