blob: 1e3145e5dcb2c71aa728e1d58405eb187d62cb13 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
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)
|