-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMakefile
166 lines (137 loc) · 4.96 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
# Use bash syntax for all shell commands
export SHELL := /bin/bash
# Where to install.
prefix ?= /usr/local
targets := m100-tokenize m100-decomment m100-jumps m100-crunch
scripts := tokenize m100-sanity
# By default, create m100-tokenize and friends (implicitly compiled from .lex)
all: ${targets} bacmp
m100-tokenize.o: m100-tokenize-main.c
m100-decomment.o: m100-tokenize-main.c
# Use 'make debug' to compile with debugging and catch pointer errors.
debug : CFLAGS+=-g -fsanitize=address -Wall -Wno-unused-function
debug : LDLIBS+=-lasan
debug : all
# Rule to automatically run flex to create .c files from .lex.
.SUFFIXES: .lex
.lex.c:
${flex} -o $@ $<
# Utility targets are "PHONY" so they'll run even if a file exists
# with the same name.
.PHONY: all install uninstall clean test check distcheck artifacts cfiles
install: ${targets} bacmp
cp -p $^ ${prefix}/bin/
cp -p ${scripts} ${prefix}/bin/
uninstall:
for f in ${targets} bacmp ${scripts}; do \
rm ${prefix}/bin/$$f 2>/dev/null || true; \
done
clean:
rm ${targets} \
$(addsuffix .c, ${targets}) \
bacmp \
*.tar.gz \
*.o *~ core \
input.do output.do output.ba \
2>/dev/null || true
# Check that the program is building and running correctly
check: all test-m100-tokenize test-m100-decomment test-m100-crunch test-tokenize-script
# Check that the distribution will actually install, uninstall.
distcheck: all
@echo Not implemented yet
# Quick test
test: test-tokenize-script
test-tokenize-script: all
@echo "Testing tokenize script"
@for f in samples/*.BA; do \
src="$${f%.BA}.DO"; \
[ -r "$$src" ] || continue; \
./tokenize "$$src" output.ba >/dev/null; \
echo -n " tokenize $$src: "; \
if ./bacmp output.ba "$$f"; then echo "(pass)"; else exit 1; fi \
done
@for f in samples/*-d.BA; do \
src="$${f%-d.BA}.DO"; \
./tokenize -d "$$src" output.ba >/dev/null; \
echo -n " tokenize -d $$src:"; \
if ./bacmp "$$f" output.ba; then echo "(pass)"; else exit 1; fi; \
done
@for f in samples/*-c.BA; do \
src="$${f%-c.BA}.DO"; \
./tokenize -c "$$src" output.ba >/dev/null; \
echo -n " tokenize -c $$src:"; \
if ./bacmp "$$f" output.ba; then echo "(pass)"; else exit 1; fi; \
rm output.ba; \
done
test-m100-tokenize: m100-tokenize bacmp
@echo "Testing m100-tokenize"
@for f in samples/*.BA; do \
src="$${f%.BA}.DO"; \
[ -r "$$src" ] || continue; \
./m100-sanity "$$src" | ./m100-tokenize >output.ba; \
echo -n " m100-tokenize $$src: "; \
if ./bacmp output.ba "$$f"; then echo "(pass)"; else true exit 1; echo ./m100-sanity "$$src"; echo; xxd output.ba | tail; wc -m output.ba "$$f"; echo; echo; fi; \
rm output.ba; \
done
test-m100-decomment: m100-decomment m100-jumps
@echo "Testing m100-decomment and m100-jumps"
@for f in samples/*-decommented.DO; do \
src="$${f%-decommented.DO}.DO"; \
[ -r "$$src" ] || continue; \
./m100-sanity "$$src" input.do; \
jumps=`./m100-jumps input.do`; \
./m100-decomment input.do output.do $$jumps; \
echo -n " m100-decomment $$src - $$jumps:"; \
if diff -q "$$f" output.do; then echo "(pass)"; else exit 1; fi; \
rm input.do output.do; \
done
test-m100-crunch: m100-crunch
@echo "Testing m100-crunch"
@for f in samples/*-crunched.DO; do \
src="$${f%-crunched.DO}.DO"; \
[ -r "$$src" ] || continue; \
./m100-crunch "$$src" output.do; \
echo -n " m100-crunch $$src:"; \
if diff -q "$$f" output.do; then echo "(pass)"; else exit 1; fi; \
rm output.do; \
done
################################################################
# Everything that follows is for creating the archive files
flex := flex
ifeq (${OS},Windows_NT)
flex := win_flex
CC := gcc
endif
# GNU tar lets us easily store files into a subdirectory in the archive.
# Unfortunately, MacOS is recalcitrant.
UNAME := $(shell uname)
ifeq ($(UNAME), Darwin)
tar := gtar
else
tar := tar
endif
# thisdir and xform are used to create tar files that unpack into a directory
thisdir := $(notdir $(shell pwd))
xform := --xform "s%^%${thisdir}/%"
# platform, specify the machine os and architecture in the .tar.gz filename
platform := $(shell uname -s)-$(shell uname -m)
# The intermediate .c files from *.lex.
cfiles=$(addsuffix .c, ${targets})
cfiles: ${cfiles}
# Create all tar files.
artifacts: tokenize.tar.gz bin-${platform}.tar.gz cfiles.tar.gz
# Entire project archive.
tokenize.tar.gz: ${targets} ${cfiles}
${tar} -C .. -zcf ../$@ \
--exclude='*reference*' --exclude='.git*' --exclude='*.tar.gz' \
${thisdir}
mv ../$@ .
# Executable binaries for a specific platform.
bin-${platform}.tar.gz: ${targets} ${scripts} bacmp
${tar} ${xform} -acf $@ $^
# Just the code needed to compile without flex.
cfiles.tar.gz: ${cfiles} cfiles-${platform}.tar.gz
${tar} ${xform} -acf $@ $^
cfiles-${platform}.tar.gz: m100-tokenize-main.c bacmp.c ${scripts} Makefile
${tar} ${xform} -acf $@ $^
# Reminder to self: $@ is target, $^ is all prerequisites, $< is 1st prereq.