[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: ignore specific file in VPATH/vpath

From: Jannick
Subject: RE: ignore specific file in VPATH/vpath
Date: Thu, 10 May 2018 10:30:03 +0200

I figured out another solution: If make cannot distinguish the two generated
files ../parse.c and parse.c from each other, then the makefile could do
that by labelling parse.c, i.e. using a prefix (here: 'g-' for generated);
use g-parse.c instead of parse.c. This definitely routes the building path
of parse.y through the corresponding .c file built *in* the folder 'build'.

This is at the expense to have an explicit rule for .y files which is -
AFAICS - currently needed anyways, since the built-in YACC rule breaks with
bison >= 3.0 (at least); more as to why please see below.

src_dir                 = ../src
prog:                   prog.o g-parse.o

g-%.c:                  %.y
                        bison -o $@ $<

# solution 1
VPATH                   = $(src_dir)

# solution 2
#vpath   %.y            $(src_dir)
#vpath   %.c            $(src_dir)

Nonetheless, I would be still interested in other sweet and short solutions.


On Wed, 9 May 2018 14:30:15 +0200, Jannick wrote:
> Hey,
> I am having an issue with the make vpath/VPATH configuration where make
> should ignore a specific existing file in vpath/VPATH. Here my case for
> any input from you is highly appreciated:
> Cd'ed to the folder 'build', the objective is to build prog with the
source files
> prog.c and parse.y, both sitting in 'src':
> +---build
> |       makefile
> |
> \---src
>         parse.c <<< disregard for a build in folder 'build'
>         parse.y
>         prog.c
> The nasty thing is src/parse.c which unfortunately does exist, but should
> ignored for our project, since build/parse.c should be separately build
> parse.y) and used instead.
> Currently, I am not able - in an elegant way - to avoid that make uses
> src/parse.c, unless make -B. The following makefile does the job, but it
is not
> very elegant to set up a vpath statement for each .c source file (this is
just a
> tiny example, in real life there might be many of those required).
> $ cat makefile
> src_dir                       = ../src
> prog:                 prog.o parse.o
> %.c:                  %.y
>                       bison -o $@ $<
> # vpath statement for each .c source file, not very elegant
> vpath   %.y           $(src_dir)
> vpath prog.c          $(src_dir)
> Alternatives:
> 1 - Using VPATH = $(src_dir) instead of the vpath block does not work,
> then make uses src/parse.c unless make -B.
> 2 - Another solution could be to copy the source files to build and take
> from there.
> 3 - My question: Is there any (easy) tweak to the makefile above (without
> given vpath block) to make that happen - or should be a copy to build
> & compile method applied or something else I was not thinking of?
> Separately, an additional note: make's YACC built-in recipe
> %.c: %.y
> #  recipe to execute (built-in):
>       $(YACC.y) $<
>        mv -f $@
> appears to assume that YACC/bison's output file name defaults to
> However, it is $*.tab.c for bison >= 3.0 (at least). Would that be worth
> enhancement to make to update to the new built-in recipe? Here I am not
> sure which versions of yacc are out there and what their output files are
> named.
> Many thanks for any input!
> Regards,
> J.
> Signatures:
> - GNU Make 4.2.1; Built for i686-pc-cygwin
> - bison (GNU Bison) 3.0.4

reply via email to

[Prev in Thread] Current Thread [Next in Thread]