CC ?= cc # Path to your CCDJIT checkout (needs bin/libccdjit.a built already) CCDJIT ?= $(HOME)/opt/ccdjit CFLAGS ?= -Wall -Wextra -O2 CPPFLAGS += -I$(CCDJIT)/src -MMD -MP LDFLAGS += -rdynamic LDLIBS += $(CCDJIT)/bin/libccdjit.a # Test cases for `make check`, see README SAMPLES ?= samples.txt TARGET := qiuyu SRC := main.c OBJ := $(SRC:.c=.o) DEP := $(OBJ:.o=.d) .PHONY: all check clean all: $(TARGET) $(TARGET): $(OBJ) $(CC) $(LDFLAGS) $^ $(LDLIBS) -o $@ %.o: %.c $(CC) $(CPPFLAGS) $(CFLAGS) -c $< -o $@ # Encrypts every line of $(SAMPLES), compares with the expected ciphertext # if given, then decrypts and compares with the original. check: $(TARGET) @fail=0; ok=0; \ while IFS='|' read -r lang plain cipher; do \ case "$$lang" in ''|'#'*) continue ;; esac; \ enc=$$(./$(TARGET) -l "$$lang" -e "$$plain") || { echo "FAIL $$lang: encrypt '$$plain'"; fail=$$((fail+1)); continue; }; \ if [ -n "$$cipher" ] && [ "$$enc" != "$$cipher" ]; then \ echo "FAIL $$lang: '$$plain' encrypted to '$$enc', expected '$$cipher'"; fail=$$((fail+1)); continue; \ fi; \ dec=$$(./$(TARGET) -l "$$lang" -d "$$enc") || { echo "FAIL $$lang: decrypt '$$enc'"; fail=$$((fail+1)); continue; }; \ if [ "$$dec" != "$$plain" ]; then \ echo "FAIL $$lang: '$$plain' -> '$$enc' -> '$$dec'"; fail=$$((fail+1)); continue; \ fi; \ ok=$$((ok+1)); \ done < $(SAMPLES); \ for f in langs/*.c; do \ name=$$(basename $$f .c); \ grep -q "^$$name|" $(SAMPLES) || echo "WARN $$name: no samples in $(SAMPLES)"; \ done; \ echo "$$ok passed, $$fail failed"; \ [ $$fail -eq 0 ] clean: rm -f $(TARGET) $(OBJ) $(DEP) -include $(DEP)