QMKhost/Makefile

65 lines
1.3 KiB
Makefile
Raw Normal View History

2022-06-24 19:58:10 -07:00
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 ""
2022-06-25 19:12:01 -07:00
libs: $(BUILD_DIR)/hid.o
.PHONY: clean all run libs
2022-06-24 19:58:10 -07:00
#################################################
# Flags and autodetection
# -MMD and -MP generate makefiles with extension .d.
2022-06-25 19:12:01 -07:00
CPPFLAGS := -Wall -MMD -MP -I src -I libs/hidapi/hidapi
LDFLAGS := -l fftw3 -l udev
2022-06-24 19:58:10 -07:00
# 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)
2022-06-25 19:12:01 -07:00
LIB_OBJS := $(BUILD_DIR)/hid.o
2022-06-24 19:58:10 -07:00
# Turns ./build/a.cpp.o into ./build/a.cpp.d
DEPS := $(OBJS:.o=.d)
#################################################
# Build targets
2022-06-25 19:12:01 -07:00
HIDAPI_PATH := libs/hidapi
# Build hidapi
$(BUILD_DIR)/hid.o:
@mkdir -p $(BUILD_DIR)
@echo "Compiling hid.o"
@gcc -Wall -g -fpic -c \
-I $(HIDAPI_PATH)/hidapi \
`pkg-config libusb-1.0 --cflags` \
\
$(HIDAPI_PATH)/linux/hid.c \
-o $(BUILD_DIR)/hid.o
2022-06-24 19:58:10 -07:00
# C++ build step
2022-06-25 19:12:01 -07:00
$(BUILD_DIR)/%.cpp.o: %.cpp $(BUILD_DIR)/hid.o
2022-06-24 19:58:10 -07:00
mkdir -p $(dir $@)
g++ $(CPPFLAGS) $(CXXFLAGS) -c $< -o $@
# Final build step
$(TARGET_EXEC) : $(OBJS)
2022-06-25 19:12:01 -07:00
g++ $(OBJS) $(LIB_OBJS) -o $@ $(LDFLAGS)
2022-06-24 19:58:10 -07:00
# Include generated makefiles
-include $(DEPS)