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

  • SEARCH
  • Home
  • 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 6324725
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T16:45:31+00:00 2026-05-24T16:45:31+00:00

I’m trying to learn makefiles. I have the following Makefile: ctx/%.ctx: rst/%.rst texlua rst_parser.lua

  • 0

I’m trying to learn makefiles.
I have the following Makefile:

ctx/%.ctx: rst/%.rst
    texlua rst_parser.lua $< $@

pdf: ctx
    mkdir -p pdf
    cd pdf; context ../ctx/main.ctx

ctx: rst
    mkdir -p ctx

.PHONY: clean
clean:
    rm -f pdf/*.log pdf/*.aux pdf/*.pgf pdf/*.top pdf/*.tuc

As you can see, all three prerequisites are directories; rst, ctx and pdf. The prerequisites recurse down to “rst”. I’ll edit files in ctx manually and files in rst, which get converted into files in ctx.

What should I do to make make make pdf 🙂 the following way:

  1. Look if something in ctx and/or something in rst has changed.
  2. If only something in ctx was changed, make pdf, else make ctx.
  3. If something in rst has changed, use the first rule to make the corresponding file in ctx, then make ctx and then make pdf.

My problem is now that I don’t know how to tell make “In order to make ctx when files in rst are changed, use the first rule (ctx/%.ctx: ctx/%.rst) to make each matching file in ctx from the corresponding one in rst”

  • 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-24T16:45:31+00:00Added an answer on May 24, 2026 at 4:45 pm

    Your question is a little unclear (e.g. you’re confusing the directory pdf/ with the makefile target pdf), but this should do what I think you want:

    TARGETS := $(wildcard rst/*.rst)
    TARGETS := $(patsubst rst/%.rst,%,$(TARGETS))
    
    ctx/%.ctx: rst/%.rst    # I assume you didn't mean ctx/%.rst
      texlua rst_parser.lua $< $@
    
    pdf: ctx
      mkdir -p pdf
      cd pdf; context ../ctx/main.ctx
    
    .PHONY:cxt
    ctx: $(patsubst %,ctx/%.ctx, $(TARGETS))
      mkdir -p ctx
    

    And the reason a plain make builds pdf is that when you invoke Make without a target it chooses the default target, which is the first target (unless you do some tinkering), which in this case is pdf. (The pattern rule doesn’t count.)

    EDIT:
    Now that I think of it, what I posted above is kind of clunky, and it will always run the pdf rule, even if nothing has changed. This is somewhat better:

    # You're right, this is better.        
    CTX_TARGETS := $(patsubst rst/%.rst,ctx/%.ctx, $(wildcard rst/*.rst))
    
    pdf: $(CTX_TARGETS)
      mkdir -p pdf
      cd pdf; context ../ctx/main.ctx
    
    $(CTX_TARGETS): ctx/%.ctx: rst/%.rst ctx
      texlua rst_parser.lua $< $@    
    
    ctx:
      mkdir -p ctx
    

    I made ctx PHONY because I was wrestling with the case when the directory exists, but the rule should still be run. It turned out to be unnecessary (as you might guess from the fact that I didn’t catch the typo).

    And yes, prerequisites are the names of files or dirs (or PHONY targets). My point was that phrases like “make pdf” are a little confusing if pdf is both a directory and a rule which builds it (and does other things).

    The problem with using directories as targets is that they don’t obey intuitive rules of modification time: if you modify a file in a directory, the directory’s mod time doesn’t change. It’s also tricky to change the mod time deliberately, since touch doesn’t do it (don’t ask me why it’s legal to touch a directory if it does nothing). It can be done, e.g. by adding and deleting a dummy file, but it’s ugly.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to learn about shift-reduce parsing. Suppose we have the following grammar, using
Warning: trying to learn OpenGL ... I have drawn a square with the following
Trying to learn about php's arrays today. I have a set of arrays like
In trying to learn how to create objects in ActionScript, I have had no
I was trying learn lex and yacc using the oreilly book. I tried following
While trying to learn Unity , I keep seeing the following code for overriding
I'm trying to learn about grails with Google App Engine and JPA by following
I'm trying to learn Make and building a Makefile into my app to help
I'm trying to learn how QProcess works and have this kind of code: #include
Trying to learn Regex in Python to find words that have consecutive vowel-consonant or

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.