Go deep into PHP kernel 4 (Automatic Build System)

Source: Internet
Author: User
<title></title>

PHP provides a flexible automatic build system that stores all modules in the ext subdirectory. Each module has its ownSource codeAlso has a config. M4 file to configure the extension (see http://www.gnu.org/software/m4/manual/m4.html for details ).

All files, including. cvsignore, are automatically generated by the ext_skel script in the ext directory. The parameter is the name of the module you want to create. This script creates a directory with the same name as the module, which contains some files corresponding to the module.

The procedure is as follows:

:~ /CVS/PhP4/ext:>./ext_skel-extname = my_module
Creating directory my_module
Creating basic files: config. M4. cvsignore my_module.c php_my_module.h credits experimental tests/001. phpt my_module.php [done].

To use your new extension, you will have to execute the following steps:

1. $ CD ..
2. $ vi ext/my_module/config. M4
3. $./buildconf
4. $./configure-[with | enable]-my_module
5. $ make
6. $./PHP-f ext/my_module/my_module.php
7. $ vi ext/my_module/my_module.c
8. $ make

Repeat steps 3-6 until you are satisfied with ext/my_module/config. M4 and
Step 6 confirms that your module is compiled into PHP. Then, start writing
Code and repeat the last two steps as often as necessary.

These commands generate the files mentioned above. To enable automatic configuration file and buildProgramContains new modules. You need to run the buildconf command again. This command will re-generate the configure script by searching the ext directory and searching for all the config. M4 files. By default, the config. M4 file is shown in Example 3-1, which may be slightly complicated:

Example3.1DefaultConfig. M4File

DNL $ ID: Build. XML, v 1.1 16:27:06 Goba exp $
DNL config. M4 for extension my_module

DNL comments in this file start with the string 'dnl '.
DNL remove where necessary. This file will not work
DNL without editing.

DNL if your extension references something external, use:

DNL php_arg_with (my_module, for my_module support,
DNL make sure that the comment is aligned:
DNL [-with-my_module include my_module support])

DNL otherwise use enable:

DNL php_arg_enable (my_module, whether to enable my_module support,
DNL make sure that the comment is aligned:
DNS [-enable-my_module enable my_module support])

If test "$ php_my_module "! = "No"; then
DNL write more examples of tests here...

DNL #-with-my_module-> check with-Path
DNL search_path = "/usr/local/usr" # You might want to change this
DNL search_for = "/include/my_module.h" # you most likely want to change this
DNL if test-r $ php_my_module/; then # path given as parameter
DNL my_module_dir = $ php_my_module
DNL else # search default path list
DNL ac_msg_checking ([For my_module files in default path])
DNL for I in $ search_path; do
DNL if test-r $ I/$ search_for; then
DNL my_module_dir = $ I
DNL ac_msg_result (found in $ I)
DNL fi
DNL done
DNL fi
DNL
DNL if test-z "$ my_module_dir"; then
DNL ac_msg_result ([not found])
DNL ac_msg_error ([Please reinstall the my_module distribution])
DNL fi

DNL #-with-my_module-> Add include path
DNL php_add_include ($ my_module_dir/include)

DNL #-with-my_module-> chech for lib and symbol presence
DNL libname = my_module # You may want to change this
DNL libsymbol = my_module # you most likely want to change this

DNL php_check_library ($ libname, $ libsymbol,
DNL [
DNL php_add_library_with_path ($ libname, $ my_module_dir/lib, my_module_shared_libadd)
DNL ac_define (have_my_modulelib, 1, [])
DNL], [
DNL ac_msg_error ([wrong my_module lib version or lib not found])
DNL], [
DNL-L $ my_module_dir/lib-lm-LDL
DNL])
DNL
DNL php_subst (my_module_shared_libadd)

Php_new_extension (my_module, my_module.c, $ ext_shared)
Fi

If you are not familiar with M4 files (there is no doubt that it is a good time to be familiar with M4 files), you may be confused. But don't worry. It's actually very simple.

Note: Comments with DNL prefixes are not parsed.

The config. M4 file resolves the configure command line options during configuration. This means that it will check the required external files and do some similar configuration and installation tasks.

The default configuration file generates two configuration commands in the configure script:-with-my_module and-enable-my_module. Use the first option when you need to reference an external file (just like using the-with-Apache command to reference the Apache directory ). The second option allows you to easily decide whether to enable the extension. No matter which command you use, you should comment out another one. That is to say, if you use-enable-my_module, you should remove-with-my_module. And vice versa.

By default, the config. M4 created through ext_skel can receive commands and the extension is automatically enabled. Enabling the extension is done through the macro php_extension. If you want to change the default situation and want users to explicitly use-enable-my_module or-with-my_module commands to include extensions in PHP binaries, set "If test" $ php_my_module "! Change = "no" to "If test" $ php_my_module "=" yes.

If test "$ php_my_module" = "yes"; then DNL
Action .. php_extension (my_module, $ ext_shared)
Fi

This causes the user to use the-enable-my_module command every time PHP is reconfigured and compiled.

Note that you need to run the buildconf command again after modifying the config. M4 file.

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.