# Makefile GPERF = gperf CC = gcc BLDDIR ?= build CFLAGS += -Ic_headers/include -Iinclude -I$(BLDDIR) -ggdb -Wall -Wextra -DDEFAULT_ENDPOINTS_PATH=\"./endpoints.so\" all: $(BLDDIR) endpoints.so main .PHONY: all clean run $(BLDDIR): mkdir -p $(BLDDIR) $(BLDDIR)/template: mkdir -p $@ $(BLDDIR)/ste: c_headers/ste/ste.c $(CC) -o $@ $< $(BLDDIR)/template/%: template/%.ste $(BLDDIR)/ste $(BLDDIR)/template $(BLDDIR)/ste -o $@ $< # endpoints $(BLDDIR)/endpoints.o: src/endpoints.c $(BLDDIR) \ $(BLDDIR)/template/args.html $(BLDDIR)/template/linkadd.html # 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) --recursive $(BLDDIR)/template/* $(BLDDIR)/* main endpoints.o endpoints.so rename.ld include/mime.h.inc veryclean: clean $(RM) jals.db run: main endpoints.so env $(shell cat config.env) ./main