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 8642241
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T11:43:35+00:00 2026-06-12T11:43:35+00:00

Fair warning: I’m something of a newb at using makefiles, so this may be

  • 0

Fair warning: I’m something of a newb at using makefiles, so this may be something obvious. What I’m trying to do is to use make to run a third-party code generation tool when and only when the source files for that generation tool (call them .abc files) change. I referenced the example at http://www.cmcrossroads.com/ask-mr-make/6795-rebuilding-when-a-files-checksum-changes which shows how to build MD5s, and I tweaked the idea a bit:

File: abc.mk

target = all
files    := $(wildcard Abc/*.abc)
bltfiles := $files $(addsuffix .built,$files)

all: $bltfiles

%.built: %.abc %.abc.md5
    @echo "Building $*"
    @ #Command that generates code from a .abc file
    @touch $@

%.md5: FORCE
    @echo "Checking $* for changes..."
    @ #Command to update the .md5 file, if the sum of the .abc file is different

FORCE:

What I’m intending to happen is for each .abc file to have two auxilary files: .abc.built & .abc.md5 . The .built file is just a dummy target & timestamp for the last time it was built, as the code produced by the generation tool cannot be readily defined as a target. The .md5 file contains a hash of the last known content of the .abc file. It should only be updated when the hash of the file changes.

However, the .built file is only created if it doesn’t exist. The .md5 rule never runs at all, and the .built rule doesn’t re-build even if the .abc file has a newer timestamp. Am I doing something wrong?

Update:
For posterity, here’s the version I got to work:

File: abc.mk

# Call this makefile as: make all --file=abc.mk

# Default Target
target = all

COMP_ABC_FILES := $(wildcard Abc/*.abc)
COMP_BLT_FILES := $(COMP_ABC_FILES) $(addsuffix .built, $(COMP_ABC_FILES) )

# This line is needed to keep make from deleting intermediary output files:
.SECONDARY: 

# Targets:
.PHONY: all
all: $(COMP_BLT_FILES)

Abc/%.abc.built: Abc/%.abc Abc/%.abc.md5
    @echo "Building $*"
    @ #Command that generates code from a .abc file
    @touch $@

%.md5: FORCE
    @echo "Checking $* for changes..."
    @$(if $(filter-out $(shell cat $@ 2>/dev/null),$(shell md5sum $*)),md5sum $* > $@)

# Empty rule to force re-build of files:
FORCE:

clean:
    @echo "Cleaning .built & .md5 files..."
    @rm Abc/*.built
    @rm Abc/*.md5
  • 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-06-12T11:43:36+00:00Added an answer on June 12, 2026 at 11:43 am

    Fixing your makefile in three places:

    target = all
    files    := $(wildcard Abc/*.abc)
    bltfiles := $(files) $(patsubst %.abc,%.built,$(files))
    
    all: $(bltfiles)
    
    #Abc/%.abc.built: Abc/%.abc Abc/%.abc.md5
    %.built: %.abc %.abc.md5
        @echo "Building $*"
        @ #Command that generates code from a .abc file
        @touch $@
    
    %.md5: FORCE
        @echo "Checking $* for changes..."
        @ #Command to update the .md5 file, if the sum of the .abc file is different
    
    FORCE:
    

    Note the changes:

    1. bltfiles := $(files) $(patsubst %.abc,%.built,$(files))

      Results in “Abc/a.built Abc/b.built” instead of “Abc/a.abc.built Abc/b.abc.built”, which was required given how the rule for %.built was defined

    2. all: $(bltfiles)

      As above, with $(files), ‘$bltfiles’ needed to be $(bltfiles), since otherwise make will interpret this as $(f)iles and $(b)ltfiles instead.

    Tip: Having an editor with syntax highlighting for makefiles is nice here


    DEMO

    mkdir -pv Abc; touch Abc/{a,b,c,d,e,f,g}.abc
    make -Bs -f abc.mk
    

    output like

    Checking Abc/e.abc for changes...
    Building Abc/e
    Checking Abc/g.abc for changes...
    Building Abc/g
    Checking Abc/b.abc for changes...
    Building Abc/b
    Checking Abc/f.abc for changes...
    Building Abc/f
    Checking Abc/a.abc for changes...
    Building Abc/a
    Checking Abc/c.abc for changes...
    Building Abc/c
    Checking Abc/d.abc for changes...
    Building Abc/d
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Fair warning: I am no expert, but I did manage to get this far.
Is this a fair analogy to make? I think I can think of some
Fair warning: The setup for this question is long, so be patient and stay
Fair warning: I'm a big time noob. Please handle with kid gloves. Details: Python
I've seen my fair share of IE stuff, but never seen this before &
I'm have a fair complex Form that I am trying to create in Play
First, fair warning: I am a complete newbie with C# and WPF. I have
I have a fair amount of Facebook development experience, but this had made me
I have done my fair amount of research and finally decided to ask this.
JNA seems a fair bit easier to use to call native code compared to

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.