Differences between export in shell and makefile

Source: Internet
Author: User

In shell, you can use export to modify the environment variables of the current process. For example,
Export Path =.: $ path
You can add the current path to the executable file search path, so that you do not need to press "./excutable" to execute the excutable in the current path. You only need to type "excutable.

Make can execute shell commands, including export. The Make syntax also contains the export operator. In this way, in the same makefile, the two exports may follow completely different syntaxes, such as shell syntax and make syntax. Their functions are completely different.

1) Shell export in makefile

The title indicates that export is a shell command. It is usually contained in makefile rules and becomes a part of a rule's command line ). For example:
Init:
Export DEBUG = 1
......
...
Run: init
./MyApp

The first init rule is intended to set the environment variable DEBUG = 1 (maybe the author wants to run the program myapps in debug mode later ). However, the above rules did not play the role that the author wanted: For the apps started later, debug has not changed. Why?

First, the above export line is the shell command; for each line of shell command, make will start a new process to execute this line of shell command. Because the environment variables of the newly started child process are completely irrelevant to the parent process, the export cannot change the environment variables of the parent process, nor can it change the child processes started after the parent process, or the environment variable of the "younger brother process.

The correct statement should be:
Run:
Export DEBUG = 1 &./MyApp
Or:
Run:
Env DEBUG = 1./MyApp

2) make export in makefile

As mentioned above, the title indicates that the export here is the operator in the make syntax. It is usually used to send variables to backward make processes (these later make processes are started by the current make process. For example:
Recursively_build:
$ (Make)-c arch/src/arch = x86_64

The arch variable is a key switch variable in the file ARCH/src/makefile. It determines which architecture source file will be compiled.

To pass the variable arch to the sub-make process that will process ARCH/src/makefile, use export:
Export Arch
The variable arch from the export here inherits the quilt make process.

 

==============================

[Summary]

1. Variables export out in makefile (in the upper-layer). Sub makefile (sub make) is accessible.

2. while makefile of the same level (you can view the levlel of the current makefile by using the built-in variable makelevel in makefile) cannot pass variables through export, that is, a variable export export in a makefile, in another makefile at the same level, it cannot be accessed/obtained.

3. The export in makefile exports the variable to the sub-makfile, and the export in the action executed by the target belongs to the export in shell, which exports the variable to the current shell. The two exports have different functions.

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.