diff options
Diffstat (limited to 'Makefile')
-rw-r--r-- | Makefile | 47 |
1 files changed, 34 insertions, 13 deletions
@@ -1,26 +1,47 @@ # Makefile -CFLAGS += -Ic_headers/include +GPERF = gperf +CC = cc -all: main endpoints.so +CFLAGS += -Ic_headers/include -Iinclude -ggdb +BLDDIR ?= build -.PHONY: all clean +all: $(BLDDIR) endpoints.so main -endpoints.o: endpoints.c - $(CC) -c $< $(CFLAGS) -o $@ +.PHONY: all clean $(BLDDIR) -rename.ld: endpoints.o +$(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 it generates renaming + # All it does is generating ld script that creates aliases for functions echo SECTIONS { > $@ - @readelf --syms endpoints.o | awk '/FUNC/ && /GLOBAL/ {printf "\t%s = %s;\n", gensub(/_/, "/", "g", $$8), $$8;}' >> $@ + @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: endpoints.o rename.ld - $(CC) -shared -Wl,rename.ld $< -fPIE -o $@ +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: main.c - $(CC) $< $(CFLAGS) -ldl -lmicrohttpd -o $@ +main: $(BLDDIR)/main.o $(BLDDIR)/mime.o $(BLDDIR)/common.o + $(CC) $(CFLAGS) $^ -ldl -lmicrohttpd -lsqlite3 -o $@ clean: - $(RM) main endpoints.o endpoints.so rename.ld + $(RM) $(BLDDIR)/* main endpoints.o endpoints.so rename.ld include/mime.h.inc |