Makefile & shell

Source: Internet
Author: User

The following are all from network collection. I sorted it out myself and only sorted out some things that I was not familiar with before, but will be used now:
I. Definition of variables in makefile:
1. recursive expansion: the variables defined by recursive expansion are replaced when the variable is referenced. That is, if the variable contains applications for other variables, when this variable is referenced, all embedded variables are expanded at one time. Although this type of variable can well complete user instructions, it also has serious disadvantages, if the content cannot be appended to the variable (because the statement: cflags
= $ (Cflags)-O may lead to infinite loops During Variable Expansion ).
2. Simple Method. Defined by: =. To avoid the above problems, the value of a simple extended variable is expanded at the definition and only once. Therefore, it does not include any reference to other variables, thus eliminating nested references of variables.
3. Use? = Defines a variable. It means that if the variable is not defined, that is, if the user does not define it, it is provided to him by default.

Examples show the differences between recursive expansion and simple mode definition:

Cflags: =-wallcflags :=$ (cflags) All: Echo $ (cflags) for the above makefile, execute make and echo the output-wall cflags =-wall cflags =$ (cflags) ALL: Echo $ (cflags): makefile: 2: *** recursive variable 'cflags

Main predefined variables of GNU make:

Predefine variable meaning

$ * The name of the target file that does not contain the extension.

$ + All dependent files are separated by spaces and appear sequentially, which may contain repeated dependent files.

$ <Name of the first dependent file.

$? All dependent files are separated by spaces. The modified date of these dependent files is later than the object creation date.

$ @ Full name of the target.

$ ^ All dependent files are separated by spaces and do not contain duplicate dependent files.

$ % If the target is an archive member, this variable indicates the name of the target archive member. For example, if the target name

For mytarget. So (image. O), $ @ is mytarget. So, and $ % is image. O.

The name of the Ar archive maintenance program. The default value is ar.

Arflags archive maintenance program options.

The name of the as assembler. The default value is.

Asflags assembler options.

The name of the cc c compiler. The default value is CC.

Ccflags C compiler options.

Name of the cpp c pre-compiler. The default value is $ (CC)-E.

Cppflags C pre-compiled options.

The name of the cxx C ++ compiler. The default value is g ++.

Cxxflags C ++ compiler options.

The name of the FC Fortran compiler. The default value is f77.

Fflags Fortran compiler options.


Reference: http://www.aka.org.cn/Lectures/001/Lecture-1/make.html

Http://hi.chinaunix.net /? Uid-14782631-action-viewspace-itemid-10165

Http://www.sudu.cn/info/html/edu/20080407/264139.html

Http://blog.csdn.net/lijierson8/article/details/6283040

Http://www.worldhello.net/doc/makefile_howto/makefile_howto.mm.htm

Classic shell Tutorial: Linux Shell scripting with Bash-translation of Ken O. brutch

Use Bash to write Linux Shell script-6. Expression

Http://blog.csdn.net/fox_lht/article/details/5894940


Chen Hao column:

Http://blog.csdn.net/haoel

Http://coolshell.cn/

Classic makefile Tutorial: Write makefile with me

Http://blog.csdn.net/haoel/article/details/2886 (http://www.chinaunix.net/jh/23/408225.html)

+

Http://wenku.baidu.com/view/4a171e6a25c52cc58bd6be6b.html

Common GCC compilation options: optimized options

Http://blog.csdn.net/iterzebra/article/details/6203067

Related Article

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.