Differences and applications between vpath and vpath

Source: Internet
Author: User

In Linux operating system management, make commands are often used to compile some source code. Such as kernel upgrade and driver installation. The usage skills of this command have been quite common. However, what I want to talk about here is a detail ignored by everyone, that is, the difference between vpath and Its Application in the make command.
1. enable the system to automatically retrieve and find the file to the dependency.

When using the make command to compile large projects, a large number of source files are often involved. This project may contain multiple administrators, which are stored in different directories of the system. At this time, you need to specify the file dependency during compilation. Although it can be specified in the preparation file, this is not the best method. Because once the source code changes, you need to change the configuration file. Therefore, we need to find a simpler and more flexible method. In Linux, this requirement is easily implemented. Because you can specify a path for the make command, the dependency of the file is automatically searched in the relevant directory. In this case, you do not need to change the preparation file as long as the directory where the source code is stored remains unchanged. Therefore, this method can simplify the compilation of the make command.

2. Use vpath to define the search path.

In Linux, there is a path environment variable. When you enter a command, the operating system searches for the command in the path specified by this environment variable. If not, an error message is displayed. In the make command, there is a similar parameter called vpath. This variable is used to specify the path for the make command search. If you do not specify this vpath, The make command will only search for the dependent and target files in the current directory. However, if you define this variable, the command first looks for the dependent and target files in the current directory. If it cannot be found in the current directory, it will be automatically searched from the path defined by the vpath variable.

You can define multiple paths in this variable. The root path of the definition rule of this variable has the same and different definitions. In the same place, multiple paths can be defined at the same time, and the paths are separated by colons in the English state. There is also a big difference between the two. For example, when defining the PATH variable, it is required to determine the path. When defining the vpath variable, you can use the decision path or relative path. For example, ../source. This directory definition method (using relative paths) is not allowed when defining PATH environment variables. However, it is allowed to define the vpath variable here. When using this variable, pay attention to this small detail. It is easier to use relative paths for representation. In addition, when the entire large folder is moved to another location, the previously defined relative path is still valid. Therefore, we recommend that you use relative paths when using relative paths.

3. Use vpath to define the search path and matching mode.

Using the vpath variable to define the path, we can see that it only defines a search path, but does not define a matching file. For example, in a directory, apart from the source code file, there are many instructions. If you judge all the files (including some instructions) during the search, the system Compilation Time will undoubtedly be increased. For this reason, the system administrator must not only specify the path to search for the make command, but also specify the matching mode. That is, search for the conditions of the symbol. The most common is to specify the file to the extension. This search is more targeted, and the compilation speed will be much faster. For example, the system administrator wants the make command to find the file ending with. h In the specified path. To achieve this, you need to use another variable vpath. Note that the vpath in upper case is in lower case, which is similar to the vpath in upper case, but is more powerful than the vpath in upper case.

This vpath variable is similar to the vpath variable. It is also used to specify the directory for the make command to find the file dependency. However, this variable is more flexible. In addition to specifying the directory for file search, you can also set the matching mode. Depending on the parameters, this command is mainly used to complete three tasks.

First, if no parameter is included, it is a vpath baton commander, not indicating that the current vpath variable is used. It is used to clear all configured file search directories. Note that it clears the search path set by the vpath command without affecting the search path set by the vpath variable. System Administrators should not be fooled by their appearance. Remember that the two variables are different, although the names are the same.

The second is to include a parameter pattern, such as vpath %. h. At this time, the system will clear the search path of the files that match the pattern. For example, the system administrator may create multiple search policies at the same time, such as. C and. h. In this form, only the matching search path is deleted. It does not affect the search path of other modes.

Third, there are two parameters, such as vpath %. h .. (this command indicates finding. H files in the parent directory ). If both parameters (matching mode and file search path) are included, it means to search in the specified mode in the specified directory. However, it should be noted that a schema corresponds to a statement. That is to say, define a matching pattern in a vpath statement. If you want to define multiple matching modes, the best way is to use the vpath statement continuously to specify different search policies. However, if the mode is the same, the original definition will be updated during the second definition. That is to say, the relationship between the two is replacement, not append. To solve this problem, if you need to search for multiple paths in the same mode, either define multiple paths in one statement or copy them to the same folder. It is generally better to copy files in the same mode to the same folder for convenient management. Only projects that are particularly complex can be saved in folders based on their purposes or modules.
However, there are some differences in RedHat Linux systems. In this version of Linux, multiple paths can be defined in the same mode. Such as vpath %. h All, vpath %. h Bll, vpath %. h CLL, and so on. In this case, the preceding definition is not overwritten. That is, the three statements are independent, and the variables defined by the three statements are valid. When the system finds the file ending with. H, it searches for the file according to the time sequence defined by the vpaht variable. Search for the folder all first, then find Bll, and then find CLL. If one of the three directories has the same file, the make command will take the file in the first directory as the standard.

From the above analysis, we can see that the two variables vpath and vpath are two different variables. Similar functions: You can specify the path to search for file dependencies. However, vpath features a little more powerful and can be searched by mode, that is, further subdivided. Therefore, you can determine whether to use vpath or vpath Based on the file size and project size.

4. Notes for using these two variables.

When using these two variables, note that you do not need to specify the current directory in the variables. In defining the PATH environment variable, you can see that the current directory (. indicates the current directory) is added at the end ). However, when defining these two variables, you do not need to add them. By default, logtail searches the current directory first. Only when the corresponding file cannot be found in the current directory will the two variables be searched in the specified path. When multiple paths exist, they are searched in the order defined in the path sequence. For this reason, I need a special system function. The path environment variable puts the current directory in the final search, while the vpath and vpath give priority to the current directory.

Second, for the vpath and vpath variables, the relative path can be used to represent the search path. In addition, the adoption of relative paths is more appropriate in terms of convenience and portability. However, this is not absolute. It depends on the actual situation of the project and the user's operation habits. However, from my personal preferences, I still like to adopt relative paths. At the same time, you must keep in mind that relative paths cannot be used when defining PATH environment variables, and absolute paths must be used.

Note the case sensitivity of the two variables. If you want to match the pattern in the search process, you must use a lower-case vpath. Otherwise, you must use an upper-case vpath. If Zhang guanli Dai is used, it may have some adverse effects. The make command is a source code compilation command that must be mastered by the system administrator. This command is not only required for compiling applications, but also for Kernel upgrade. Therefore, programmers and administrators must have a deep understanding of this command.

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.