Use make to update library files
-----------
The library file is the packaging file for the object file (intermediate file compiled by the Program. In UNIX, the "Ar" command is generally used to complete packaging.
I. Member of the function library file
A function library file consists of multiple files. You can specify the library file and its composition in the following format:
Archive (member)
This is not a command, but a definition of the target and dependency. In general, this is basically used to serve the "Ar" command. For example:
Foolib (hack. O): hack. o
Ar Cr foolib hack. o
If you want to specify multiple Member, separate them with spaces, for example:
Foolib (hack. O kludge. O)
It is equivalent:
Foolib (hack. O) foolib (kludge. O)
You can also use shell file wildcards to define them, such:
Foolib (*. O)
Ii. implicit rules of function library members
When make searches for implicit rules of a target, a special feature is that if the target is in the form of "A (m)", it will change the target to "(M )". Therefore, if our member is "%. O ", and if we use" make Foo. A (Bar. o) When makefile is called in the form of ", the implicit rule will find" bar. O "rule, if bar is not defined. O rules, then the built-in implicit rules take effect, make will go to the bar. c file to generate bar. o. If you can find it, the Command executed by make is roughly as follows:
CC-C bar. C-o Bar. o
Ar R Foo. A bar. o
Rm-F bar. o
Another variable is "$ %", which is the automation variable of the exclusive function library file. For more information, see "automation variable.
Iii. suffix rules of function library files
You can use "suffix rules" and "implicit rules" to generate library packaging files, such:
. C.:
$ (CC) $ (cflags) $ (cppflags)-C $ <-o $ *. o
$ (AR) r $ @ $ *. o
$ (RM) $ *. o
It is equivalent:
(%. O): %. c
$ (CC) $ (cflags) $ (cppflags)-C $ <-o $ *. o
$ (AR) r $ @ $ *. o
$ (RM) $ *. o
Iv. Notes
When generating a library package file, be careful to use the make parallel mechanism ("-J" parameter ). If multiple ar commands run on the same library package file at the same time, the library file may be damaged. Therefore, in future versions of make, a mechanism should be provided to prevent parallel operations from occurring on function packaging files.
However, for the moment, do not try to use the "-J" parameter.
Descending Order
--
It's time to finish the conclusion. The above is basically all the details of the makefile of GNU make. This is basically the same for other manufacturers. Whatever make, it is based on file dependency, and it basically follows a standard. 80% of the technical details in this document apply to any make. I guess the content in the chapter "functions" may not be supported by other make statements, but the implicit rules, I think different make may have different implementations. I don't have the power to check the differences between GNU make and VC nmake, BCB make, or other UNIX make, first, I don't have enough time and energy. Second, I basically use make in Unix. I used to use AIx in SCO UNIX and IBM, it is now used in Linux, Solaris, HP-UX, Aix, and Alpha, and more in Linux and Solaris. However, what I can be certain about is that, in UNIX, make and CC/GCC compilers developed by Richard Stallman are almost used on either platform, basically, it is GNU make (all UNIX machines in the company are installed with GNU, so there are more programs using GNU ). The GNU stuff is still very good. Especially after deep usage, the GNU software is becoming more and more powerful and the GNU Operating System (mainly Unix or even windows) is becoming more and more popular) "Lethal effect ".
For all the above make details, we can not only use the make tool to compile our program, but also use make to complete other work, because the commands in the rule can be commands under any shell, in UNIX, you may not only use the compiler of the program language, but also write other commands in makefile, such as tar, awk, mail, sed, CVS, compress, ls, RM, YACC, rpm, FTP ...... Wait, to complete various functions, such as "program PACKAGING", "program backup", "creating program installation packages", "submitting code", "using program templates", and "merging Files, file Operations, file management, programming and design, or some other whimsical things. For example, in the past, when I was writing a bank transaction program, because the bank transaction procedures were basically the same, I saw someone writing some general transaction program templates, in this template, you can write some common network communication, database operations, and business operations in one file, in these files, use strange strings such as "@ n, ### N" to mark some locations. Then, when writing transactions, you only need to write specific processing according to a specific rule, finally, in make, use awk and sed to replace the "@ n, ### N" and other strings in the template into a specific program, form a c file, and then compile. This action is similar to the "extended C" language of the database (that is, the SQL statement is executed in the C language like "Exec SQL". Before compiling with CC/GCC, you need to use a "extended C" translation program, such as cpre, to translate it into standard C ). If you have some better methods when using make, please remember to tell me.
Looking back at the entire document, I don't know what I was talking about when I first started development in UNIX a few years ago. Someone asked me if I would write makefile. When someone else writes the program in VI at the beginning, enter "! When making ", I thought it was a VI function. Later I realized that a makefile was playing a strange role, so I checked it online and didn't want to read English at that time, I found that there was no Chinese document to introduce makefile. I had to read the makefile written by others. I had accumulated some knowledge by myself, but I knew it in many places. Later, I started to develop UNIX product software. I saw a large project with nearly 400 lines of code for 2 million people and found that such a huge object would be compiled. If no makefile exists, that would be a terrible thing. As a result, I read a bunch of English documents and thought I had mastered it. However, I found that there are still few articles about makefile on the Internet, so I want to write such an article and share it with you. I hope it will help you.
Now I have finished writing the file. I have read the file creation time. This technical document has been written for more than two months. I found that I knew it was one thing. I had to write it down and tell others about it. Moreover, I am not having any time to study technical details, I found it difficult to be rigorous and refined when explaining some details, and I am not very clear about what I will talk about first. Therefore, I still referred to the materials and topic of some foreign sites, and the language style of some technical books. The outline of the entire document is based on the outline of the GNU makefile technical manual. It combines its work experience and learning history. Because I have never written such a long and detailed document, there must be many expressions, language ambiguities, or errors. For some reason, I am waiting for you to give me your testimony and suggestions, as well as any feedback.
Finally, I will introduce myself using this post-order. I am currently engaged in software development on all UNIX platforms, mainly for Distributed Computing/grid computing system products and software, and I am very interested in the next generation of computer revolution-grid computing, I am also very interested in distributed computing, P2P, Web Service, and J2EE technologies. At the same time, I also have some experiences in project implementation, team management, and project management, hoping to fight with meBoth Technology and ManagementThe young generation on the front can communicate with me a lot. My MSN is: haoel@hotmail.com (commonly used), QQ is: 753640 (not commonly used ). (Note: Do not send emails to my MSN mailbox. Due to Hotmail spam, I reject all emails from this mailbox)
Finally, I would like to introduce the design developers of the make program.
First:Richard Stallman
The leaders and pioneers of Open Source Software have never received a one-day salary and have never used a Windows operating system. I don't need to say much about his deeds, his software, and his thoughts. I believe everyone is no stranger to this person. This is his homepage:Http://www.stallman.org/. Here, only one recent photo is posted:
Computers, music, and butterflies are his favorites.
The second digit is:Roland McGrath
The personal homepage is:Http://www.frob.com /~ Roland/Below are some of his stories:
1) developed and maintained the GNUmake
。
2) andThomas BushnellCompiled GNU Hurd together.
3) compile and maintain the gnu c library.
4) write and maintain part of GNU Emacs.
Here, I would like to express my sincere respect to the two open-source project fighters.
<-Previous Page
(All Rights Reserved. Please indicate the author and source when reprinting)
(Full text)I welcome any form of communication, whether it's about technology, management, or other things. I don't care about politics and entertainment news. I welcome anything that is positive!