Update the library file using the make -----------
The library file is also a package file for the Object file (intermediate file compiled). Under UNIX, it is generally made by the command "AR" to complete the package.
First, the member of the library file
A library file consists of multiple files. You can specify a library file and its composition in the following format:
Archive (MEMBER)
This is not a command, and a definition of a goal and dependencies. In general, this usage is basically to serve "AR" commands. Such as:
FOOLIB (HACK.O): Hack.o Ar Cr Foolib Hack.o
If you want to specify multiple member, then separate space, such as:
FOOLIB (Hack.o Kludge.o)
It is equivalent to:
FOOLIB (Hack.o) Foolib (Kludge.o)
You can also use the shell's file wildcard to define, such as:
FOOLIB (*. o)
Second, the implicit rules of the function library member
When the Make search for an implicit rule, a special feature is that if this goal is "a (m)" form, it will turn the target "(m)". So, if our member is "% .o" mode definition, and if we use "make foo.a" to call Makefile form, the implicit rule will go to "bar.o" rules. If there is no rule of bar.o, then the internal implicit rules take effect. Make will go to Bar.c file to generate bar.o. If you find it, the command executed by Make is as follows:
Cc -c bar.c -o bar.o ar r foo.a bar.o rm -f bar.o
There is also a variable to pay attention to "$%", which is an automated variable of the exclusive library file. For its instructions, see the Automation Variables.
Third, the suffix rule of the function library file
You can use the Suffix Rules and Incontrol Rules to generate a log library package file, such as:
.c.a: $ (cc) $ (cflags) $ (cppflags) -c $ <- 6 *. o $ (ar) R $ @ $ *. o $ (rm) $ *. o
It is equivalent to:
(% .O):%. C $ (cc) $ (cppflags) -c $ <-o $ *. o $ (ar) R $ @ $ *. o $ (rm) $ *. o
Fourth, pay attention
Carefully use the Make's parallel mechanism ("-j" parameter) when performing a function library packaging file. If multiple ar commands run on the same function library package at the same time, you can damage this library file. Therefore, in the future version of the Make, a mechanism should be provided to avoid parallel operations to occur on a function package file.
But as far, you should not try not to use the "-j" parameter as much as possible.
Subsequent sequence -
Finally, when I wrote a concclusion, the above basically is all the details of GNU Make's makefile. The Make's Make is basically like this, no matter what kind of make, it is based on the dependence of documents. It is basically following a standard. 80% of the technical details in this document apply to any make, I guess the content of the "function" may not be supported by other make, and I think different makers will have different implementations. I have no energy to view the GNU's make and VC's nmake, BCB Make, or what difference is made under other Unix, one is not enough, the second is because I basically use it under UNIX. Make, previously in Sco Unix and IBM AIX, now in Linux, Solaris, HP-UX, AIX, and Alpha, LINUX and Solaris are more. However, I can be sure that Make under UNIX, whether it is a platform, almost all the Make and CC / GCC compilers developed by Richard Stallman, and basically all GNU Make (all The UNIX machine is installed on the GNU, so there are more programs that use the GNU). The GNU's thing is still very good, especially after use, more and more sense of the power of the GNU software, and more and more feel that GNU is "killed" in the operating system (mainly Unix or even windows). For all the details of all the makers, we can not only use the Make tool to compile our programs, but also use Make to complete other work, because the commands in the rules can be under any shell, so in Unix You don't necessarily just use the compiler of the program language, you can also write other commands in Makefile, such as: Tar, AWK, Mail, Sed, CVS, Compress, LS, RM, YACC, RPM, FTP ..., etc. , Etc., to complete the function, file operation, file management, file operation, file management, file operation, and file management, such as "Program Packaging", "Program Backup", "Production Program Installation Pack", "Submit Code", "User Template", "Merge File", etc. Programming development design, or some other whimsical things. For example, when you write a bank trading process, because the bank's trading procedure is basically the same, you will see some general program templates for some transactions, and write some network communication, database operation, business operation. In one file, in these files, in these files, such as "@@ n, ### n" strange string labeled some locations, then write a transaction, just writing a specific process according to a specific rule, and finally When Make, use awk and sed to replace the "@@ n, ### n" in the template to a specific program, form a C file, and then compile. This action is very similar to the "extended C" language of the database (ie, "Exec SQL" in the C language executes the SQL statement. Before compiling CC / GCC, you need to use "extended C" translation, such as CPRE, It translates into standard C). If you have some more wonderful methods when using Make, please remember to tell me.
Looking back, look at the whole document, I don't think I have just started to develop in Unix a few years ago, someone asked if I would not write Makefile, I didn't know what to say. At first, I saw that someone turned "! Make" after writing the program in the VI, I thought it was the function of VI. Later, I learned that there was a makefile in my monster, so I checked it. At that time, I didn't want to read English, I found it. Introducing Makefile if there is no Chinese documentation, I have to see Makefile written by others, I have accumulated a little knowledge, but in many places, I don't know if I don't know. Later, I started working on UNIX product software. I saw a 400-year-old year, nearly 2,000 lines of code, I found that it is necessary to compile such a huge thing. If there is no Makefile, how horror is the same. So I came to my heart, I read a bunch of English documents, I feel that I have mastered it. But it is found that the article is still so pitiful, so I want to write such an article, share it for everyone, I hope to help you. Now I finally finished, I saw the creation time of the document, and this technical document has also been written for more than two months. I found that I know it is a matter, I have to write down, telling others is another thing, and now there is no time to study technology details, so when I write, it is difficult to explain some details. Doing rigorous and refined, and telling what you are telling what you first say, it is still referring to some foreign sites, and the language style of some technical books is completed. The outline of the entire document is written by the Outline of the GNU-based Makefile Technical Manual and combines its own work experience and its own learning. Because there is never written such a long, such a thin document, there will be many places where there is a problem, language ambiguity or error. Because of some, I am in urgent to wait to give me an indication and suggestion, as well as any feedback.
Finally, use this in this back, introduce yourself. I have currently engaged in software development under all UNIX platforms, mainly to do distributed computing / grid computing system product software, and I am very interested in the next-generation computer revolution - grid computing, for distributed calculations , P2P, Web Service, J2EE technical direction is also very interesting, and at the same time, for project implementation, team management, project management is also small, I hope to fight the young generation on the "technology and management of" technology and management ", A lot of exchanges with me. My MSN is: haoel@hotmail.com (common), QQ is: 753640 (not common). (Note: Do not send me MSN's mailbox, because Hotmail's spam causes me to refuse this mailbox.)
In the end, I also want to introduce the design and developer of the Make program. The first rush is: Richard Stallman
Open source software leaders and pioneers have never received a day of salary, never used a Windows operating system. For his deeds and his software and his thoughts, I don't have to say too much, I believe that everyone is not strange to this person, this is his home page: http://www.stallman.org/. Only a recent photo is posted here:
Computer, music, butterfly is his favorite
The second is: Roland McGrath Personal Homepage is: http://www.frob.com/~roland/, below is some of his deeds: 1) Cooperation and maintain GNU Make.
2) Write GNU Hurd with Thomas Bushnell.
3) Write and maintain GNU C Library.
4) Cooperation and maintain part of GNU Emacs.
Here, the fighter of the two open source projects is the most authentic tribute.
<- Previous page (copyright, please indicate the author and the author) (full text)
I welcome any form of communication, whether it is discussing technology or management, or other hairdryerous things. I don't care about politics and entertainment news, other things I am welcome!