QMKhost/Makefile

86 lines
1.7 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 $(BUILD_DIR)/libmpdclient.o
2022-06-25 19:12:01 -07:00
.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 \
2022-07-08 19:36:05 -07:00
-I libs/hidapi/hidapi \
-I libs/spdlog/include \
-I libs/libmpdclient/include \
-I libs/libmpdclient/output
2022-06-26 12:36:36 -07:00
# udev: required by hidapi
# TODO: better hunspell link
LDFLAGS := -l fftw3 -l udev -l hunspell-1.7
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)
LIB_OBJS := $(BUILD_DIR)/hid.o $(BUILD_DIR)/libmpdclient.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
$(BUILD_DIR)/hid.o:
@mkdir -p $(BUILD_DIR)
@echo "Compiling hid.o"
@gcc -Wall -g -fpic -c \
-I libs/hidapi/hidapi \
2022-06-25 19:12:01 -07:00
`pkg-config libusb-1.0 --cflags` \
libs/hidapi/linux/hid.c \
2022-06-25 19:12:01 -07:00
-o $(BUILD_DIR)/hid.o
2022-06-26 12:36:36 -07:00
# Build libmpdclient
$(BUILD_DIR)/libmpdclient.o:
@cd libs/libmpdclient && \
meson . output && \
ninja -C output
ln -s ../libs/libmpdclient/output/libmpdclient.so $(BUILD_DIR)/libmpdclient.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)