CXX=g++
CXXFLAGS=-Wall -Wextra -std=c++17 -fno-elide-constructors
DEFS=#-DVERBOSE

.PHONY: all
all: bin/ecci.a bin/concat bin/median bin/words

.PHONY: asan
asan: CXXFLAGS += -fsanitize=address -fno-omit-frame-pointer
asan: all

# Link Concat app
bin/concat: build/concat/main.o bin/ecci.a | bin/.
	$(CXX) -g $(CXXFLAGS) $(DEFS) $^ -o $@

# Compile Concat app
build/concat/main.o: src/concat/main.cpp | build/concat/.
	$(CXX) -c -g $(CXXFLAGS) $(DEFS) -Isrc/ecci $< -o $@



# Link Median app
bin/median: build/median/median.o bin/ecci.a | bin/.
	$(CXX) -g $(CXXFLAGS) $(DEFS) $^ -o $@

# Compile Median app
build/median/median.o: src/median/median.cpp | build/median/.
	$(CXX) -c -g $(CXXFLAGS) $(DEFS) -Isrc/ecci $< -o $@


# Link Words app
bin/words: build/words/main.o bin/ecci.a | bin/.
	$(CXX) -g $(CXXFLAGS) $(DEFS) $^ -o $@

# Compile Words app
build/words/main.o: src/words/main.cpp | build/words/.
	$(CXX) -c -g $(CXXFLAGS) $(DEFS) -Isrc/ecci $< -o $@



# ECCI static library
bin/ecci.a: build/ecci/String.o | bin/.
	ar rs $@ $^

build/ecci/%.o: src/ecci/%.cpp src/ecci/%.hpp | build/ecci/.
	$(CXX) -c -g $(CXXFLAGS) $(DEFS) $< -o $@

.PRECIOUS: %/.
%/.:
	mkdir -p $@

.PHONY: clean
clean:
	rm -rf bin/ build/ doc/

.PHONY: lint
lint:
	cpplint --filter=-build/header_guard,-build/include_subdir,-build/c++11,-runtime/references src/concat/*.?pp src/ecci/*.?pp
