test.c/Makefile

40 lines
699 B
Makefile
Raw Normal View History

2019-06-29 09:29:51 +00:00
CROSS_COMPILE ?=
TARGET_FILE ?= dnssd
CC = $(CROSS_COMPILE)gcc
SRC_DIR = src
OBJ_DIR = obj
BIN_DIR = bin
C_SRCS = $(wildcard $(SRC_DIR)/*.c)
C_OBJS = $(patsubst %.c,$(OBJ_DIR)/%.o,$(notdir $(C_SRCS)))
OBJS = $(C_OBJS)
TARGET = $(BIN_DIR)/$(TARGET_FILE)
.PHONY: all
all: $(TARGET)
$(TARGET): $(OBJS)
@mkdir -p $(BIN_DIR)
$(CC) $(LD_FLAGS) $(OBJS) $(LIBS) -o $@
$(OBJ_DIR)/%.o: $(SRC_DIR)/%.c
@mkdir -p $(OBJ_DIR)
$(call makedep,$<,$@,$(patsubst %c,%d,$(OBJ_DIR)/$(notdir $<)))
$(CC) -c $(C_FLAGS) $< -o $@
.PHONY: clean
clean:
rm -rf $(OBJ_DIR) $(BIN_DIR)
define makedep
$(CC) -MM -MF $3 -MP -MT $2 $4 $1
endef
ifneq ($(MAKECMDGOALS),clean)
-include $($(subst .o,.d,$(OBJS)))
endif