
program_name=sau
test_name=sau_test

cc=g++
cflag=-Wall -std=c++0x
#cflag=-Wall -std=c++0x -pg -rdynamic

inc_path=./
src_path=./
bin_path=../bin/

incs=-I$(inc_path)
clib=

test_lib=-static -lboost_unit_test_framework

# object files
objects=
# ls *.cpp */*.cpp | grep -v "test" | sed 's/.cpp/.o/g' | sed 's/^/objects+=/'
# Searched Object File Candidates
objects=
objects+=code_data_editor.o
objects+=code_data_loader.o
objects+=code_data_parser.o
objects+=display_module.o
objects+=instruction.o
objects+=main.o
objects+=opcode_helper.o
objects+=origin_scanner.o
objects+=reference.o
objects+=state_machine.o
objects+=utils/number_format.o
objects+=utils/stream_filter.o
test_objects=
test_objects+=all_test.o
test_objects+=code_data_editor.o
test_objects+=code_data_loader.o
test_objects+=code_data_parser.o
test_objects+=display_module.o
test_objects+=graph_test.o
test_objects+=instruction.o
test_objects+=opcode_helper.o
test_objects+=origin_scanner.o
test_objects+=reference.o
test_objects+=state_machine.o
test_objects+=utils/filter_stream_test.o
test_objects+=utils/hex_form_test.o
test_objects+=utils/number_format.o
test_objects+=utils/stream_filter.o
default: test build;

$(bin_path):
	mkdir $@
	mkdir $@/utils
	mkdir $@/filter

test: $(bin_path) $(bin_path)$(test_name)
	-cd $(bin_path) && $(test_name)

build: $(bin_path) $(bin_path)$(program_name)

$(bin_path)$(test_name): $(test_objects:%=$(bin_path)%)
	$(cc) $(cflag) $(incs) $(libs) -o $@ $^ $(test_lib)

$(bin_path)$(program_name): $(objects:%=$(bin_path)%)
	$(cc) $(cflag) $(incs) $(libs) -o $@ $^ $(clib)


$(bin_path)%.o: $(src_path)%.cpp
	$(cc) $(cflag) $(incs) -o $@ -c $< $(clib)
clean:
	rm -r $(bin_path)/*.o


# Searched Dependencies
$(bin_path)all_test.o: all_test.cpp
$(bin_path)code_data_editor.o: code_data_editor.cpp front_end.hpp basic_type.hpp \
 utils/file_path.hpp reference.hpp graph.hpp instruction.hpp opcode.hpp \
 code_data_parser.hpp utils/hex_form.hpp utils/string_aligner.hpp \
 utils/string_repeat.hpp nes_memory_map.hpp nes_memory_mapper.hpp \
 ines_file.hpp ines_header.hpp utils/number_format.hpp \
 utils/stream_measure.hpp utils/binary_dump.hpp \
 utils/character_graphic.hpp utils/stream_filter.hpp debug_macro.hpp \
 state_machine.hpp display_module.hpp
$(bin_path)code_data_loader.o: code_data_loader.cpp front_end.hpp basic_type.hpp \
 utils/file_path.hpp reference.hpp graph.hpp instruction.hpp opcode.hpp
$(bin_path)code_data_parser.o: code_data_parser.cpp front_end.hpp basic_type.hpp \
 utils/file_path.hpp reference.hpp graph.hpp instruction.hpp opcode.hpp \
 state_machine.hpp nes_memory_map.hpp nes_memory_mapper.hpp ines_file.hpp \
 ines_header.hpp utils/number_format.hpp utils/stream_measure.hpp \
 utils/binary_dump.hpp utils/character_graphic.hpp \
 utils/stream_filter.hpp utils/string_aligner.hpp utils/string_repeat.hpp \
 debug_macro.hpp utils/hex_form.hpp code_data_parser.hpp
$(bin_path)display_module.o: display_module.cpp display_module.hpp basic_type.hpp \
 reference.hpp graph.hpp instruction.hpp opcode.hpp nes_memory_mapper.hpp \
 ines_file.hpp ines_header.hpp utils/number_format.hpp \
 utils/stream_measure.hpp utils/file_path.hpp utils/binary_dump.hpp \
 utils/character_graphic.hpp utils/stream_filter.hpp \
 utils/string_aligner.hpp utils/string_repeat.hpp debug_macro.hpp \
 nes_memory_map.hpp disassembler.hpp utils/hex_form.hpp code_server.hpp \
 code_data_parser.hpp state_machine.hpp
$(bin_path)graph_test.o: graph_test.cpp graph.hpp debug_macro.hpp
$(bin_path)instruction.o: instruction.cpp instruction.hpp basic_type.hpp opcode.hpp \
 disassembler.hpp utils/hex_form.hpp utils/string_aligner.hpp \
 utils/string_repeat.hpp ines_file.hpp ines_header.hpp \
 utils/number_format.hpp utils/stream_measure.hpp utils/file_path.hpp \
 utils/binary_dump.hpp utils/character_graphic.hpp \
 utils/stream_filter.hpp debug_macro.hpp nes_memory_map.hpp \
 code_server.hpp reference.hpp graph.hpp
$(bin_path)main.o: main.cpp utils/option_parser.hpp utils/word_stream.hpp \
 utils/file_path.hpp utils/number_format.hpp basic_type.hpp ines_file.hpp \
 ines_header.hpp utils/stream_measure.hpp utils/binary_dump.hpp \
 utils/character_graphic.hpp utils/stream_filter.hpp \
 utils/string_aligner.hpp utils/string_repeat.hpp debug_macro.hpp \
 nes_memory_map.hpp nes_memory_mapper.hpp instruction.hpp opcode.hpp \
 reference.hpp graph.hpp utils/hex_form.hpp front_end.hpp \
 display_module.hpp
$(bin_path)opcode_helper.o: opcode_helper.cpp opcode.hpp basic_type.hpp
$(bin_path)origin_scanner.o: origin_scanner.cpp front_end.hpp basic_type.hpp \
 utils/file_path.hpp reference.hpp graph.hpp instruction.hpp opcode.hpp \
 ines_file.hpp ines_header.hpp utils/number_format.hpp \
 utils/stream_measure.hpp utils/binary_dump.hpp \
 utils/character_graphic.hpp utils/stream_filter.hpp \
 utils/string_aligner.hpp utils/string_repeat.hpp debug_macro.hpp \
 nes_memory_map.hpp
$(bin_path)reference.o: reference.cpp reference.hpp basic_type.hpp graph.hpp \
 instruction.hpp opcode.hpp
$(bin_path)state_machine.o: state_machine.cpp state_machine.hpp basic_type.hpp \
 nes_memory_map.hpp instruction.hpp opcode.hpp nes_memory_mapper.hpp \
 ines_file.hpp ines_header.hpp utils/number_format.hpp \
 utils/stream_measure.hpp utils/file_path.hpp utils/binary_dump.hpp \
 utils/character_graphic.hpp utils/stream_filter.hpp \
 utils/string_aligner.hpp utils/string_repeat.hpp debug_macro.hpp \
 utils/hex_form.hpp
