Write with Me Makefile (14) _makefile

Source: Internet
Author: User

Update a function library file with make
———————————

The function library file is the packaged file for the object file (the intermediate file that the program compiles). Under UNIX, it is generally the command "AR" to complete the packaging work.

A member of a function library file

A function library file consists of multiple files. You can specify the function library file and its composition in the following format:

Archive (Member)

This is not a command, but a definition of a goal and a dependency. Generally speaking, this usage is basically for the "ar" command to serve. Such as:

Foolib (HACK.O): HACK.O
AR cr foolib HACK.O

If you want to specify more than one member, it is separated by a 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)


Ii. implicit rules for function library members

When make searches for an implied rule for a target, a special feature is that if the target is "a (m)", it will change the target to "(m)". Thus, if our members are "%.O" schema definitions, and if we invoke makefile using the form "Make FOO.A (BAR.O)", the implied rule will look for "BAR.O" rules, If the BAR.O rule is not defined, then the built-in implied rule takes effect, and make will find the Bar.c file to generate BAR.O and, if found, the commands to execute are roughly as follows:

Cc-c Bar.c-o BAR.O
AR R foo.a bar.o
Rm-f BAR.O

Another variable to note is "$%", which is an automation variable for the proprietary function library file, see the "Automation variables" section for instructions.


Third, the function library file suffix rules

You can use "suffix rules" and "implied rules" to generate function library packaging files, such as:

. C.A:
$ (CC) $ (cflags) $ (cppflags)-C $<-O $*.O
$ (AR) R $@ $*.o
$ (RM) $*.O

It is equivalent to:

(%.O):%.c
$ (CC) $ (cflags) $ (cppflags)-C $<-O $*.O
$ (AR) R $@ $*.o
$ (RM) $*.O


Iv. Matters of note

Be careful to use the parallel mechanism of make (the "-j" parameter) when you are building the library packaging file. If more than one AR command runs at the same time on the same function library package file, it is possible to corrupt this function library file. Therefore, in make future releases, you should provide a mechanism to prevent parallel operations from occurring on the function packaging file.

But for now, you should not try not to use the "-j" argument.

Post-order
——

Finally, it's time to write a closing, which is basically all the details of the GNU make makefile. Other producers of make is basically the case, no matter what make, are based on the dependence of the file, its basic is to follow a standard. 80% of the technical details in this document apply to any make, I guess the contents of the "function" chapter may not be supported by other make, and in implied rules, I think different makes would have different implementations, and I have no energy to view GNU make and VC nmake, What is the difference between BCB make or other Unix make, one is not enough time, and two is because I basically use make on Unix, formerly in SCO UNIX and IBM AIX, now in Linux, Solaris, HP-UX, Aix and Alpha are used under Linux and Solaris a little more. I'm sure, however, that make on UNIX, no matter what platform, uses almost all of the make and CC/GCC compilers developed by Richard Stallman, and It's basically GNU make (all UNIX machines in the company are loaded with GNU stuff, so there are a few more programs using GNU). The GNU thing is still very good, especially after a deep use, and increasingly feel the GNU software is strong, but also increasingly feel the GNU in the operating system (mainly UNIX, even Windows) "lethality."

For all of the details above, we can use make to compile our programs, and make to do other things because the commands in the rules can be commands under any shell, so, on Unix, You don't necessarily just use the compiler for programming languages, you can also write other commands in makefile, such as tar, awk, mail, sed, CVS, compress, LS, RM, YACC, RPM, FTP ... Wait, and so on, to complete a wide variety of features such as "Program Pack", "program Backup", "Make program installation package", "Submit Code", "Use program template", "merge file" and so on, file operation, file management, programming development design, or some other whimsical things. For example, when writing a bank-trading procedure before, as the bank's trading procedures are basically the same, you can see someone wrote a generic program template for some transactions, in which some network communications, database operations, business operations Common things in a file, in these files, such as "@@@n, # # #N" Strange strings to mark some positions, and then write a transaction, just follow a specific rule to write specific processing, and finally make, use awk and sed, the template "@@@n, # # #N" and other strings into a specific program, form C file, and then compile. This action is much like the "Extended C" Language of the database (that is, executing SQL statements in the language of "EXEC SQL" in C, and you need to use the "Extended C" translation program, such as CPRE, to translate it into standard C before you compile with CC/GCC. If you have some more wonderful ways to use make, please remember to let me know.

Looking back at the entire document, I do not remember a few years ago just started under the UNIX development, when someone asked me will not write makefile, I have two eyes straight, do not know what to say. In the beginning to see someone in the VI to write the program after the input "!make", but also thought to be the function of VI, then know that there is a makefile in mischief, so the Internet check, then did not want to see English, found that there is no Chinese document introduction makefile, Have to see other people write makefile, their blind touch to accumulate a little knowledge, but in many places is completely aware of the reason why. Later began to engage in the development of software products under UNIX, to see a 400-man, nearly 2 million lines of the big project, found to compile such a behemoth, if not makefile, it would be so horrible thing ah. So he came down and read a pile of English documents, and felt that he had mastered it. But found that the current online makefile to introduce the article is still so poor, so want to write such an article, sharing to everyone, I hope to help you.

Now that I've finished, I've looked at the file creation time, and this technical document has been written for two months. found that it is one thing to know, to write down, to tell others is another thing, and, now more and more do not have time to study technical details, so in writing, it is difficult to explain some of the details of the precise and concise, and what to say after what is not very clear, so, or the reference to some foreign sites on the information and problems, as well as some technical books of language style, to be completed. The outline of the entire document is based on the outline of the GNU Makefile Technical Manual, combined with its own work experience and its own learning process. Because I have never written such a long, so fine document, so there must be many places to express problems, language ambiguity or error. For some reason, I have to wait for you to give me indications and suggestions, as well as any feedback.

Finally, or use this after the second, introduce yourself. I am currently engaged in software development under all UNIX platforms, mainly for distributed computing/Grid computing system product software, and I for the next generation of the computer revolution-Grid computing is very interested in distributed computing, Peer-to-peer, Web Service, Java technology Direction is also very interested in At the same time, for project implementation, team management, project management is also a small experience, I hope that the same fight with me in the "technology and management" on the front of the younger generation, can communicate with me a lot. My MSN is: haoel@hotmail.com (commonly used), QQ is: 753640 (not commonly used). (Note: Please do not give me MSN Mail letter, due to Hotmail spam caused me to reject all letters of this mailbox)

Finally, I would also like to introduce the design developer of make program.

First and foremost: Richard Stallman

The leader and pioneer of open source software never paid a day's wages and never used the Windows operating system. For his deeds and his software and his ideas, I do not need to say too much, I believe that everyone is not stranger to this person, this is his homepage: http://www.stallman.org/. Here is only a recent photo of him:


Computer, music, butterflies are his favorites.

The second place is: Roland McGrath

Personal homepage is: http://www.frob.com/~roland/, here are some of his deeds:

1) collaborated in the preparation and maintenance of GNU make.

2) and Thomas Bushnell wrote the GNU Hurd together.

3 Write and maintain the GNU C Library.

4 cooperation in the preparation and maintenance of a part of GNU Emacs.

Here, to the two open source project, the most sincere tribute to the fighters.


(End of full text)

Source: http://blog.csdn.net/haoel/article/details/2899

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.