[Top][All Lists]

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

Re: Question about target files

From: Raleigh Rinehart
Subject: Re: Question about target files
Date: Wed, 09 Feb 2011 10:50:24 -0600
User-agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv: Gecko/20101207 Lightning/1.0b2 Thunderbird/3.1.7

On 2/9/2011 9:05 AM, Faruk Kuşcan wrote:

I'm new to make. I'm trying to write a makefile which looks at ../src/
directory and looks for updated cpp, c, hpp, h, ipp files. If they are
updated then I want to do the recipe. I wrote following lines. : ../src/*.cpp ../src/*.c ../src/*.h ../src/*.hpp ../src/*.ipp

However my problem is this; in some cases I don't have .c files or .h files.
But I may have sometimes. I don't know about that. So I want to write all
possibilities. Make looks at the directory and then tells me "there is no
*.h file in that directory" . How can I handle this?


Good day.

Faruk Kuscan

this is easily handled using the $(wildcard ) make function. So your example might looks something like this:

SRC_DIR := ../src
c_src =  $(wildcard $(SRC_DIR)/*.c)
cpp_src = $(wildcard $(SRC_DIR)/*.c)
ipp_src = $(wildcard $(SRC_DIR)/*.ipp)
headers = $(wildcard $(SRC_DIR)/*.h) $(wildcard $(SRC_DIR)/*.hpp) $(c_src) $(cpp_src) $(ipp_src) $(headers)

However, I wonder what you are trying to accomplish? Do you really want to explicitly define the .h/.hpp files as prerequisites in this way? Or would using a dependency generation tool and Make's include directive work? You might also want to look at vpath.

What is the target producing? Should it really depend on the src files or should it depend on the object files produced (by a compiler) instead? This way your are letting the rules that do the compilation worry about when to update files.

If you give us some more info on what you want to accomplish then we can provide some more detailed help.

I take that since you've found this list, you've also found the Gnu Make manual, you might want to give a quick look through to see what other built-in functions make has. Also the book Managing Projects with GNU Make, Third Edition is an invaluable resource, especially for someone just starting out. You can find an open version here:

hope this helps,

reply via email to

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