libdzonerzy.so/src/Makefile

57 lines
2.6 KiB
Makefile
Raw Normal View History

2023-07-13 14:29:58 +00:00
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" "}'
2023-07-13 22:00:51 +00:00
PANDOC_ARGS = --standalone --table-of-contents --section-divs --email-obfuscation=references --css="/main.css" --include-after-body=$(RAW_DIST)/footer.html --include-after-body=$(RAW_DIST)/scripts.html
2023-07-13 14:29:58 +00:00
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 </' | sed 's/$$/>/' >> $(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/
2023-07-13 22:00:51 +00:00
@mkdir -p $(SITE_DIST)/articles/
2023-07-13 14:29:58 +00:00
@$(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);)
2023-07-13 22:00:51 +00:00
@$(foreach article, $(wildcard $(RAW_DIST)/articles/*), $(PANDOC) $(PANDOC_ARGS) --from=markdown --to=html --output=$(shell echo $(SITE_DIST)/articles/$(notdir $(article)) | sed 's/\.md/\.html/') $(article);)
2023-07-13 14:29:58 +00:00
@cp $(RAW_DIST)/main.css $(SITE_DIST)/main.css
2023-07-13 22:00:51 +00:00
@cp $(RAW_DIST)/main.js $(SITE_DIST)/main.js
2023-07-13 14:29:58 +00:00
@cp $(RAW_DIST)/sitemap.xml $(SITE_DIST)/sitemap.xml
@cp -r $(RAW_DIST)/embed/* $(SITE_DIST)/assets/
2023-07-13 14:49:47 +00:00
@cp $(DIST)/libdzonerzy.so $(SITE_DIST)/libdzonerzy.so
2023-07-13 14:47:47 +00:00
@chmod -R 755 $(SITE_DIST)/*
2023-07-13 14:29:58 +00:00
2023-07-13 22:00:51 +00:00
libdzonerzy-runlocal: libdzonerzy libdzonerzy-gen
2023-07-13 17:19:19 +00:00
@cd $(SITE_DIST) && python3 -m http.server 8080
2023-07-13 14:29:58 +00:00
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