build process improved
This commit is contained in:
parent
614a1a73f8
commit
f752aece31
17
Makefile
17
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:
|
||||
|
Loading…
Reference in New Issue
Block a user