Newer
Older
Import / research / reflection / Makefile


TARGETS=\
	build/pipe-tests \
	build/hello \
	build/hello.bin \
	build/vm \
	build/asm \
	build/translator \
	build/test-results.txt \
	build/hello.output \
	build/hello.bin.output \
	build/csv_parser


all: .tags $(TARGETS)


# Unrelated code
build/csv_parser: source/csv_parser.cpp
	@g++ -g --std=c++11 -DTEST $< -o $@


build/hello: source/hello.c
	@mkdir -p build
	@gcc -Wl,-s -Xlinker -unexported_symbol -Xlinker "*" -Os source/hello.c -o build/hello

build/hello.bin: build/asm examples/hello.asm
	@mkdir -p build
	@touch build/hello.bin
	@rm build/hello.bin
	@build/asm examples/hello.asm build/hello.bin

build/asm: source/asm.cpp source/vm.hpp
	@mkdir -p build
	@g++ -std=c++11 -g -Os source/asm.cpp -o build/asm

build/vm: source/vm.cpp source/vm.hpp
	@mkdir -p build
	@# Standard release build options:
	@# g++ -std=c++11 -O3 source/vm.cpp -o build/vm ; strip build/vm
	@# This can reduce it another 1200 bytes:
	@g++ -fno-rtti -fno-exceptions -std=c++11 -O3 source/vm.cpp -o build/vm ; strip build/vm
	@# This can make it about another 500 bytes smaller:
	@# g++ -Wl,-s -Xlinker -unexported_symbol -Xlinker "*" -fno-rtti -fno-exceptions -std=c++11 -O3 source/vm.cpp -o build/vm
	@# This might be the smallest, but would require quite some work:
	@# -nostdlib

build/translator: source/translation.cpp
	@mkdir -p build
	@g++ -std=c++11 -g -Os source/translation.cpp -o build/translator

build/pipe-tests: examples/test.cpp
	@mkdir -p build
	@# Requires C++14, overall this has horrific build times, not exactly zero cost
	@g++ -std=c++14 -g -Os examples/test.cpp -o build/pipe-tests
	@strip build/pipe-tests

build/hello.output: build/hello
	@build/hello > build/hello.output
	@echo "hello world" > build/hello.bin.output
	@diff build/hello.output build/hello.bin.output

build/hello.bin.output: build/vm build/hello.bin
	@build/vm build/hello.bin > build/hello.bin.output
	@echo "hello world" > build/hello.output
	@diff build/hello.bin.output build/hello.output

build/test-results.txt: build/translator
	@for TEST in tests/test_*.txt ;\
	do \
		echo "============ $${TEST} ===================================" >> "$@" ;\
		./build/translator "$${TEST}" >> "$@" ;\
		if [ "$$?" != "0" ] ;\
		then \
			echo "============ FAIL $${TEST} ==============================" >> "$@" ;\
			echo "fail running test $${TEST}" ;\
		else \
			echo "============ PASS $${TEST} ==============================" >> "$@" ;\
			echo "pass running test $${TEST}" ;\
		fi \
	done ;\
	for TEST in tests/fail_*.txt ;\
	do \
		echo "============ $${TEST} ===================================" >> "$@" ;\
		./build/translator "$${TEST}" >> "$@" ;\
		if [ "$$?" == "0" ] ;\
		then \
			echo "============ FAIL $${TEST} ==============================" >> "$@" ;\
			echo "fail running test $${TEST}" ;\
		else \
			echo "============ PASS $${TEST} ==============================" >> "$@" ;\
 			echo "pass running test $${TEST}" ;\
		fi \
	done ;
	@# cat build/test-results.txt

test: build/translator
	@build/translator examples/example1.kai

clean:
	@rm -rf build .tags

.tags:
	@echo "Rebuilding tags"
	@# cscope -q -R -b source/*.cpp source/*.hpp
	@ctags -f $@ --tag-relative=yes --sort=yes --c++-kinds=+p --fields=+iaS --extras=+q source/*.cpp source/*.hpp

.PHONY: test clean