libdzonerzy.so/src/Makefile

74 lines
3.8 KiB
Makefile
Raw Permalink 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
2023-10-20 20:17:40 +00:00
CONVERT_TOOL = $(shell which convert)
CONVERT_ARGS = -define webp
:lossless=false -define webp:alpha-compression=1 -define webp:alpha-quality=70 -define webp:emulate-jpeg-size=true -o
2023-07-13 14:29:58 +00:00
DIST = dist
SRC_DIR = src
RES_DIR = res
2023-07-13 14:29:58 +00:00
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
PYTHON = $(shell which python3)
2023-07-13 14:29:58 +00:00
libdzonerzy:
# first create the index.md page
$(PYTHON) tools/index_gen/indexgen.py --resources $(RES_DIR) --blog-title="DZONERZY's Blog" --blog-author="DZONERZY"
2023-07-13 14:29:58 +00:00
@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_DIR)/assets/*.jpg $(RES_DIR)/assets/*.gif $(RES_DIR)/assets/*.png), $(CONVERT_TOOL) $(file) $(CONVERT_ARGS) $(file).webp;)
@$(foreach file, $(wildcard $(RES_DIR)/assets/*.jpg $(RES_DIR)/assets/*.gif $(RES_DIR)/assets/*.png), $(EMBED_TOOL) -i $(file).webp -o $(SRC_INC_DIR)/$(notdir $(file).webp).h $(EMBED_ARGS);)
@$(foreach file, $(wildcard res/advisory/*.txt), $(EMBED_TOOL) -i $(file) -t=a -o $(SRC_INC_DIR)/$(notdir $(file)).h $(EMBED_ARGS);)
@$(foreach file, $(wildcard res/pages/*.md), $(EMBED_TOOL) -i $(file) -t=p -o $(SRC_INC_DIR)/$(notdir $(file)).h $(EMBED_ARGS);)
@$(foreach file, $(wildcard res/articles/*.md), $(EMBED_TOOL) -i $(file) -t=A -o $(SRC_INC_DIR)/$(notdir $(file)).h $(EMBED_ARGS);)
@rm -f res/assets/*.webp
2023-07-13 14:29:58 +00:00
@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:
2023-10-21 17:48:18 +00:00
$(READELF) -S -W $(DIST)/$(OUTPUT) | $(AWK_UTIL) | xargs dirname {} | sort | uniq | xargs -I{} mkdir -p $(RAW_DIST)/{}
2023-07-13 14:29:58 +00:00
@$(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-10-21 17:48:18 +00:00
@mkdir -p $(SITE_DIST)/advisory/
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-10-21 17:48:18 +00:00
@$(foreach advisory, $(wildcard $(RAW_DIST)/advisory/*), cp $(advisory) $(SITE_DIST)/advisory/$(notdir $(advisory));)
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