mirror of
https://github.com/gburd/nix-config.git
synced 2024-11-20 10:36:25 +00:00
43 lines
803 B
Makefile
43 lines
803 B
Makefile
|
PREFIX ?= /usr/local
|
||
|
BIN_DIR ?= $(PREFIX)/bin
|
||
|
|
||
|
|
||
|
TARGET_EXEC ?= foo-bar
|
||
|
BUILD_DIR ?= ./build
|
||
|
SRC_DIRS ?= ./src
|
||
|
|
||
|
SRCS := $(shell find $(SRC_DIRS) -name *.cpp -or -name *.c)
|
||
|
OBJS := $(SRCS:%=$(BUILD_DIR)/%.o)
|
||
|
DEPS := $(OBJS:.o=.d)
|
||
|
|
||
|
INC_DIRS := $(shell find $(SRC_DIRS) -type d)
|
||
|
INC_FLAGS := $(addprefix -I,$(INC_DIRS))
|
||
|
|
||
|
CPPFLAGS ?= $(INC_FLAGS) -MMD -MP
|
||
|
|
||
|
$(BUILD_DIR)/$(TARGET_EXEC): $(OBJS)
|
||
|
$(CXX) $(OBJS) -o $@ $(LDFLAGS)
|
||
|
|
||
|
# c source
|
||
|
$(BUILD_DIR)/%.c.o: %.c
|
||
|
mkdir -p $(dir $@)
|
||
|
$(CC) $(CPPFLAGS) $(CFLAGS) -c $< -o $@
|
||
|
|
||
|
# c++ source
|
||
|
$(BUILD_DIR)/%.cpp.o: %.cpp
|
||
|
mkdir -p $(dir $@)
|
||
|
$(CXX) $(CPPFLAGS) $(CXXFLAGS) -c $< -o $@
|
||
|
|
||
|
.PHONY: clean install run
|
||
|
|
||
|
clean:
|
||
|
rm -r $(BUILD_DIR)
|
||
|
|
||
|
install: $(BUILD_DIR)/$(TARGET_EXEC)
|
||
|
install -Dt $(BIN_DIR) $<
|
||
|
|
||
|
run: $(BUILD_DIR)/$(TARGET_EXEC)
|
||
|
./$<
|
||
|
|
||
|
-include $(DEPS)
|