Nginx source code analysis (3)-Automatic script

Source: Internet
Author: User

Nginx automatic script refers to the configure script program and the script program under the auto sub-directory. Automatic scripts perform two tasks: checking the environment and generating files. Two types of files are generated: makefile files required for compiling code, and C code generated based on the Environment check results. The generated makefile is very clean and easy to read. The generated C code has three files. ngx_auto_config.h is some macro definitions declared based on the results of the Environment check. This header file is included in ngx_core.h, so it will be referenced by all source codes, this ensures that the source code is portable. ngx_auto_headers.h is also a macro definition, but it is a statement about the existence of system header files. ngx_modules.c is the declaration of modules that are included in the system by default, if you want to remove some modules, you only need to modify this file.

Configure is the total driver of automatic scripts. It combines script programs with different functions in the auto directory to perform Environment check and file generation tasks. The Environment check consists of three parts: Compiler version and support features, operating system version and support features, and third-party library support, the checked script programs are stored in three subdirectories: Auto/CC, auto/OS, and auto/lib. The check method is interesting. You can use automatic compilation to check the code snippets of a feature and determine whether the feature is supported based on the compiler output. According to the check, if the environment is sufficient to support running a simple version of nginx, makefile and C code will be generated, and these files will be stored in the newly created objs directory. Of course, it may also fail. if the system does not support PCRE and SSH, if the related modules are not blocked, the automatic script will fail.

The script functions in the auto directory are clearly divided, including checking the environment, checking the module, and providing help information (. /configure -- Help). Some scripts are designed to process Script Parameters purely for modular automatic scripts. For example, feature scripts are used to check single features, other environment check scripts call this script to check a feature. Some scripts are used to output information to the generated file, such as have, nohave, make, and install.

The reason why I want to talk about automatic scripts in source code analysis is that the nginx automatic scripts are not generated by tools such as Autoconf, but manually written by the author and contain certain design components, for those who need to write automatic scripts, there is a high reference value. Here is just a rough introduction. It is best to read these scripts in detail. These scripts do not use many uncommon syntaxes and are quite readable.

BTW, followed by the real source code analysis phase. There are many struct in the nginx source code, and the references between these struct are also frequent. It is difficult to clearly express the relationship in words, I think it is the best way to use charts. Therefore, we need to master an efficient and flexible drawing method. I chose graphviz, a cross-platform Graph Generation Tool contributed by at&t, by writing a script language called "The dot language", you can use the dot command to directly generate a graph in the specified format, which is very convenient.

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.