blob: 3ba528884ab03158f1d98cdf9b4bfe8ae5407b78 (
plain)
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
|
# Makefile
GPERF = gperf
CC = cc
CFLAGS += -Ic_headers/include -Iinclude -ggdb
BLDDIR ?= build
all: $(BLDDIR) endpoints.so main
.PHONY: all clean $(BLDDIR)
$(BLDDIR):
mkdir -p $(BLDDIR)
# endpoints
$(BLDDIR)/endpoints.o: src/endpoints.c $(BLDDIR)/rename.ld $(BLDDIR)
# PIC here is important
$(CC) -fPIC -c $< $(CFLAGS) -o $@
$(BLDDIR)/rename.ld: $(BLDDIR)/endpoints.o $(BLDDIR)
# Looks terrible
# All it does is generating ld script that creates aliases for functions
echo SECTIONS { > $@
@readelf --syms --wide $(BLDDIR)/endpoints.o | awk '/FUNC/ && /GLOBAL/ && /ENDP/ {old = $$8; gsub(/_/, "/", $$8); gsub(/ENDP/, "", $$8); printf "\t%s = %s;\n", $$8, old }' >> $@
echo } >> $@
endpoints.so: $(BLDDIR)/endpoints.o $(BLDDIR)/common.o $(BLDDIR)/mime.o
$(CC) -shared -fPIE -Wl,$(BLDDIR)/rename.ld $^ -lmicrohttpd -o $@
# main
src/mime.c.inc: src/mime_gen.c.gperf
$(GPERF) -IGCt -K key -H __mimetype_hash -N __mimetype_get_helper -W mimetype_words $< > $@
$(BLDDIR)/mime.o: src/mime.c src/mime.c.inc
$(CC) -c $(CFLAGS) -o $@ $<
$(BLDDIR)/%.o: src/%.c
$(CC) -c $(CFLAGS) -o $@ $^
main: $(BLDDIR)/main.o $(BLDDIR)/mime.o $(BLDDIR)/common.o
$(CC) $(CFLAGS) $^ -ldl -lmicrohttpd -lsqlite3 -o $@
clean:
$(RM) $(BLDDIR)/* main endpoints.o endpoints.so rename.ld include/mime.h.inc
|