From a447b5f8c8f07afbacc693e62d2463e2bf619119 Mon Sep 17 00:00:00 2001 From: Mark Date: Sun, 26 Jun 2022 12:36:36 -0700 Subject: [PATCH] Cleaned up makefile --- Makefile | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/Makefile b/Makefile index 41b2856..4c0da6a 100644 --- a/Makefile +++ b/Makefile @@ -22,22 +22,31 @@ libs: $(BUILD_DIR)/hid.o # Flags and autodetection # -MMD and -MP generate makefiles with extension .d. -CPPFLAGS := -Wall -MMD -MP -I src -I libs/hidapi/hidapi +CPPFLAGS := -MMD -MP \ + -Wall \ + -I src \ + -I libs/hidapi/hidapi + +# udev: required by hidapi LDFLAGS := -l fftw3 -l udev # 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 src/a.cpp into build/src/a.cpp.o +SRC_OBJS := $(SRCS:%=$(BUILD_DIR)/%.o) LIB_OBJS := $(BUILD_DIR)/hid.o -# Turns ./build/a.cpp.o into ./build/a.cpp.d +OBJS = $(SRC_OBJS) $(LIB_OBJS) +# Turns build/a.cpp.o into build/a.cpp.d DEPS := $(OBJS:.o=.d) ################################################# # Build targets -HIDAPI_PATH := libs/hidapi + +### Libraries + # Build hidapi +HIDAPI_PATH := libs/hidapi $(BUILD_DIR)/hid.o: @mkdir -p $(BUILD_DIR) @@ -49,15 +58,18 @@ $(BUILD_DIR)/hid.o: $(HIDAPI_PATH)/linux/hid.c \ -o $(BUILD_DIR)/hid.o + +### Source + # C++ build step -$(BUILD_DIR)/%.cpp.o: %.cpp $(BUILD_DIR)/hid.o +$(BUILD_DIR)/%.cpp.o: %.cpp mkdir -p $(dir $@) g++ $(CPPFLAGS) $(CXXFLAGS) -c $< -o $@ # Final build step $(TARGET_EXEC) : $(OBJS) - g++ $(OBJS) $(LIB_OBJS) -o $@ $(LDFLAGS) + g++ $(OBJS) -o $@ $(LDFLAGS)