# Makefile GPERF = gperf CC = gcc CFLAGS += -Ic_headers/include -Iinclude -ggdb -Wall -Wextra -DDEFAULT_ENDPOINTS_PATH=\"./endpoints.so\" 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)/sql.o: src/sql.c $(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 $(BLDDIR)/sql.o $(CC) -shared -fPIC -Wl,$(BLDDIR)/rename.ld $(CFLAGS) $^ -lmicrohttpd -lsqlite3 -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