CC = $(shell which gcc) PANDOC = $(shell which pandoc) OBJDUMP = $(shell which objdump) OBJCOPY = $(shell which objcopy) READELF = $(shell which readelf) OUTPUT = libdzonerzy.so SRC_INC_DIR = src/include CFLAGS = -Wno-error=unused-parameter -Wno-error=unused-const-variable -std=c99 -O0 -shared -fPIC -I$(SRC_INC_DIR) -Wno-int-conversion -Wno-div-by-zero LDFLAGS = EMBED_TOOL = tools/bin/embed EMBED_ARGS = -f=h DIST = dist SRC_DIR = src RAW_DIST = dist/raw SITE_DIST = dist/site AWK_UTIL = awk '/^\s*\[[0-9]+\]\s+([^\.].+)/ {print $$2}' AWK_UTIL_NOCRLF = awk '/^\s*\[[0-9]+\]\s+([^\.].+)/ {printf $$2" "}' PANDOC_ARGS = --standalone --table-of-contents --section-divs --email-obfuscation=references --css=main.css --include-after-body=$(RAW_DIST)/footer.html libdzonerzy: @echo "/* DO NOT EDIT THIS FILE - it is machine generated */" > $(SRC_DIR)/res.h @mkdir -p $(DIST) @mkdir -p $(RAW_DIST) @mkdir -p $(SITE_DIST) @$(foreach file, $(wildcard res/*), $(EMBED_TOOL) -i $(file) -o $(SRC_INC_DIR)/$(notdir $(file)).h $(EMBED_ARGS);) @ls $(SRC_INC_DIR)/*.h | xargs -n1 basename | sed 's/^/#include /' >> $(SRC_DIR)/res.h $(CC) $(CFLAGS) $(LDFLAGS) -o $(DIST)/$(OUTPUT) $(SRC_DIR)/libdzonerzy.so.c $(SRC_DIR)/challenge.o libdzonerzy-dump: @$(READELF) -S -W $(DIST)/$(OUTPUT) | $(AWK_UTIL) | xargs dirname {} | sort | uniq | xargs -I{} mkdir -p $(RAW_DIST)/{} @$(foreach fn, $(shell $(READELF) -S -W $(DIST)/$(OUTPUT) | $(AWK_UTIL_NOCRLF)), $(OBJCOPY) $(DIST)/$(OUTPUT) --dump-section $(fn)=/dev/stdout | cat | head -c -1 > $(RAW_DIST)/$(fn);) libdzonerzy-gen: libdzonerzy-dump @mkdir -p $(SITE_DIST)/assets/ @$(foreach page, $(wildcard $(RAW_DIST)/pages/*), $(PANDOC) $(PANDOC_ARGS) --from=markdown --to=html --output=$(shell echo $(SITE_DIST)/$(notdir $(page)) | sed 's/\.md/\.html/') $(page);) @cp $(RAW_DIST)/main.css $(SITE_DIST)/main.css @cp $(RAW_DIST)/sitemap.xml $(SITE_DIST)/sitemap.xml @cp -r $(RAW_DIST)/embed/* $(SITE_DIST)/assets/ @cp $(DIST)/libdzonerzy.so $(SITE_DIST)/libdzonerzy.so @chmod -R 755 $(SITE_DIST)/* clean-libdzonerzy: @echo "/* DO NOT EDIT THIS FILE - it is machine generated */" > $(SRC_DIR)/res.h rm -rf $(DIST) rm -f $(SRC_INC_DIR)/*.h