# This makefile is getting ugly... we should probably just use ghc --make .PRECIOUS: %.pdf GHC = ghc GHCFLAGS = -Wall -Werror -cpp -odir build -hidir build -ibuild \ -fno-warn-unused-imports -fno-warn-name-shadowing ifdef OPTIMIZE GHCFLAGS += -O2 endif apps = SimpleCiphers RSA miniapps = RunTests HW4 docs = SimpleCiphers.pdf RSA.pdf HW4.pdf HW5.pdf lib_sources = $(shell find src/Brianweb -name '*.lhs') app_sources = $(shell find src ! -path 'src/Brianweb/*' -name '*.lhs') libs = $(lib_sources:src/%.lhs=build/%.o) sources = $(lib_sources) $(app_sources) all: $(apps) $(miniapps) doc: $(docs) $(apps): %: build/%Main.o build/%.o $(libs) @mkdir -p "$@D" $(GHC) $(GHCFLAGS) -o $@ $^ $(miniapps): %: build/%.o $(libs) @mkdir -p "$@D" $(GHC) $(GHCFLAGS) -o $@ $^ $(miniapps:%=build/%.o) $(apps:%=build/%Main.o): build/%.o: src/%.lhs @mkdir -p "$@D" $(GHC) $(GHCFLAGS) -main-is $* -c -o $@ $< build/%.o: src/%.lhs @mkdir -p "$@D" $(GHC) $(GHCFLAGS) -c -o $@ $< build/%.hi: build/%.o; @true %.pdf: $(sources) TEXINPUTS="src:"; export TEXINPUTS; pdflatex $*.lhs && pdflatex $*.lhs rm -f "$*.log" "$*.aux" .depend: $(sources) @echo Rebuilding dependencies... @$(GHC) $(GHCFLAGS) -isrc -M -optdep-f -optdep$@ $^ pdf: pdf_RSA pdf_%: %.pdf @if [ "`uname -s`" = "Darwin" ]; then open $^; \ else xpdf $^; \ fi test: testsc testrsa testmath; @true testmath: RunTests; @true; ./RunTests testrsa: RSA @for x in 1 2 3 4 5 6 7 8 9 10; do \ echo "Generating key..."; \ ./RSA genkey 64 | awk '{ print $$2}' | ( \ read p; \ read q; \ read pq; \ read e; \ read d; \ echo "--> pq: $$pq e: $$e d: $$d"; \ for m in \ 69 420 1337 31337 31337111 900000000 \ `od -t 'u4' -N 128 /dev/random |awk '{$$1=""; print;}'`; \ do \ c=`./RSA encrypt $$pq $$e $$m`; \ p=`./RSA decrypt $$pq $$d $$c`; \ if [ "$$p" = "$$m" ]; then \ echo "($$m) $$c -> $$p, OK!"; \ else \ echo "($$m) $$c -> $$p, NOT OK!"; \ exit 1; \ fi; \ done; \ ) || exit 1; \ done testsc: SimpleCiphers @while read cipher op key i o; do \ x="`echo "$$i"|./SimpleCiphers $$cipher $$op \"$$key\"`"; \ if [ "$$x" = "$$o" ]; then \ echo "$$cipher $$i -> $$o, OK!"; \ else \ echo "$$cipher $$i -> $$x, NOT OK!"; \ exit 1; \ fi \ done < tests.txt @while read cipher lang ct pt n; do \ echo "$$ct" > .tmp; \ FILTER="`printf \"/^Possible decryption #$$n, key: \\\\\\(.*\\\\\\)/{\nn\np\nq\n}\"`"; \ x="`yes n | ./SimpleCiphers $$cipher break $$lang .tmp | sed -n \"$$FILTER\"`"; \ if [ "$$x" = "$$pt" ]; then \ echo "$$cipher: `echo $$ct | head -c 20`... -> `echo $$pt | head -c 50`..., OK!"; \ else \ echo "$$cipher: $$ct -> $$x, NOT OK!"; \ exit 1; \ fi; \ done < test.break.txt @while read cipher lang ct pt n key; do \ echo "$$ct" > .tmp.ct; \ echo "$$pt" > .tmp.pt; \ FILTER="`printf \"/^Possible decryption #$$n, key: \\\\\\(.*\\\\\\)/{\ns/.*key: //\np\nq\n}\"`"; \ x="`yes n | ./SimpleCiphers $$cipher pbreak $$lang .tmp.pt .tmp.ct | sed -n \"$$FILTER\"`"; \ if [ "$$x" = "$$key" ]; then \ echo "$$cipher: `echo $$ct | head -c 20`/`echo $$pt | head -c 20` -> $$key, OK!"; \ else \ echo "$$cipher: $$ct, $$pt -> $$x, NOT OK!"; \ exit 1; \ fi \ done < test.pbreak.txt @rm -f .tmp .tmp.ct .tmp.pt clean: rm -rf $(docs) build/* push: $(docs) darcs push charger.brianweb.net:/home/darcs/ritcrypto scp $(docs) charger.brianweb.net:/home/darcs/ritcrypto include .depend