bugmake - Bugs: bug #62228, prerequisite based on input file...

 
 

bug #62228: prerequisite based on input file created during processing not created, but no error

Submitter:  Greg Minshall <minshall>
Submitted:  Tue 29 Mar 2022 04:38:56 AM UTC
   
 
Severity:  3 - Normal Item Group:  None
Status:  Not A Bug Privacy:  Public
Assigned to:  None Open/Closed:  Closed
Component Version:  4.3 Operating System:  POSIX-Based
Fixed Release:  None Triage Status:  None
* Mandatory Fields

Add a New Comment Rich Markup
   

Sun 24 Apr 2022 07:18:43 PM UTC, comment #2: 

thanks!

Greg Minshall <minshall>
Sat 23 Apr 2022 09:29:54 PM UTC, comment #1: 

Make always parses all non-recipe lines when the makefile is read, before it runs any recipes.  It finishes parsing all the makefiles (which includes expanding all variables that are targets or prerequisites) during the read-on phase.

See the GNU make manual for exact details: https://www.gnu.org/software/make/manual/html_node/Reading-Makefiles.html

You can't have a makefile where the recipe of one rule creates a file and another rule uses wildcards or shell commands to list all the files to generate prerequisites because when the function or variable is expanded to list the prerequisites, the rule to create them hasn't been run yet.  In your makefile:


INFILES = $(notdir $(shell ls ${INDIR}/*.input))
  ...
OUTFILES = $(addprefix ${OUTDIR}/,$(notdir ${INFILESASOUT}))
  ...
processoutputs: ${OUTFILES}


When make parses the makefile, before it runs any rules, it will expand OUTFILES which will cause INFILES to be expanded, which will search for .input files.  But the something rule has not been run yet, so ./inputs/b.input doesn't exist, so the contents of INFILES won't see it, so it won't be in OUTFILES either.

Basically you can't rely on wildcards to find files that are created during the build, because at the time that these wildcards are expanded the build has not been run so the created files won't be found.

If you need help please email either -email is unavailable- or bug-make@gnu.org.  You'll need to provide a more exact description of precisely what you want to accomplish however.

Paul D. Smith <psmith>
Group administrator
Tue 29 Mar 2022 04:38:56 AM UTC, original submission:  

hi.  sorry.  i'm not sure if this is a bug.

in the makefile below, the initial condition should be that ./outputs is empty, but ./inputs includes a file ./inputs/a.input.  the main goal causes ./inputs/b.input to be created.  a pattern rule should convert ./inputs/%.input to ./outputs/%.output.  and, the sub-goal `processoutputs` has as prerequisites `${OUTFILES}`, created by text-munging of the files (then) in ./inputs.  so, when this goal is executed, that includes ./outputs/b.output.  but, ./outputs/b.output is not created (which seems consistent with verbiage in the info pages), and, no error is generated saying "no rule to make ./outputs/b.output..." (or, words to that effect).

the fact that `${OUTFILES}`, when the `diff` command is invoked, includes ./outputs/b.output makes me wonder if there is a bug here?

(but, i'm guessing that dependencies are built when the makefile is read, then not updated?)

cheers.


INDIR = ./inputs
OUTDIR = ./outputs

INFILES = $(notdir $(shell ls ${INDIR}/*.input))
INFILESASOUT = $(INFILES:.input=.output)
OUTFILES = $(addprefix ${OUTDIR}/,$(notdir ${INFILESASOUT}))
NEWIN = ${INDIR}/b.input
NEWOUT = ${OUTDIR}/b.output

${OUTDIR}/%.output: ${INDIR}/%.input
        echo creating $(notdir $@)
        cp -p $< $@

.PHONY: all setup processoutputs something clean

all: setup something processoutputs

setup:
        @for dir in ${OUTDIR} ${INDIR}; do \
                if [ ! -e $${dir} ]; then mkdir $${dir}; fi \
        done
        @if [[ -f ${NEWIN} ]]; then \
                echo error: "${NEWIN} exists -- run \`make clean\`"; \
                exit 1; \
        fi

# this wants, as dependency,
processoutputs: ${OUTFILES}
        @diff <(for i in ${OUTFILES}; do echo $$i; done) <(ls ${OUTDIR}/*)

something:
        @touch ${NEWIN}

clean:
        @-rm -f ${OUTFILES}
        @-rm -f ${NEWIN}



Greg Minshall <minshall>

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach Files:
   
   
Comment:
   

No files currently attached

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by psmith (Posted a comment)
  • -email is unavailable- added by minshall (Submitted the item)
  • -email is unavailable- added by minshall
  •  

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

    Only logged-in users can vote.

     

    Follow 3 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2022-04-23 psmith StatusNone Not A Bug
        Open/ClosedOpen Closed
    2022-03-29 minshall Carbon-Copy- Added -email is unavailable-

    Back to the top

    Powered by Savane 3.13-02a9.
    Corresponding source code