forked from iromero91/PMAS
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Makefile
executable file
·208 lines (173 loc) · 6.6 KB
/
Makefile
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
##############################################################################
#### On building the Pika Macro ASsembler ####
##############################################################################
#### PMAS was originally designed by Rafael Vuijk (DarkFader) of darkfader.net
####
#### This is designed for GNU Make. Compile thru MSYS2 on Windows.
#### Windows (admin PowerShell prompt with Chocolatey installed):
#### choco install python3 msys2
#### msys2
#### pacman -S mingw-w64-gcc make diffutils zip
#### make release
#### Linux (Ubuntu):
#### apt install build-essential diffutils tar
#### make release
####
#### build_common_pm.py works on Python 2.7+ so the version that ships with
#### your linux install should be good enough.
PMAS_VERSION := 1.1
.PHONY: help
help:
@echo "Command goals:"
@echo " help This list."
@echo " release Build release version of pmas."
@echo " debug Build debug version of pmas."
@echo " bundle Bundle a release build"
@echo " releasetest Run some tests."
@echo " debugtest Run some tests under gdb to find bugs."
@echo " clean Delete all output files (besides release)."
##############################################################################
#### Config ####
##############################################################################
# Command-line configurable options
## Select which CPU to test, folder name from cpu subdir
CPU ?= all
# Tools
COMPARE := diff -q --binary
LD := $(CXX)
PY := python
PMAS = ./$(tPMAS)
PMDIS = ./$(tPMDIS)
# General
CPUS := minx s1c88 pm r16
EXES = $(tPMAS) $(tPMDIS)
COPYME = $(EXES) $(wildcard *.md) cpu
SOURCES := $(wildcard src/*.cpp)
DEPFILES := $(SOURCES:src/%.cpp=obj/%.d)
NODEPS := clean
# Build flags
INCLUDES := -Isrc
CXXFLAGS := -Wall $(INCLUDES) -DVERSION="\"$(PMAS_VERSION)\""
LDFLAGS := $(INCLUDES)
ifeq ($(OS),Windows_NT)
tPMAS := pmas.exe
tPMDIS := pmdis.exe
tPARSEMINDX := parsemindx.exe
ifeq ($(PROCESSOR_ARCHITECTURE),AMD64)
BUNDLE := releases/pmas-$(PMAS_VERSION)-windows-x64.zip
else
BUNDLE := releases/pmas-$(PMAS_VERSION)-windows-x86.zip
endif
else
tPMAS := pmas
tPMDIS := pmdis
tPARSEMINDX := parsemindx
UNAME_S := $(shell uname -s)
UNAME_P := $(shell uname -p)
ifeq ($(UNAME_S),Darwin)
OS := osx
else
OS := linux
endif
ifeq ($(UNAME_P),x86_64)
BUNDLE := releases/pmas-$(PMAS_VERSION)-$(OS)-x64.tar.gz
else
BUNDLE := releases/pmas-$(PMAS_VERSION)-$(OS)-x86.tar.gz
endif
endif
# Generate dependecies
## Do g++ -MM exports and make object deps rules
ifeq (,$(filter $(MAKECMDGOALS),$(NODEPS)))
-include $(DEPFILES)
endif
##############################################################################
#### Phony rules ####
##############################################################################
.PHONY: release
release: CFLAGS += -O3
release: $(EXES)
.PHONY: debug
debug: CFLAGS += -g -DDEBUG
release: $(EXES)
.PHONY: releasetest
releasetest: release test-$(CPU)
.PHONY: debugtest
debugtest: PMAS = echo r | gdb -q -x - --args $(PMAS)
debugtest: debug test-$(CPU)
.PHONY: bundle
bundle: releasetest $(BUNDLE)
##############################################################################
#### Executables ####
##############################################################################
EVAL_O = obj/eval.o obj/stack.o obj/misc.o obj/symbol.o $(TMPLABEL_O) obj/valuetype.o
INSTRUCTION_O = obj/instruction.o $(MEM_O) $(EVAL_O)
MACROLIST_O = obj/macrolist.o obj/misc.o # $(SYMBOL_O)
MEM_O = obj/mem.o obj/misc.o
STACK_O = obj/stack.o obj/misc.o $(VALUETYPE_O)
SYMBOL_O = obj/symbol.o $(MACROLIST_O) $(EVAL_O) # $(VALUETYPE_O)
TMPLABEL_O = obj/tmplabel.o obj/misc.o
VALUETYPE_O = obj/valuetype.o $(EVAL_O)
$(tPMAS): obj/pmas.o $(MACROLIST_O) $(INSTRUCTION_O)
$(LD) $(LDFLAGS) -o $@ $(filter %.o,$^)
$(tPMDIS): obj/pmdis.o $(INSTRUCTION_O)
$(LD) $(LDFLAGS) -o $@ $(filter %.o,$^)
# Isn't needed anymore but...
$(tPARSEMINDX): obj/parsemindx.o $(INSTRUCTION_O)
$(LD) $(LDFLAGS) -o $@ $(filter %.o,$^)
obj/%.d: src/%.cpp
@mkdir obj 2>/dev/null | true
$(CXX) $(CXXFLAGS) -MM -MT $(patsubst src/%.cpp,obj/%.o,$(filter %.cpp,$+)) $(filter %.cpp,$+) > $@
obj/%.o: src/%.cpp
@mkdir obj 2>/dev/null | true
$(CXX) $(CXXFLAGS) -c -o $@ $<
cpu/pm.s: cpu/s1c88/s1c88.s
$(PY) build_common_pm.py
##############################################################################
#### Building release rules ####
##############################################################################
releases/pmas-%.zip: build
cd $< && zip -r ../$@ *
releases/pmas-%.tar.gz: build
cd $< && tar -czf ../$@ *
build: cpu/pm.s $(COPYME)
@echo 'If this fails, update the changelog'
grep $(PMAS_VERSION) README.md
-mkdir $@
-cp -r $? $@
##############################################################################
#### Test rules ####
##############################################################################
TESTFILESMINX := test/test-reference.s $(wildcard test/minx/*.s)
TESTFILESS1C88 := test/test-reference.s $(wildcard test/s1c88/*.s)
TESTFILESR16 := $(wildcard test/r16/*.s)
# Test suites
.PHONY: test-all test-pm $(addprefix test-,$(patsubst cpu/%,%,$(wildcard cpu/*)))
test-all: test/test-nested.min test-r16 test-pm
test-pm: CPU = pm
test-pm: cpu/pm.s test-minx test-s1c88
test-minx: $(tPMAS) $(TESTFILESMINX:.s=.min)
$(COMPARE) test/minx/opcodes1.min test/minx/opcodes2.min
$(COMPARE) test/minx/opcodes1.min test/minx/opcodes3.min
$(COMPARE) test/test-reference.min test/minx/test.min
test-s1c88: $(tPMAS) $(TESTFILESS1C88:.s=.min)
$(COMPARE) test/test-reference.min test/s1c88/test.min
test-r16: $(tPMAS) $(TESTFILESR16:.s=.min)
# TODO: $(COMPARE) test/r16/reference.min test/r16/test.min
# Build test files
test/%.min: test/%.s $(tPMAS)
$(PMAS) $< $@ $(@:.min=.sym)
define test_template =
test/$(1)/%.min: test/$(1)/%.s $$(tPMAS) cpu/$(1)/$(1).s
$$(PMAS) -c $$(CPU:all=$(1)) $$< $$@ $$(@:.min=.sym)
endef
$(foreach cpu,$(CPUS),$(eval $(call test_template,$(cpu))))
##############################################################################
#### Clean-up ####
##############################################################################
.PHONY: clean
clean:
-rm -f obj/*.o obj/*.d test/*.min test/*.sym test/*.dis.s \
test/*/*.min test/*/*.sym test/*/*.dis.s \
pmas pmas.exe pmdis pmdis.exe parsemindx parsemindx.exe
-rm -rf build
-rmdir obj