|
Blue Forest http://www.lslnet.com at 10:18 on June 6, 2006
Makefile (7)
Title : makefile (7)
2.6 function (Functions)
Makefile Lane -- very similar to the function of the variables used it to the time you sign with the opening of a $ brackets, a few letters, a series of ballots, told the parameters separated by commas, brackets relations with the final end. For example, there is a GNU Make called 'wildcard' letter, it would have one parameter is a function of its launch into a list of all the parameters described in the documents, and documents with blank space between interval. You can use this order as indicated below :
SOURCES = $ (wildcard *.c)
It's all to be one '. C 'end of the list of documents, which could then be stored in variables SOURCES Lane. Of course, you must not result into a variable.
Another useful function is patsubst (patten substitude, for the initials for the match) function. It requires three parameters -- is a need for a matching pattern, and the second said what to replace it, and the third is a box separated from the need to be dealt with the word out. For example, after the above address that the definition of variables,
OBJS = $ (patsubst %.c, %.o $ (SOURCES))
SOURCES characters in this series will deal with all the characters (a series of papers), if it is the end '. C 'used'. O 'turn'. C 'replacement. Symbol% of the market will pay attention to here is assigned one or more characters, and it's always a matching string is called a 'stalk' (stem). In the second parameter, be interpreted as% of the match with the first parameter that stalk.
2.7 a more effective makefile
We are now using the study, we can create a very effective makefile. We need to finish most of the makefile can rely on the inspection did not have to do too much change can be directly used in the vast majority of projects Lane.
We need a basic makefile to build our procedures. We can let the current catalog search to find source documents, and assume that they are all our projects, either in a variable called SOURCES. If the document contains all the *.cc here, perhaps more insurance may be because the C + + source code documentation. SOURCES = $ (wildcard *.c *.cc) patsubst use, we can have a goal of documents from the source file name, and we need the translation of these objectives document. If both the source document. C documents, as well. Cc documents, we need to use the embedded phase patsubst function call :
OBJS = $ (patsubst %.c, %.o $ (patsubst %.cc, %.o $ (SOURCES)))
Call on the inside layer of the most patsubst. Cc suffix alternative document, the result was the outer patsubst Call, for right. C suffix paper alternative.
Now we can establish a procedure to build the executable files :
Myprog : $ (OBJS)
Gcc -o myprog $ (OBJS)
Further rules do not necessarily need to know how to have generated gcc object files (object files). Now we can have a set of rules on information :
Depends : $ (SOURCES)
$ Gcc-M (SOURCES) "; Depends
Here, if one is called 'depends' documents did not exist, or any other source than the one already in existence depends new document, a document will be depends Health%. Gcc from the document will be depends on the source documents containing the rules (M attention switches). Now we want to make these rules as part of the makefile stalls. Here the use of C language skills like #include system -- we should seek to make this document include makefile, as follows :
Include depends
GNU Make see this check 'depends' renewed purpose, if not, we will have to reconsider its order depends stalls. Then it will turn this group of (new) rules contain them, to continue to address the ultimate goal of 'myprog'. When he saw the myprog rules, it will check whether the objectives of all the documents to update the rules -- use depends, of course, the rules now is the updated.
In fact, this system is inefficient, because whenever a source document had been altered, the source of all the documents are pre-handle to create a new 'depends' document. It is not 100% safe, it is because when a header stalls had been altered, and not rely on information being updated. But on the basic work, it is also quite useful in this case.
|
Makefile (7)
Received |
Makefile (7)
Haotie, the series is pretty good, read! |
| |