-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathMakefile
178 lines (141 loc) · 5.57 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
#
# Type `make help` for a list of all the targets
#
CC=gcc
CFLAGS=-c -Wall -Wextra -I /usr/local/include `libpng-config --cflags` -DUSEPNG -DUSEJPG
LDFLAGS=`libpng-config --ldflags` -lz -ljpeg -lm
AWK=awk
# Add your source files here:
LIB_SOURCES=bmp.c
LIB_OBJECTS=$(LIB_SOURCES:.c=.o)
LIB=libbmp.a
# To build luabmp, link against the lua library
LUALIBS=-llua
DOC_DIR = doc
DOCS=$(DOC_DIR)/bitmap.html $(DOC_DIR)/README.html \
$(DOC_DIR)/freetype-fonts.html $(DOC_DIR)/built-in-fonts.html \
$(DOC_DIR)/LICENSE
ifeq ($(BUILD),debug)
# Debug
CFLAGS += -O0 -g
LDFLAGS +=
else
# Release mode
CFLAGS += -O2 -DNDEBUG
LDFLAGS += -s
endif
LUA_EXEC=luabmp
ifeq ($(OS),Windows_NT)
# Windows (MinGW)
CFLAGS += -D WIN32
LUA_EXEC := $(LUA_EXEC).exe
else
UNAME_S := $(shell uname -s)
ifeq ($(UNAME_S),Linux)
endif
ifeq ($(UNAME_S),Linux)
# Under linux, we need to link Lua related stuff with -ldl
LUALIBS += -ldl
CFLAGS += -D LINUX
endif
ifeq ($(UNAME_S),Darwin)
CFLAGS += -D OSX
endif
endif
all: libbmp.a docs utils stb ## Builds everything
debug: ## Build a library with debugging symbols
@$(MAKE) BUILD=debug
libbmp.a: $(LIB_OBJECTS)
@echo $@
@ar rs $@ $^
.c.o:
@echo $@
@$(CC) $(CFLAGS) -c $< -o $@
bmp.o: bmp.c bmp.h
docs: $(DOCS) | $(DOC_DIR) ## Generates documentation
$(DOC_DIR):
@echo $@
@mkdir -p doc
$(DOC_DIR)/bitmap.html: bmp.h d.awk | $(DOC_DIR)
@echo $@
@$(AWK) -v Title="API Documentation" -f d.awk $< > $@
$(DOC_DIR)/LICENSE: LICENSE | $(DOC_DIR)
@echo $@
@cp $< $@
$(DOC_DIR)/README.html: README.md d.awk | $(DOC_DIR)
@echo $@
@$(AWK) -f d.awk -v Clean=1 -v Title="README" $< > $@
$(DOC_DIR)/freetype-fonts.html: ftypefont/ftfont.h d.awk | $(DOC_DIR)
@echo $@
@$(AWK) -v Title="FreeType Font Support" -f d.awk $< > $@
$(DOC_DIR)/built-in-fonts.html: fonts/instructions.md d.awk | $(DOC_DIR)
@echo $@
@$(AWK) -v Title="Raster Font Support" -f d.awk -v Clean=1 $< > $@
# Single header file library
stb: bmph.h ## Package into a single header library
bmph.h: bmp.c bmp.h
@echo Making stb-style single header library $@ from $^
@echo '/* STB-style single header bitmap library.' > $@
@echo ' *' >> $@
@echo ' * To use this file, add the following to _one_ source file:' >> $@
@echo ' *' >> $@
@echo ' * #define BMPH_IMPLEMENTATION' >> $@
@echo ' * #include "bmph.h"' >> $@
@echo ' *' >> $@
@echo ' * and then use `#include "bmph.h"` in all other files that' >> $@
@echo ' * use the bitmap functionality.' >> $@
@echo ' *' >> $@
@echo ' * This file was automatically generated by a script.' >> $@
@echo ' * To modify the code, it is recommend to modify the original' >> $@
@echo ' * sources and then regenerating this file by running `make bmph.h`.' >> $@
@echo ' *' >> $@
@echo ' * The original sources can be found at https://github.com/wernsey/bitmap' >> $@
@echo ' * Contributions are welcome.' >> $@
@echo ' *' >> $@
@echo ' * For more information on stb-style single header libraries, see' >> $@
@echo ' * https://github.com/nothings/stb/blob/master/docs/stb_howto.txt' >> $@
@echo ' */' >> $@
@cat bmp.h >> $@
@echo '#ifdef BMPH_IMPLEMENTATION' >> $@
@cat bmp.c >> $@
@echo '#endif /* BMPH_IMPLEMENTATION */' >> $@
utils: util/hello util/bmfont util/dumpfonts util/cvrt util/imgdup ## Build utilities
util/hello: hello.o libbmp.a | util
@echo $@
@$(CC) -o $@ $^ $(LDFLAGS)
util/bmfont: fonts/bmfont.o misc/to_xbm.o libbmp.a | util
@echo $@
@$(CC) -o $@ $^ $(LDFLAGS)
util/dumpfonts: fonts/dumpfonts.o misc/to_xbm.o libbmp.a | util
@echo $@
@$(CC) -o $@ $^ $(LDFLAGS)
util/cvrt: misc/cvrt.o libbmp.a | util
@echo $@
@$(CC) -o $@ $^ $(LDFLAGS)
util/imgdup: misc/imgdup.o libbmp.a | util
@echo $@
@$(CC) -o $@ $^ $(LDFLAGS)
lua-bindings : $(LUA_EXEC) ## Builds a Lua interpreter for working with bitmaps
$(LUA_EXEC): misc/luabmp.o libbmp.a | doc
@echo $@
@$(CC) -o $@ $^ $(LDFLAGS) $(LUALIBS)
@awk -f d.awk misc/luabmp.c > doc/luabmp.html
misc/luabmp.o: misc/luabmp.c
@echo $@
@$(CC) $(CFLAGS) -I . -c $< -o $@
ftypefont/fttest: ftypefont/fttest.c ftypefont/ftfont.c bmp.c
@echo $@
@$(CC) -I . -I /usr/local/include/freetype2/ -o $@ $^ -lfreetype $(LDFLAGS)
util:
@echo $@
@mkdir -p util
.PHONY : clean lua-bindings docs help stb
help: ## Shows this message
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
clean: ## Cleans all the build files
@-rm -f *.o $(LIB) bmph.h
@-rm -f $(LUA_EXEC) hello *.exe test/*.exe
@-rm -rf $(DOCS)
@-rm -rf util doc misc/*.o fonts/*.o
@echo Cleaned
# The .exe above is for MinGW, btw.