QMKhost/Makefile

77 lines
1.4 KiB
Makefile
Raw Normal View History

2022-07-08 10:42:57 -07:00
TARGET_EXEC := hostdox
2022-06-24 19:58:10 -07:00
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-26 12:36:36 -07:00
CPPFLAGS := -MMD -MP \
-Wall \
-I src \
-I libs/hidapi/hidapi
# udev: required by hidapi
2022-06-25 19:12:01 -07:00
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')
2022-06-26 12:36:36 -07:00
# Turns src/a.cpp into build/src/a.cpp.o
SRC_OBJS := $(SRCS:%=$(BUILD_DIR)/%.o)
2022-06-25 19:12:01 -07:00
LIB_OBJS := $(BUILD_DIR)/hid.o
2022-06-26 12:36:36 -07:00
OBJS = $(SRC_OBJS) $(LIB_OBJS)
# Turns build/a.cpp.o into build/a.cpp.d
2022-06-24 19:58:10 -07:00
DEPS := $(OBJS:.o=.d)
#################################################
# Build targets
2022-06-26 12:36:36 -07:00
### Libraries
2022-06-25 19:12:01 -07:00
# Build hidapi
2022-06-26 12:36:36 -07:00
HIDAPI_PATH := libs/hidapi
2022-06-25 19:12:01 -07:00
$(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-26 12:36:36 -07:00
### Source
2022-06-24 19:58:10 -07:00
# C++ build step
2022-06-26 12:36:36 -07:00
$(BUILD_DIR)/%.cpp.o: %.cpp
2022-06-24 19:58:10 -07:00
mkdir -p $(dir $@)
g++ $(CPPFLAGS) $(CXXFLAGS) -c $< -o $@
# Final build step
$(TARGET_EXEC) : $(OBJS)
2022-06-26 12:36:36 -07:00
g++ $(OBJS) -o $@ $(LDFLAGS)
2022-06-25 19:12:01 -07:00
2022-06-24 19:58:10 -07:00
# Include generated makefiles
-include $(DEPS)