Thread: % in makefile target match range

  1. #1
    Registered User
    Join Date
    Mar 2009

    % in makefile target match range


    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:
    %.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 int overfl Salem's Avatar
    Join Date
    Aug 2001
    The edge of the known universe
    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.
    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.

  3. #3
    Registered User
    Join Date
    Mar 2009
    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
    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
Website Security Test