github.com/DQNEO/babygo@v0.0.3/Makefile (about) 1 # Run this on Linux 2 tmp = /tmp/bbg 3 4 .PHONY: all 5 all: test 6 7 # test all 8 .PHONY: test 9 test: $(tmp) test0 test1 selfhost compare-test 10 11 $(tmp): 12 mkdir -p $(tmp) 13 14 t/expected.txt: t/*.go lib/*/* 15 export FOO=bar; go run t/*.go myargs > t/expected.txt 16 17 $(tmp)/pre: pre/*.go lib/*/* $(tmp) 18 go build -o $@ ./pre 19 20 $(tmp)/bbg: *.go lib/*/* src/*/* $(tmp) 21 go build -o $@ ./ 22 23 $(tmp)/pre-bbg: $(tmp)/pre *.go src/*/* 24 ./compile $< $(@).s *.go 25 ./assemble_and_link $(@).s $@ $(tmp) 26 27 $(tmp)/bbg-bbg: $(tmp)/bbg src/*/* 28 ./compile $< $(@).s *.go 29 ./assemble_and_link $(@).s $@ $(tmp) 30 31 $(tmp)/pre-test.s: $(tmp)/pre t/*.go src/*/* 32 ./compile $< $(@) t/*.go 33 34 $(tmp)/pre-bbg-test.s: $(tmp)/pre-bbg t/*.go 35 ./compile $< $(@) t/*.go 36 37 $(tmp)/bbg-test.s: $(tmp)/bbg t/*.go 38 ./compile $< $(@) t/*.go 39 40 $(tmp)/bbg-bbg-test.s: $(tmp)/bbg-bbg t/*.go 41 ./compile $< $(@) t/*.go 42 43 # compare output of test0 and test1 44 .PHONY: compare-test 45 compare-test: $(tmp)/pre-test.s $(tmp)/bbg-test.s $(tmp)/bbg-bbg-test.s $(tmp)/pre-bbg-test.s 46 diff -u $(tmp)/pre-test.s $(tmp)/bbg-test.s 47 diff -u $(tmp)/bbg-test.s $(tmp)/pre-bbg-test.s 48 diff -u $(tmp)/bbg-test.s $(tmp)/bbg-bbg-test.s 49 50 .PHONY: test0 51 test0: $(tmp)/pre-test t/expected.txt 52 ./test.sh $< 53 54 .PHONY: test1 55 test1: $(tmp)/bbg-test t/expected.txt 56 ./test.sh $< 57 58 $(tmp)/pre-test: $(tmp)/pre-test.s 59 ./assemble_and_link $< $@ $(tmp) 60 61 $(tmp)/bbg-test: $(tmp)/bbg-test.s 62 ./assemble_and_link $< $@ $(tmp) 63 64 # test self hosting by comparing 2gen.s and 3gen.s 65 .PHONY: selfhost 66 selfhost: $(tmp)/bbg-bbg 67 @echo "testing self host ..." 68 ./compile $< $(tmp)/bbg-bbg-bbg.s *.go 69 70 diff $(tmp)/bbg-bbg.s $(tmp)/bbg-bbg-bbg.s 71 @echo "self host is ok" 72 73 .PHONY: fmt 74 fmt: 75 gofmt -w *.go t/*.go pre/*.go src/*/*.go lib/*/*.go 76 77 .PHONY: clean 78 clean: 79 rm -f ./tmp/* ./.shared/* 80 rm -fr $(tmp) 81 82 # to learn the official Go's assembly 83 .PHONY: example 84 example: 85 make example/example.s example/min.s 86 87 example/example.s: example 88 # -N: disable optimizations, -S: print assembly listing -l: no inline 89 go tool compile -N -S -l example/example.go > example/example.s 90 91 example/min.s: example 92 go tool compile -N -S -l example/min.go > example/min.s