Thread: Confused with a make file

  1. #1
    Registered User
    Join Date
    Jan 2006
    Posts
    13

    Confused with a make file

    Hi,
    I got a following Make file. Could anyone give me a hint of what
    COMPILEDIRS = $(SUBDIRS:=.compile)

    means ? Does it replace all subdirs with .compile ???


    Many thanks.
    Anh





    Code:
    # Source, Executable, Includes, Library Defines
    INCL   = trees.h
    SRCDIR= src
    LIBDIR = lib
    INCDIR = include
    
    # Compiler, Linker Defines
    CC      = gcc
    CFLAGS  = -Wall 
    
    # make sure all variables are exported to sub-makes
    export
    
    # subdirectories to be built
    SUBDIRS = $(SRCDIR) $(LIBDIR)
    
    # path definitions 
    
    prefix = /usr/local
    exec_prefix = $(prefix)
    bindir = $(exec_prefix)/bin
    libdir = $(exec_prefix)/lib
    
    # installation programs
    INSTALL = /usr/bin/install
    INSTALL_PROGRAM = $(INSTALL)
    INSTALL_DATA = $(INSTALL) -m 644
    
    
    # build everything recursively 
    
    all: srcdirs
    
    COMPILEDIRS = $(SUBDIRS:=.compile)
    
    .PHONY: srcdirs $(COMPILEDIRS)
    
    # must build library first
    src.compile: lib.compile
    
    srcdirs: $(COMPILEDIRS)
    
    $(COMPILEDIRS):
    	$(MAKE) -C $(@:.compile=) all  
    
    # install everything in the right place - again done recursively
    install: installdirs
    
    INSTALLDIRS = $(SUBDIRS:=.install)
    
    .PHONY: installdirs $(INSTALLDIRS)
    
    installdirs: $(INSTALLDIRS)
    
    $(INSTALLDIRS): all
    	$(MAKE) -C $(@:.install=) install 
    
    # clear up after build
    .PHONY:	clean
    
    clean:
    	(cd $(SRCDIR) ; $(MAKE) clean )
    	(cd $(LIBDIR) ; $(MAKE) clean )
    </code>
    Last edited by soothsayer; 04-17-2006 at 09:32 AM.

  2. #2
    C / C++
    Join Date
    Jan 2006
    Location
    The Netherlands
    Posts
    312
    Use code tags!!
    Operating Systems:
    - Ubuntu 9.04
    - XP

    Compiler: gcc

  3. #3
    erstwhile
    Join Date
    Jan 2002
    Posts
    2,227
    Could anyone give me a hint of what
    COMPILEDIRS = $(SUBDIRS:=.compile)

    means ? Does it replace all subdirs with .compile ???
    Yes. Substitution References with GNU make, as the name implies, substitutes each instance of the left of := with what's on the right.
    Last edited by Ken Fitlike; 04-17-2006 at 01:33 PM. Reason: typos
    CProgramming FAQ
    Caution: this person may be a carrier of the misinformation virus.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Data Structure Eror
    By prominababy in forum C Programming
    Replies: 3
    Last Post: 01-06-2009, 09:35 AM
  2. Can we have vector of vector?
    By ketu1 in forum C++ Programming
    Replies: 24
    Last Post: 01-03-2008, 05:02 AM
  3. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM
  4. simulate Grep command in Unix using C
    By laxmi in forum C Programming
    Replies: 6
    Last Post: 05-10-2002, 04:10 PM