### quick Makefile to build ke in the top-level. It will never be used
### kge; ke doesn't use any non-system libraries. vim, emacs, and joe
### all support building from a Makefile in the root directory of the
### project, so it's useful to quickly test builds when editing remote.
CC :=		clang
CXX := 		clang++
CXXFLAGS :=	-Werror -Wall -Wextra -g -fsanitize=address -std=c++17
LDFLAGS :=	

SOURCES :=	Buffer.cc	Buffer.h		\
		Cursor.cc	Cursor.h		\
		Defs.cc		Defs.h			\
		File.cc		File.h			\
		main.cc
OBJS := 	$(patsubst %.cc,%.o,$(filter %.cc,$(SOURCES)))
TARGET :=	ke

.PHONY: all
all: tags trashme $(TARGET) 
	./$(TARGET) trashme.txt

.PHONY: trashme
trashme:
	cp Makefile trashme.txt

.PHONY: cmake
cmake: build
	cd build && cmake --config Debug --build ..

build:
	mkdir -p build
	
# TODO: run these from ./scripts/install-dependencies.sh
PHONY: deps
deps:
	sudo apt-get install doxygen scdoc

.PHONY: gui-deps
gui-deps:
	sudo apt-get install libfreetype-dev libsdl2-dev libopengl-dev libglfw3-dev

.PHONY:
clean:
	rm -f *.o $(TARGET)

tags: $(SOURCES)
	ctags --declarations -o $@ $(SOURCES)

ke: $(OBJS)
	$(CXX) -o $@ $(CXXFLAGS) $(LDFLAGS) $(OBJS)


.PHONY: cclean
cclean:
	rm -r build cmake-build-*

print-%: ; @echo '$(subst ','\'',$*=$($*))'

%.o:%.cc
	$(CXX) -c -o $@ $(CXXFLAGS) $<
