test.c/Makefile
2019-07-09 12:27:35 +02:00

43 lines
822 B
Makefile

CROSS_COMPILE ?=
TARGET_FILE ?= test
CC = $(CROSS_COMPILE)gcc
SRC_DIR = src
OBJ_DIR = obj
BIN_DIR = bin
C_FLAGS := -O0 -g -Iinc
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 $@
.PRECIOUS: $(OBJ_DIR)/%.d
$(OBJ_DIR)/%.d:
@mkdir -p $(OBJ_DIR)
$(CC) -MM -MF $@ -MP -MT $(patsubst %.d,%.o,$@) $(C_FLAGS) $(filter %$(patsubst %.d,%.c,$(notdir $@)),$(C_SRCS))
$(OBJ_DIR)/%.o: $(SRC_DIR)/%.c $(OBJ_DIR)/%.d
@mkdir -p $(OBJ_DIR)
$(CC) -c $(C_FLAGS) $< -o $@
.PHONY: clean
clean:
rm -rf $(OBJS) $(patsubst %.o,%.d,$(OBJS)) $(TARGET)
ifneq ($(MAKECMDGOALS),clean)
-include $(patsubst %.o,%.d,$(OBJS))
endif