63 lines
1.3 KiB
Makefile
63 lines
1.3 KiB
Makefile
CROSS_COMPILE ?=
|
|
|
|
TARGET_FILE ?= test
|
|
|
|
CC = $(CROSS_COMPILE)gcc
|
|
CPP = $(CROSS_COMPILE)cpp
|
|
|
|
SRC_DIR = src
|
|
OBJ_DIR = obj
|
|
BIN_DIR = bin
|
|
|
|
INCLUDES := inc
|
|
|
|
#Alpine Linux ftdi include path
|
|
INCLUDES += /usr/include/libftdi1
|
|
|
|
DISTRO=$(head -1 /etc/issue)
|
|
ifeq "$(findstring Alpine,$(DISTRO))" ""
|
|
LIBS := ftdi
|
|
else
|
|
LIBS := ftdi1
|
|
endif
|
|
|
|
LD_FLAGS :=
|
|
C_FLAGS := -O0 -g
|
|
CPP_FLAGS := $(addprefix -I, $(INCLUDES))
|
|
|
|
C_SRCS = $(wildcard $(SRC_DIR)/*.c)
|
|
C_OBJS = $(patsubst $(SRC_DIR)%,$(OBJ_DIR)%,$(patsubst %.c,%.o,$(C_SRCS)))
|
|
|
|
OBJS = $(C_OBJS)
|
|
|
|
TARGET = $(BIN_DIR)/$(TARGET_FILE)
|
|
THIS_MAKEFILE := $(lastword $(MAKEFILE_LIST))
|
|
|
|
.PHONY: all
|
|
all: $(TARGET)
|
|
|
|
$(TARGET): $(OBJS) $(THIS_MAKEFILE)
|
|
head -1 /etc/issue
|
|
echo "$(LIBS)"
|
|
echo "$(DISTRO)"
|
|
echo "$(findstring Alpine,$(DISTRO))"
|
|
@mkdir -p $(BIN_DIR)
|
|
$(CC) $(C_FLAGS) $(LD_FLAGS) $(OBJS) $(addprefix -l,$(LIBS)) -o $@
|
|
|
|
.PRECIOUS: $(OBJ_DIR)/%.d
|
|
$(OBJ_DIR)/%.d: $(SRC_DIR)/%.c
|
|
@mkdir -p $(OBJ_DIR)
|
|
$(CPP) -MM -MF $@ -MP -MT $(patsubst %.d,%.o,$@) $(CPP_FLAGS) $(patsubst $(OBJ_DIR)/%.d,$(SRC_DIR)/%.c,$@)
|
|
|
|
$(OBJ_DIR)/%.o: $(SRC_DIR)/%.c $(OBJ_DIR)/%.d
|
|
@mkdir -p $(OBJ_DIR)
|
|
$(CC) -c $(CPP_FLAGS) $(C_FLAGS) $< -o $@
|
|
|
|
.PHONY: clean
|
|
clean:
|
|
rm -rf $(OBJS) $(patsubst %.o,%.d,$(OBJS)) $(TARGET)
|
|
|
|
ifneq ($(MAKECMDGOALS),clean)
|
|
-include $(patsubst %.o,%.d,$(OBJS))
|
|
endif
|