help-make
[Top][All Lists]
Advanced

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

Cancelling a Implicit Rule ?


From: L.Guo
Subject: Cancelling a Implicit Rule ?
Date: Tue, 8 Dec 2009 18:13:47 +0800

Hi all:

In my C project, I need to generate version.h and add it into compiling.
And also, I need a 'copy' rule, which copies the output binaries into a dir 
specified by a environment var COPYDIR.
This is a common need for my projects.
So I design a makefile structure, try to implement it and encounter a problem 
as followed.


I have a main makefile 'Makefile' and two sub (common) makefile 'default.mk' 
and 'rules.mk'.

The source files all in 'src' dir, the output in 'out'. As these:

        SRCS = src/a.c src/main.c src/version.h
        DEPS = out/a.d out/main.d
        OBJS = out/a.o out/main.o
        TGTS = out/programme


I want to use pattern rules in 'rules.mk' to handle the dependencies generating.

$(OUTDIR)/%.d: $(SRCDIR)/%.c $(OUTDIR)
        @{ set -e; $(RM) $@;\
           echo 'Generate $@ from $<'\
           $(CC) -M $(CFLAGS) $< > address@hidden;\
           sed 's,\($*\)\.o[ :]*,\1.o $@ : ,g' < address@hidden > $@;\
           $(RM) address@hidden;\
         }

$(OBJS): $(OUTDIR)/%.o: $(SRCDIR)/%.c $(OUTDIR)/%.d
        $(CC) -c $(CFLAGS) -o $@ $<


'default.mk' is omited because it just complete some necessary-but-unset vars 
in 'Makefile'.


When using the whole thing to build my project, 'make' gives me an error report:

        make: *** No rule to make target `main.c', needed by `out/main.d'.  
Stop.


I know that, for 'rules.mk' including the '.d' files, 'make' need 'out/main.d', 
and also need 'src/main.c'.
I guess it is using a implict rule to generate '.d' from '.c'. And tried this 
additional empty rule but failed:

        $(OUTDIR)/%.d: %.c

I have no idea why 'main.c' is needed after 'make' using 'src/main.c'.
Here is the output of 'make -d'. (I use -R to make the output shorter.)

---------------------------------------------------------------
Reading makefiles...
Reading makefile `Makefile'...
Reading makefile `default.mk' (search path) (no ~ expansion)...
Reading makefile `rules.mk' (search path) (no ~ expansion)...
Reading makefile `out/a.d' (search path) (no ~ expansion)...
Reading makefile `out/main.d' (search path) (no ~ expansion)...
Updating makefiles....
 Considering target file `out/main.d'.
  Looking for an implicit rule for `out/main.d'.
  Trying pattern rule with stem `main'.
  Trying implicit prerequisite `src/main.c'.
  Trying rule prerequisite `out'.
  Found an implicit rule for `out/main.d'.
   Considering target file `src/main.c'.
    Looking for an implicit rule for `src/main.c'.
    No implicit rule found for `src/main.c'.
    Finished prerequisites of target file `src/main.c'.
   No need to remake target `src/main.c'.
   Considering target file `out'.
    Finished prerequisites of target file `out'.
   No need to remake target `out'.
   Considering target file `main.c'.
    File `main.c' does not exist.
    Looking for an implicit rule for `main.c'.
    No implicit rule found for `main.c'.
    Finished prerequisites of target file `main.c'.
   Must remake target `main.c'.
make: *** No rule to make target `main.c', needed by `out/main.d'.  Stop.
----------------------------------------------------------------------


Mainly structure of makefile :

file Makefile :
1: set FILE, DIR and COMPILER vars.
2: include default.mk
3: rule 'all' for TGTS
4: other project specified rules. e.g. rule for out/programme
5: include rules.mk

file default.mk :
1: complete vars. e.g. DEPS, SRCDIR, OUTDIR, etc.

file rules.mk :
1: common rules. e.g. clean, copy, $(OUTDIR)/%.d, $(OBJS), $(SRCDIR)/version.h
2: include dependencies

    Regards
--------------
L.Guo
2009-12-08





reply via email to

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