http://stackoverflow.com/questions/239004/need-a-makefile-dependency-rule-that-can-handle-missing-files gives some pointers on how to handle removed source files for generating .o files. I'm using gcc/g++, so adding the -MP option when generating dependencies works great for me, until I get to the link stage with my .a file...
What about updating archives/libraries when input sources go away? This works OK for me, but is there a cleaner way (ie, something as straightforward as the g++ -MP option)?
#BUILD_DIR is my target directory (includes Debug/Release and target arch)
#SRC_OUTS are my .o files
LIBATLS_HAS = $(shell nm ${BUILD_DIR}/libatls.a | grep ${BUILD_DIR} | sed -e 's/.*(//' -e 's/).*://')
LIBATLS_REMOVE = $(filter-out $(notdir ${SRC_OUTS}), ${LIBATLS_HAS})
${BUILD_DIR}/libatls.a: ${BUILD_DIR}/libatls.a(${SRC_OUTS})
ifneq ($(strip ${LIBATLS_REMOVE}),)
$(AR) -d $@ ${LIBATLS_REMOVE}
endif
Updated to the following after initial feedback:
LIBATLS_HAS := $(shell $(AR) t ${BUILD_DIR}/libatls.a)
LIBATLS_REMOVE := $(filter-out $(notdir ${SRC_OUTS}), $(filter %.o,${LIBATLS_HAS}))
.PHONY: clean_archive
clean_archive:
$(AR) -d $(BUILD_DIR)/libatls.a $(LIBATLS_REMOVE)
.PHONY: $(LIBATLS_REMOVE)
$(LIBATLS_REMOVE): clean_archive
${BUILD_DIR}/libatls.a: % : %(${SRC_OUTS}) ${LIBATLS_REMOVE}