From f752aece31691bdf05acbbef8f206e90d1cecb80 Mon Sep 17 00:00:00 2001 From: Thomas Klaehn Date: Sat, 13 Jul 2019 12:45:42 +0200 Subject: [PATCH] build process improved --- Makefile | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/Makefile b/Makefile index 766f77c..48e6595 100644 --- a/Makefile +++ b/Makefile @@ -3,35 +3,40 @@ CROSS_COMPILE ?= TARGET_FILE ?= test CC = $(CROSS_COMPILE)gcc +CPP = $(CROSS_COMPILE)cpp SRC_DIR = src OBJ_DIR = obj BIN_DIR = bin -C_FLAGS := -O0 -g -Iinc +INCLUDES := inc + +C_FLAGS := -O0 -g +CPP_FLAGS := $(addprefix -I, $(INCLUDES)) C_SRCS = $(wildcard $(SRC_DIR)/*.c) -C_OBJS = $(patsubst %.c,$(OBJ_DIR)/%.o,$(notdir $(C_SRCS))) +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) +$(TARGET): $(OBJS) $(THIS_MAKEFILE) @mkdir -p $(BIN_DIR) $(CC) $(LD_FLAGS) $(OBJS) $(LIBS) -o $@ .PRECIOUS: $(OBJ_DIR)/%.d -$(OBJ_DIR)/%.d: +$(OBJ_DIR)/%.d: $(SRC_DIR)/%.c @mkdir -p $(OBJ_DIR) - $(CC) -MM -MF $@ -MP -MT $(patsubst %.d,%.o,$@) $(C_FLAGS) $(filter %$(patsubst %.d,%.c,$(notdir $@)),$(C_SRCS)) + $(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 $(C_FLAGS) $< -o $@ + $(CC) -c $(CPP_FLAGS) $(C_FLAGS) $< -o $@ .PHONY: clean clean: