Like Tree1Likes
  • 1 Post By Salem

% in makefile target match range

This is a discussion on % in makefile target match range within the Tech Board forums, part of the Community Boards category; Hi, I was reading a makefile in someone else's C code. I found the percentage sign use and looked up ...

  1. #1
    Registered User
    Join Date
    Mar 2009
    Posts
    48

    % in makefile target match range

    Hi,

    I was reading a makefile in someone else's C code. I found the percentage sign use and looked up the GNU make manual. In the manual, the sign is illustrated in a snippet as follows:
    Code:
    %.o: %.c
        recipe ....
    The manual tells that % is a pattern matching any nonempty substring, but my question is in which range/files to match? For example, if I type `ls *' in directory /tmp, the wildcard * matches file names under /tmp. The percentage sign in makefile must have a matching range/place/files to match file names. I couldn't find the explanation in the manual. Could anyone help to explain?

    Thanks a lot!

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,659
    You have to remember that makefiles kind of work "backwards".
    You start with a target, and it has dependencies to make that target.

    Say for example
    myprog: foo.o bar.o

    Then make asks itself, OK, how do I make a foo.o?

    Well for one thing, it could look for an explicit
    foo.o : foo.c

    But in the absence of that, it tries a matching rule instead, say
    %.o : %.c
    So it temporarily invents foo.o : foo.c, finds that foo.c does indeed exist, and proceeds to execute recipe to make a foo.o it can use to satisfy myprog.
    stahta01 likes this.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  3. #3
    Registered User
    Join Date
    Mar 2009
    Posts
    48
    @Salem,
    I got it. It's target matches against pattern rule, not pattern rule matches against target.
    thank you very much!
    Last edited by password636; 10-15-2012 at 12:21 PM. Reason: spell wrong name

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 2
    Last Post: 04-27-2011, 04:14 PM
  2. HELP -Upload to Target FTP-
    By s0nicstr1fe in forum Networking/Device Communication
    Replies: 3
    Last Post: 09-06-2009, 09:52 AM
  3. Makefile Problem: None rule to make target
    By chris24300 in forum Linux Programming
    Replies: 25
    Last Post: 06-17-2009, 09:45 AM
  4. difference makefile makefile.am makefile.in
    By Bargi in forum Linux Programming
    Replies: 7
    Last Post: 10-28-2007, 02:08 PM
  5. &target
    By zp523444 in forum C Programming
    Replies: 2
    Last Post: 01-24-2006, 11:22 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21