Makefile option/rule to handle missing/removed source files

Posted by b3nj1 on Stack Overflow See other posts from Stack Overflow or by b3nj1
Published on 2010-05-17T03:56:21Z Indexed on 2010/05/17 4:00 UTC
Read the original article Hit count: 235

Filed under:
|

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

© Stack Overflow or respective owner

Related posts about makefile

Related posts about library