diff options
| author | David Moc <personal@cdatgoose.org> | 2026-11-19 02:10:24 +0100 |
|---|---|---|
| committer | David Moc <personal@cdatgoose.org> | 2026-11-19 02:10:24 +0100 |
| commit | 74111495622a13104b4f6500f6dc8e9db6aec9bd (patch) | |
| tree | 9695ff6f2abbb1d5f04bf9061d3ffafc248fb9f1 /Makefile | |
Hello World!
Diffstat (limited to 'Makefile')
| -rw-r--r-- | Makefile | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..1e3145e --- /dev/null +++ b/Makefile @@ -0,0 +1,55 @@ +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) |
