GNU Web
The GNU Web project is an enhancement to autoconf and automake. This is a collection of M4 macros and Perl utilities to automatically produce Makefile for software packages of non-native run-times:
The current release 0.2.0 supports:
- PHP runtime
- W3C complaint object such as javascripts, stylesheet, etc.
Introduction
The autotools is well-know tools for producing shell scripts that automatically configure, build, and install software. These tools has build-in support for various native and non-native run-times such as C, C++, Erlang, Fortran, and many other. However, its do not support run-times mostly used for Web applications development. The support of additional run-time within the Autotools could be enabled through additional macros and Makefile rules.
The collection macroses provided by GNU Web project is an extension to autoconf and automake. You have to simply use macros within configure.ac and Makefile.am as the result your configure and build software through GNU Build System
./configure make make install
In addition to use cases supported by Autotools, this project supports:
- Check for programs required to build sources of non-native runtime.
- Check for libraries and other dependencies required to build and run non-native application.
- Write Makefile rules to enable runtime support via GNU Build System.
- Convert config.h into runtime complaint syntax.
- Defines additional directory variables.
- Supported VPATH enables parallel builds for development, staging and production environments.
- Rolling-out binaries as tarballs.
Writing configure.ac
A configure script for a software package is generated from configure.ac (See autoconf manual). Tedious coding of configure script becomes straight forward with help of GNU Web project, you have to just reference M4 macros following standard configure.ac layout:
Example: configure.ac
AC_INIT([package], [version], [bug-report]) AM_INIT_AUTOMAKE # # check for programs ACX_PREFIX ACX_PHP # # check for libraries ACX_CHECK_PHP_LIB([libxyz.php]) # # check for optional features ACX_FEATURE([fea]) # # define Makefile rules AMX_PHP # # output configuration AM_CONFIG_HEADER(config.h) AC_OUTPUT(\ Makefile \ src/Makefile \ ) ACX_DONENote: M4 macros provided by GNU Web project utilizes following prefixes:
- ACX_XXX expanded into sequence of shell operation used within configure script.
- AMX_XXX outputs Makefile rules
Check for programs (configure runtime)
The project defines a single macro to encapsulate sequence of actions, required to configure a runtime.
- Macro: ACX_PHP
- Checks for php, php-cgi programs and set corresponding variables; defines directory variables: libphpdir, wwwdir and staticdir.
- Macro: ACX_W3C
- Checks for either yuicompressor or jsmin; define directory variables: libjsdir.
Check for libraries (manage dependencies)
The following macros check for the precence of non-native runtime libraries and defines variable into config.h and Makefile.
- Macro: ACX_CHECK_PHP_LIB(library, [action-if-found], [action-if-not-found])
- Checks if library exists in default PHP path, libphpdir or nested packages. Defines Makefile and config.h variable HAVE_library
- Macro: ACX_CHECK_JS_LIB(library, [action-if-found], [action-if-not-found], [link-to-dir])
- Checks if library exists in libjsdir; defines Makefile and config.h variable HAVE_library; creates a symbolic link into link-to-dir (usefull feature for widget developers).
Define Makefile rules
The following macros encapsulate Makefile rules and outputs them into aminclude.am during software configuration. Later on aminclude.am referenced from Makefile via include directive.
- Macro: AMX_PHP
- defines rules to validate syntax of php files; index.php creation for web application; converts config.h into php syntax and assembles multiple files into php library.
- Macro: AMX_W3C
- defines rules to minify javascript and stylesheet files; converts config.h into javascript syntax and assembles multiple javascript/stylesheet files into single library.
- Macro: AMX_TARBALL
- define a new make target make tarball. In contrast to make dist, it creates a package-version-bin.tgz from all installable objects. The created package is usable for further installation across cluster nodes by single command tar -C / -xzvf package-version-bin.tgz
Helper macros
- Macro: ACX_PREFIX
- copies ${ac_default_prefix} into ${ac_prefix} if --prefix options is not defined.
- Macro: ACX_FEATURE
- defines a optional feature configurable via command-line options of ./configure --enable-feature. The macros performs routine to defines command line arguments, validates user input, define a Makefile and config.h variables.
- Macro: ACX_ROOT_PACKAGE
- helper script for nested package management
- Macro: ACX_PACKAGE
- helper script for nested package management
Output variable
Directory variables
We extends default folders hierarchy for software installation, that is denoted by GNU Coding Standards. The following variables specified the directory for non-native runtime packages installation. The default value of directory variables could be altered from command line arguments of configure script.
./configure --libdir=/var/local/lib wwwdir=/var/www/html Note: In contrast with default directory variables front dash symbols are skipped. Runtime dir variables are implemented via environment variables.
The directory variables could be referenced in make and automake scripts:
#Makefile.am www_DATA = index.html #Makefile copy: index.html cp $^ $(wwwdir)
PHP
- Variable: libphpdir
- The directory for installing PHP code libraries (default $libdir/php).
- Variable: wwwdir
- The directory for installing dynamic objects, accessible via web server (default $prefix/var/www)
- Variable: staticdir
- The directory for installing static objects, accessible via web server (default $wwwdir/static)..
W3C
- Variable: libjsdir
- The directory for installing Javascript code libraries (default of $libdir/js).
Other variable
- Variable: have_xxx
- automatically defined into Makefile and config.h for each configurable feature, library or nested package.
Configuration Header File
Source code pre-processor available in C allows conditional compilation to adapt they code depending on system configuration. Non-native runtime extends these possibility to perform code adaptation at runtime. GNU Build System scans system configuration and outputs result into config.h. GNU Web project has built-in mechanism to convert config.h file into format acceptable by non-native runtime.
PHP
Converts config.h into PHP class, where each #define macro is translated into static public variable:
<?php class libxyz { static public $PACKAGE_URL = ""; static public $PACKAGE = "xyz"; static public $PACKAGE_BUGREPORT = "..."; static public $PACKAGE_STRING = "xyz 1.0"; static public $VERSION = "1.0"; static public $PACKAGE_VERSION = "1.0"; static public $PACKAGE_TARNAME = "xyz"; static public $PACKAGE_NAME = "xyz"; ... static public $HAVE_FEA_XYZ = 1; } ?>
It enables a runtime check for desired configuration
if(libxyz::$HAVE_FEA_XYZ) print "Feature XYZ is on"; else print "Feature XYZ is off";
W3C
Converts config.h into javascript class, where each #define macro is translated into static public variable:
var libxyz = { PACKAGE_URL : "", PACKAGE : "xyz", PACKAGE_STRING : "xyz 1.0", PACKAGE_VERSION : "1.0", PACKAGE_TARNAME : "xyz", PACKAGE_BUGREPORT : "...", VERSION : "1.0", PACKAGE_NAME : "xyz", ... HAVE_FEA_XYZ : 1 }
It enables a runtime check for desired configuration
if(libxyz.HAVE_FEA_XYZ) alert("Feature XYZ is on"); else alert("Feature XYZ is off");