Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 806507
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T00:15:14+00:00 2026-05-15T00:15:14+00:00

Need a makefile dependency rule that can handle missing files gives some pointers on

  • 0

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}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T00:15:15+00:00Added an answer on May 15, 2026 at 12:15 am

    There are a few different ways to do this. One that’s pretty clean is:

    LIBATLS_HAS:=$(shell $(AR) t $(BUILD_DIR)/libatls.a)
    LIBATLS_REMOVE:= $(filter-out $(SRC_OUTS),$(LIBATLS_HAS))
    REMOVE_LIST = $(addprefix remove_,$(LIBATLS_REMOVE))
    
    .PHONY: $(REMOVE_LIST)
    $(REMOVE_LIST): remove_%
        $(AR) -d $(BUILD_DIR)/libatls.a $*
    
    $(BUILD_DIR)/libatls.a: % : %($(SRC_OUTS)) $(REMOVE_LIST)
    

    This is a little inefficient in that it runs a seperate $(AR) command for each member to be removed. I doubt that’ll be a problem, but if it is you can get around it with a phony target:

    # Note that this will run once at most.
    .PHONY: clean_archive
    clean_archive:
        $(AR) -d $(BUILD_DIR)/libatls.a $(LIBATLS_REMOVE)
    
    .PHONY: $(REMOVE_LIST)
    $(REMOVE_LIST): clean_archive
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to create a special makefile rule, which is best explained by an
I have a makefile for compiling Arduino programs . I need to add some
we have some C++ code that we need to create a make file in.
I need to create a makefile that will compile my simpleprogram.c to sp and
How can I use shell parameter extension in a Makefile? I need to get
I need help with comparing two files in makefile. I need something like this:
I need to take a parameter in my Makefile that consists of a host
I need to make a makefile that compiles and executes my classes with an
I need to modify the below makefile to create a dll (SampleNew.dll) that will
i need to build 4 targets from the same set of source files. The

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.