forked from howerj/libforth
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmakefile
180 lines (140 loc) · 4.74 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
# @todo clean up make file
# @todo The standalone executable "libforth" needs a better name, but then so
# does the normal executable "forth".
# @note The makefile is not very Windows friendly, but it will work under
# Cygwin
ECHO = echo
AR = ar
CC = gcc
CFLAGS = -Wall -Wextra -g -pedantic -std=c99 -O2
LDFLAGS =
INCLUDE = libline
TARGET = forth
RM = rm -rf
CTAGS ?= ctags
CP = cp
VIEWER = mupdf
MDS := ${wildcard *.md}
DOCS := ${MDS:%.md=%.htm}
FORTH_FILE = forth.fth
.PHONY: all shorthelp doc clean test profile unit.test forth.test line small fast static
all: shorthelp ${TARGET}
shorthelp:
@${ECHO} "Use 'make help' for a list of all options"
help:
@${ECHO} ""
@${ECHO} "project: lib${TARGET}"
@${ECHO} "description: A small ${TARGET} interpreter and library"
@${ECHO} ""
@${ECHO} "make {option}*"
@${ECHO} ""
@${ECHO} " all create the ${TARGET} libraries and executables"
@${ECHO} " ${TARGET} create the ${TARGET} executable"
@${ECHO} " unit create the unit test executable"
@${ECHO} " test execute the unit tests"
@${ECHO} " doc make the project documentation"
@${ECHO} " lib${TARGET}.a make a static ${TARGET} library"
@${ECHO} " libforth make ${TARGET} with built in core file"
@${ECHO} " clean remove generated files"
@${ECHO} " dist create a distribution archive"
@${ECHO} " profile generate lots of profiling information"
@${ECHO} ""
%.o: %.c *.h
@echo "cc $< -c -o $@"
@${CC} ${CFLAGS} $< -c -o $@
lib${TARGET}.a: lib${TARGET}.o
${AR} rcs $@ $<
${TARGET}: main.o unit.o lib${TARGET}.a
@echo "cc $^ -o $@"
@${CC} ${CFLAGS} $^ ${LDFLAGS} -o $@
forth.core: ${TARGET} ${FORTH_FILE} test
./${TARGET} -s $@ ${FORTH_FILE}
forth.dump: forth.core ${TARGET}
./${TARGET} -l $< -e "0 here dump" > $@
run: ${TARGET} ${FORTH_FILE}
./$< -t ${FORTH_FILE}
# Use the previously built executable to help generate a new one with
# a built in core.
core.gen.c: forth.core
./forth -l $< -e 'c" forth.core" c" core.gen.c" core2c'
lib${TARGET}: main.c unit.o core.gen.c lib${TARGET}.a
@echo "cc $^ -o $@"
@${CC} ${CFLAGS} -I. -DUSE_BUILT_IN_CORE $^ ${LDFLAGS} -o $@
# "unit" contains the unit tests against the C API
unit.test: ${TARGET}
./$< -u
# A side effect of failing the tests in "unit.fth" is the fact that saving to
# "forth.core" will fail, making this test fail.
forth.test: forth unit.test forth.fth unit.fth
./$< -s forth_test.core forth.fth unit.fth
@${RM} forth_test.core
test: unit.test forth.test
tags: lib${TARGET}.c lib${TARGET}.h unit.c main.c
${CTAGS} $^
dist: ${TARGET} ${TARGET}.1 lib${TARGET}.a lib${TARGET}.htm ${DOCS} forth.core
tar zvcf ${TARGET}.tgz $^
%.htm: %.md
markdown $< > $@
libforth.md: main.c libforth.c libforth.h
./convert libforth.c > $@
echo "## Appendix " >> $@
echo "### libforth header" >> $@
./convert -H libforth.h >> $@
echo "### main.c example program" >> $@
./convert main.c >> $@
%.pdf: %.md
pandoc -V geometry:margin=0.5in --toc $< -o $@
%.1: %.md
pandoc -s -t man $< -o $@
%.md: %.c convert
./convert $< > $@
%.md: %.h convert
./convert -H $< -o $@
%.3: %.h
./convert -H $< | pandoc -f markdown -s -t man -o $@
${TARGET}.1: readme.1
${CP} $^ $@
doc: lib${TARGET}.htm ${DOCS}
doxygen: *.c *.h *.md
doxygen -g
doxygen 2> doxygen_warnings.log
small: CFLAGS = -m32 -g -std=c99 -Os
small: ${TARGET}
fast: CFLAGS = -DNDEBUG -O3 -std=c99
fast: ${TARGET}
static: CC=musl-gcc -std=c99 -static
static: ${TARGET}
libline/makefile:
git submodule update
libline/libline.a:
make -C libline libline.a
# just a handy helper when making documentation
show: lib${TARGET}.pdf
${VIEWER} $<
# This option requires a clean build
line: LDFLAGS += -lline
line: CFLAGS += -L${INCLUDE} -I${INCLUDE} -DUSE_LINE_EDITOR
line: libline/libline.a ${TARGET}
# CFLAGS: Add "-save-temps" to keep temporary files around
# objdump: Add "-M intel" for a more sensible assembly output
profile: CFLAGS += -pg -g -O2 -DNDEBUG -fprofile-arcs -ftest-coverage
profile: clean ${TARGET}
./${TARGET} forth.fth unit.fth > testrun.log
gprof ${TARGET} gmon.out > profile.log
gcov lib${TARGET}.c
objdump -d -S lib${TARGET}.o > libforth.s
# attempt decompilation of all visible words
decompile: ${TARGET} forth.fth
rm -vf decompiled.log words.log words.see.log
./${TARGET} -f forth.fth -e words > words.log
sed 's/ / see /g' < words.log > words.see.log
./${TARGET} -t -f forth.fth -e hex < words.see.log > decompiled.log
clean:
${RM} ${TARGET} unit *.a *.so *.o
${RM} *.log *.htm *.tgz *.pdf
${RM} *.core *.dump
${RM} tags
${RM} *.i *.s *.gcov *.gcda *.gcno *.out
${RM} html latex Doxyfile *.db *.bak
${RM} libforth.md
${RM} libforth core.gen.c