OBJ:= main.o fs.o strhash.o hashtable.o
CC ?= clang

# OS dependend targets
OBJ += fs_linux.o
OUTPUT:= texdepends

.PHONY: test debug clean

all: debug
test: ctests debug
	./$(OUTPUT) test.tex

ctests: test_path test_hashtable
	$(foreach exe,$^,./$(exe);)

.INTERMEDIATE: test_path tests.o test_path.o

test_path: test_path.o fs.o fs_linux.o tests.o
	$(CC) $^ -o test_path
test_path.c: fs.o tests.o 

test_hashtable: test_hashtable.o strhash.o tests.o hashtable.o
	$(CC) $^ -o test_hashtable

test_hashtable.c: hashtable.h
	
debug: CXXFLAGS += -g -std=c++11
debug: CFLAGS += -g
debug: $(OUTPUT)

clean:
	$(RM) $(OBJ) $(OUTPUT)

fs.c: fs_linux.o
main.c: fs.o strhash.o hashtable.o

$(OUTPUT): main.o
	$(CXX) $(OBJ) -o $(OUTPUT)