diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..96d3670 --- /dev/null +++ b/.gitignore @@ -0,0 +1,5 @@ +/.vscode + +# Build files and final binary +/build +test \ No newline at end of file diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..6d924df --- /dev/null +++ b/Makefile @@ -0,0 +1,47 @@ +TARGET_EXEC := test +BUILD_DIR := ./build +SRC_DIRS := ./src + +# False targets +# (these are the only ones you manually run) +all: $(TARGET_EXEC) + +run: all + ./$(TARGET_EXEC) + +clean: + -rm -r $(BUILD_DIR) + @echo "" + +.PHONY: clean all run + +################################################# +# Flags and autodetection + +# -MMD and -MP generate makefiles with extension .d. +CPPFLAGS := -Wall -MMD -MP -I src +LDFLAGS := -l fftw3 + +# Find all cpp files in source dirs +SRCS := $(shell find $(SRC_DIRS) -name '*.cpp') +# Turns ./build/a.cpp into ./build/a.cpp.o +OBJS := $(SRCS:%=$(BUILD_DIR)/%.o) +# Turns ./build/a.cpp.o into ./build/a.cpp.d +DEPS := $(OBJS:.o=.d) + +################################################# +# Build targets + +# C++ build step +$(BUILD_DIR)/%.cpp.o: %.cpp + mkdir -p $(dir $@) + g++ $(CPPFLAGS) $(CXXFLAGS) -c $< -o $@ + + +# Final build step +$(TARGET_EXEC) : $(OBJS) + g++ $(OBJS) -o $@ $(LDFLAGS) + + +# Include generated makefiles +-include $(DEPS) \ No newline at end of file