forked from howerj/embed
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmakefile
159 lines (113 loc) · 3.29 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
# Embed Virtual Machine Makefile
#
# Targets:
# - Unix (Linux Tested)
# - Windows (Using MinGW)
CFLAGS= -O2 -std=c99 -g -Wall -Wextra -fwrapv -fPIC -pedantic -I. -Wmissing-prototypes
CC=gcc
EXE=
DF=
META1=embed-1.blk
META2=embed-2.blk
TEMP=tmp.blk
UNIT=unit.blk
TARGET=embed
CMP=cmp
AR=ar
ARFLAGS=rcs
RM=rm -fv
TESTAPPS=cpp call mmu rom ref
TRACER=
.PHONY: all clean run cross double-cross default tests docs apps dist
default: all
ifeq ($(OS),Windows_NT)
DF=
EXE=.exe
TESTAPPS+= win
.PHONY: ${TARGET}
else # assume unixen
DF=./
EXE=
TESTAPPS+= unix
endif
FORTH=${TARGET}${EXE}
B2C=b2c${EXE}
all: ${FORTH}
${B2C}: t/b2c.o
${CC} ${CFLAGS} $< -o $@
core.gen.c: ${B2C} embed-1.blk
${DF}${B2C} embed_default_block embed-1.blk $@ "eForth Image"
embed.o: embed.c embed.h
util.o: util.c util.h
lib${TARGET}.a: ${TARGET}.o image.o
${AR} ${ARFLAGS} $@ $^
lib${TARGET}.so: ${TARGET}.o image.o
${CC} -shared -o $@ $^
${FORTH}: main.o util.o lib${TARGET}.a
${CC} $^ ${LDFLAGS} -o $@
### Meta Compilation #########################################################
${META1}: ${FORTH} embed.fth
${DF}${FORTH} -o ${META1} embed.fth
${META2}: ${FORTH} ${META1} embed.fth
${DF}${FORTH} -o ${META2} -i ${META1} embed.fth
cross: ${META1}
double-cross: ${META2}
${CMP} ${META1} ${META2}
run: cross
${TRACER} ${DF}${FORTH} -o ${TEMP} -i ${META1}
### Unit Tests ###############################################################
${UNIT}: ${FORTH} ${META1} t/unit.fth
${DF}${FORTH} -o ${UNIT} -i ${META1} t/unit.fth
unit: t/unit.c util.o libembed.a
${CC} ${CFLAGS} $^ -o $@
tests: unit ${UNIT}
${DF}unit${EXE}
### Documentation ############################################################
%.pdf: %.md
pandoc -V geometry:margin=0.5in --toc $< -o $@
%.md: %.fth t/convert
t/${DF}convert $< > $@
%.htm: %.md t/convert
markdown $< > $@
docs: ${TARGET}.pdf ${TARGET}.htm
### Release Distribution #####################################################
embed.blk: embed-1.blk
cp $< $@
dist: lib${TARGET}.so lib${TARGET}.a ${TARGET}.pdf embed.1 ${FORTH} ${TARGET}.h embed.blk
tar zcf ${TARGET}.tgz $^
### Test Applications ########################################################
cpp: t/cpp.cpp util.o libembed.a
${CXX} ${CPPFLAGS} -I. -o $@ $^
eforth: CC=musl-gcc
eforth: CFLAGS=-Wall -Wextra -Os -fno-stack-protector -static -std=c99 -DNDEBUG
eforth: LDFLAGS=-Wl,-O1
eforth: embed.c image.c util.c main.c
${CC} ${CFLAGS} $^ -o $@
strip $@
unix: CFLAGS=-O2 -Wall -Wextra -std=gnu99 -I.
unix: t/unix.c util.o libembed.a
${CC} ${CFLAGS} $^ -o $@
win: CFLAGS=-Wall -Wextra -std=gnu99 -I.
win: t/win.c util.o libembed.a
${CC} ${CFLAGS} $^ -o $@
call: CFLAGS=-O3 -Wall -Wextra -std=c99 -I.
call: t/call.c util.o libembed.a
${CC} ${CFLAGS} $^ -lm -o $@
mmu: CFLAGS=-O2 -Wall -Wextra -std=c99 -I.
mmu: t/mmu.c util.o libembed.a
${CC} ${CFLAGS} $^ -o $@
rom: CFLAGS=-O2 -Wall -Wextra -std=c99 -I. -g
rom: t/rom.c util.o libembed.a
${CC} ${CFLAGS} $^ -o $@
ref: t/ref.c embed.blk
${CC} ${CFLAGS} $< -o $@
apps: ${TESTAPPS}
### Cleanup ##################################################################
clean:
${RM} ${FORTH} *.blk ${B2C}
${RM} *.o *.a *.so *.pdf *.htm *.log
${RM} *.gen.c
${RM} *.tgz
${RM} *.bin
${RM} ${TESTAPPS} eforth unit
### EOF ######################################################################