gpio_ftdi/Makefile

57 lines
1.2 KiB
Makefile
Raw Normal View History

2019-06-29 09:29:51 +00:00
CROSS_COMPILE ?=
2019-07-09 10:27:35 +00:00
TARGET_FILE ?= test
2019-06-29 09:29:51 +00:00
CC = $(CROSS_COMPILE)gcc
2019-07-13 10:45:42 +00:00
CPP = $(CROSS_COMPILE)cpp
2019-06-29 09:29:51 +00:00
SRC_DIR = src
OBJ_DIR = obj
BIN_DIR = bin
2019-07-13 10:45:42 +00:00
INCLUDES := inc
#Alpine Linux names libftdi libftdi1
ifneq "$(findstring Alpine,$(shell head -1 /etc/issue))" ""
2019-07-13 17:17:18 +00:00
INCLUDES += /usr/include/libftdi1
LIBS := ftdi1
else
2019-07-13 17:17:18 +00:00
LIBS := ftdi
endif
2019-07-13 17:17:18 +00:00
LD_FLAGS :=
2019-07-13 10:45:42 +00:00
C_FLAGS := -O0 -g
CPP_FLAGS := $(addprefix -I, $(INCLUDES))
2019-07-09 10:27:35 +00:00
2019-06-29 09:29:51 +00:00
C_SRCS = $(wildcard $(SRC_DIR)/*.c)
2019-07-13 10:45:42 +00:00
C_OBJS = $(patsubst $(SRC_DIR)%,$(OBJ_DIR)%,$(patsubst %.c,%.o,$(C_SRCS)))
2019-06-29 09:29:51 +00:00
OBJS = $(C_OBJS)
TARGET = $(BIN_DIR)/$(TARGET_FILE)
2019-07-13 10:45:42 +00:00
THIS_MAKEFILE := $(lastword $(MAKEFILE_LIST))
2019-06-29 09:29:51 +00:00
.PHONY: all
all: $(TARGET)
2019-07-13 10:45:42 +00:00
$(TARGET): $(OBJS) $(THIS_MAKEFILE)
2019-06-29 09:29:51 +00:00
@mkdir -p $(BIN_DIR)
2019-07-13 17:17:18 +00:00
$(CC) $(C_FLAGS) $(LD_FLAGS) $(OBJS) $(addprefix -l,$(LIBS)) -o $@
2019-06-29 09:29:51 +00:00
2019-07-09 10:27:35 +00:00
.PRECIOUS: $(OBJ_DIR)/%.d
2019-07-13 10:45:42 +00:00
$(OBJ_DIR)/%.d: $(SRC_DIR)/%.c
2019-07-09 10:27:35 +00:00
@mkdir -p $(OBJ_DIR)
2019-07-13 10:45:42 +00:00
$(CPP) -MM -MF $@ -MP -MT $(patsubst %.d,%.o,$@) $(CPP_FLAGS) $(patsubst $(OBJ_DIR)/%.d,$(SRC_DIR)/%.c,$@)
2019-07-09 10:27:35 +00:00
$(OBJ_DIR)/%.o: $(SRC_DIR)/%.c $(OBJ_DIR)/%.d
2019-06-29 09:29:51 +00:00
@mkdir -p $(OBJ_DIR)
2019-07-13 10:45:42 +00:00
$(CC) -c $(CPP_FLAGS) $(C_FLAGS) $< -o $@
2019-06-29 09:29:51 +00:00
.PHONY: clean
clean:
2019-07-09 10:27:35 +00:00
rm -rf $(OBJS) $(patsubst %.o,%.d,$(OBJS)) $(TARGET)
2019-06-29 09:29:51 +00:00
ifneq ($(MAKECMDGOALS),clean)
2019-07-09 10:27:35 +00:00
-include $(patsubst %.o,%.d,$(OBJS))
endif