I'm not a makefile expert. I have the following makefile (it is part of a larger project all have similar files), in this make I only want to create the objects (not the static library). When I change a C file or header file it will not recompile. I must perform clean (the clean is done by the makefile that calls this makefile). How can I force re-compile of every chaged C or H file?
#
# MAKEFILE
#
MAKEFILE := build.mk
#
# TARGET
#
#TARGET = librtos_butterfly.a
#
# PATH
#
RTOS_SRC_PATH := .
RTOS_PATH := ..
ROOT_PATH := ../..
RTOS_OUT_PATH := $(ROOT_PATH)/build/obj/FreeRTOS/tmp
export BLOCK_BUILD_PATH := $(ROOT_PATH)/build
#
# FLAGS
#
# Add module specific build options here
COPTS_RVDS +=
CXXOPTS_RVDS +=
# INCLUDES
#
# Add module specific include path here
INCLUDES = \
-I$(RTOS_PATH)/Source/include \
-I$(RTOS_PATH)/Source/portable/GCC/ARM_CM4F \
-I$(RTOS_SRC_PATH) \
-I$(RTOS_SRC_PATH)/CMSIS \
-I$(RTOS_SRC_PATH)/Device/include \
-I$(ROOT_PATH)/GNSS/main
#
# VPATH & SRCS
#
# Add directorys if you create any directories.
cdirs := Device/source # add GCC_Specific to use startup_ARMCM4.s instead of startup_ARMCM4.c
C_DIRS := $(foreach dir, $(cdirs), $(RTOS_SRC_PATH)/$(dir))
VPATH += . $(C_DIRS)
C_SRCS := $(notdir $(foreach dir, $(C_DIRS), $(wildcard $(dir)/*.c)))
CXX_SRCS := $(notdir $(foreach dir, $(C_DIRS), $(wildcard $(dir)/*.cc)))
ASM_SRCS := $(notdir $(foreach dir, $(C_DIRS), $(wildcard $(dir)/*.s)))
ifeq ($(VERBOSE), 1)
$(warning C_DIRS = $(C_DIRS))
$(warning C_SRCS = $(C_SRCS))
$(warning ASM_SRCS = $(ASM_SRCS))
$(warning CXX_SRCS = $(CXX_SRCS))
$(warning TARGET = $(TARGET))
$(warning RTOS_OUT_PATH = $(RTOS_OUT_PATH))
endif
OBJS := $(ASM_SRCS:.s=.o) $(C_SRCS:.c=.o) $(CXX_SRCS:.cc=.o)
OBJS := $(OBJS:%.o=$(RTOS_OUT_PATH)/%.o)
DEPENDS := $(OBJS:.o=.d)
CFLAGS = $(CFLAGS_COMMON) $(INCLUDES)
CXXFLAGS = $(CXXFLAGS_COMMON) $(INCLUDES)
ASFLAGS = $(ASFLAGS_COMMON) $(INCLUDES)
#
# Rule (tentative)
#
.SUFFIXES:
.SUFFIXES: .o .c .cc .s .h
all: $(OBJS) $(C_SRCS) #$(TARGET)
$(TARGET): $(OBJS) $(MAKEFILE)
@echo "===< archive : $(@F) >==="
$(HIDE)cd $(RTOS_OUT_PATH); $(AR) $(ARFLAGS) $@ $(notdir $(OBJS))
$(RTOS_OUT_PATH)/%.o : %.c
@echo "===< compile : $(<F) >==="
$(CC) $(CFLAGS) -o $@ $< $(call CDEPEND,$@)
$(RTOS_OUT_PATH)/%.o : %.cc
@echo "===< compile : $(<F) >==="
$(CC) $(CXXFLAGS) -o $@ $< $(call CDEPEND,$@)
$(RTOS_OUT_PATH)/%o : %s
@echo "===< compile : $(<F) >==="
$(AS) $(ASFLAGS) -I./include -o $@ $< $(call CDEPEND,$@)
$(UNSILENT).SILENT:
clean:
# \rm -f $(OUTPUT_PATH)/$(TARGET)
# \rm -f $(OBJS)
# \rm -f $(DEPENDS)
sinclude $(DEPENDS)
In case needed (I think it is irrelevant) this is the makefile that calls the above makefile
#
# rtos_build.mk
#
# MAKEFILE dependency
MAKEFILE := rtos_build.mk
SHELL = /bin/sh
export RTOS_NAME = FreeRTOS
##### Specify the object files of each SW blocks to link #####
RTOS_SW_OBJS = librtos_butterfly.a librtos_source.a
##### Specify the directory name of SW block to build #####
RTOS_SW_BLOCK = $(RTOS_NAME)/butterfly $(RTOS_NAME)/Source
TARGET_RTOS_LIB := $(RTOS_NAME).a
RTOS_MAP := $(RTOS_NAME).map
include common_path.mk
include toolchain.mk
# suffix roules
.SUFFIXES:
.SUFFIXES: .o .c .cc .s .h
.PHONY : all codesonar clean
all : MakeRtosDirs $(RTOS_SW_BLOCK) #$(TARGET_RTOS_LIB)
codesonar : $(RTOS_SW_BLOCK)
MakeRtosDirs:
$(HIDE)-mkdir -p $(RTOS_OBJ_DIR)
$(HIDE)-mkdir -p $(RTOS_RELEASE_PATH)
$(HIDE)-mkdir -p $(PKG_OUT_PATH)
$(HIDE)-mkdir -p $(PKG_OUT_TMP)
########## Create main target library ##########
$(TARGET_RTOS_LIB) : $(RTOS_SW_BLOCK) $(MAKEFILE)
@echo -e "start to make FreeRTOS library"
@echo "--------------------------------"
$(HIDE)cd $(RTOS_RELEASE_PATH) && \
$(AR) $(ARFLAGS) $@ $(RTOS_SW_OBJS)
$(HIDE)rm -f -r $(RTOS_RELEASE_PATH)
######## create sw blocks ########
.PHONY : $(RTOS_SW_BLOCK)
$(RTOS_SW_BLOCK):
@echo -e "*** Make $@ ***"
$(HIDE)$(MAKE) -C $(ROOT_DIR)$@
# $(HIDE)cp -f $(RTOS_OBJ_DIR)/*.a $(RTOS_RELEASE_PATH)
$(UNSILENT).SILENT:
clean :
rm -f -r $(RTOS_BUILD)
realclean: clean