diff options
author | konablend <[email protected]> | 2009-03-10 23:22:24 +0000 |
---|---|---|
committer | konablend <[email protected]> | 2009-03-10 23:22:24 +0000 |
commit | 6a294a9fc3519114f283760ac39b33d70ae09406 (patch) | |
tree | 4b00d82f5d09cd2e5273567a47216c009ae4b7c1 | |
parent | 246cf371553c120192011d5c10274160b2d48156 (diff) |
BuildSystem: docs; new location for generated docs which we can point users to
- doc/BUILD-Mac
- doc/BUILD-Linux
- doc/BUILD-Cygwin
BuildSystem: doc cleanup
- dropped wiki autogen stuff; not compatible with project goals.
git-svn-id: svn://svn.handbrake.fr/HandBrake/trunk@2253 b64f7644-9d1e-0410-96f1-a4d463321fa5
-rw-r--r-- | doc/BUILD-Cygwin | 444 | ||||
-rw-r--r-- | doc/BUILD-Linux | 510 | ||||
-rw-r--r-- | doc/BUILD-Mac | 623 | ||||
-rw-r--r-- | doc/module.defs | 7 | ||||
-rw-r--r-- | doc/module.rules | 10 | ||||
-rwxr-xr-x | doc/xml2wiki.py | 387 |
6 files changed, 1582 insertions, 399 deletions
diff --git a/doc/BUILD-Cygwin b/doc/BUILD-Cygwin new file mode 100644 index 000000000..5bda0ae13 --- /dev/null +++ b/doc/BUILD-Cygwin @@ -0,0 +1,444 @@ +Guide to Building HandBrake svn2252 (2009031001) on Cygwin +********************************************************** + +Table of Contents +***************** + +1 Introduction +2 Prerequisites +3 QuickStart +4 Overview +5 Building via Terminal + 5.1 Checkout Sources + 5.2 Configure + 5.3 Build + 5.4 Make Targets + 5.4.1 Global + 5.4.2 General Modules + 5.4.3 Contrib Modules + 5.4.4 Contrib Touch and Untouch + 5.4.5 Contrib Aggregates + 5.5 Customizing Make +Appendix A Project Repository Details + + +1 Introduction +************** + +This guide documents the recommended process to build HandBrake on +Cygwin hosts from the official source-code repository. Building from +any other source is not supported. + +2 Prerequisites +*************** + +The following are the recommended specifications for building on +Cygwin; but is not necessarily the only configuration that is possible: + + * Intel 32-bit or 64-bit hardware (only 32-bit product binaries are + supported) + + * Cygwin, gcc 4.2.4 + + * yasm 0.7.2.2153 (for i386 or x86_64 architectures) + + Note: It is recommended to use the platform distribution's bundled + compiler for maximum C++ compatibility. If you build with a custom + compiler it will likely introduce non-standard runtime + requirements. There are of course many valid reasons to build with + unbundled compilers, but be aware it is generally unsupported and + left as an exercise to the reader. + + Note: As of this writing, Cygwin has available to it several + versions of gcc; only one of which may be found and used in the + path as `gcc' and `g++'. Configure will thus find what is probably + the older version of gcc in a typical Cygwin environment. If you + desire to build with the newer gcc, it is found in the path as + `gcc-4' and `g++-4' respectively and you must indicate to + configure the desired versions. The following syntax should do the + trick: + + ../configure --gcc=gcc-4 + +The following general tools are used on various platforms and it is +recommended you use these versions or similar: + + * subversion - 1.5.5 + + * python - Python 2.4.6 + + * curl - curl 7.19.3 (or wget) + + * m4 - GNU M4 1.4.6 + + * make - GNU Make 3.81 + + * patch - Patch 2.5.8 + + * tar - GNU tar 1.15.1 + + * wget - GNU Wget 1.11.4 (or curl) + +3 QuickStart +************ + +This chapter is for building from a terminal/shell environment in as +few commands as possible. Upon completion of the following commands you +should have a fresh build of HandBrake. Further instructions are +available beginning with *Note overview:: which describes procedures +suitable for repeating builds. This chapter should be skipped by those +seeking more than a minimalist build. + + svn checkout svn://svn.handbrake.fr/HandBrake/trunk hb-trunk + cd hb-trunk + ./configure --launch + +The special option `--launch' selects launch mode and performs the +following steps: + + * assert scratch directory `build/' does not exist + + * create scratch directory `build/' + + * change to directory `build/' + + * launch `make' + + * capture build output to `build/log/build.txt' + + * echo build output + + * print elapsed time + + * indicate if build ultimately succeeded or failed + +4 Overview +********** + +Cygwin builds are performed from a terminal. There is no support for +building from any IDEs. + +5 Building via Terminal +*********************** + +5.1 Checkout Sources +==================== + +Checkout HandBrake from the official source-code repository. + + svn checkout svn://svn.handbrake.fr/HandBrake/trunk hb-trunk + cd hb-trunk + +Sources are checked out from the `trunk' branch. This document was +generated from that very branch, and for example purposes, we will use +exactly the same branch. + +If you have write-access to the repository, then you may add the +appropriate login/password information as needed. It is recommended to +use Subversion 1.5.0 or higher. Lower versions should also work. + +5.2 Configure +============= + +Configure the build system. + + ./configure + +Configure will automatically create a scratch build directory `build' +unless you use GNU-style build procedures and first `cd' to a directory +other than top-level source. Additionally you may specify use `--build' +to specify the directory. The name of the directory is arbitrary but it +is recommended to use something which indicates transient files which +are not checked into the repository. + +The `configure' utility accepts many options. It is recommended that +you specify `--help' for the complete list of options. The following +options are also documented here: + +`--help' + List available options. + +`--src=DIR' + Specify top-level source directory for HandBrake sources. + +`--build=DIR' + Specify destination directory for final product install. The + default is to use either `build' if in the top-level source + directory, otherwise `.' + +`--prefix=DIR' + Specify destination directory for final product install. This + defaults to a reasonable platform-specific value. + +`--launch' + All-in-one option which launches the build and logs output + automatically. Useful for novices and quickstart procedures. + +`--disable-xcode' + Disable shunting the build through Xcode. If this option is + applied, `HandBrakeCLI' will be produced in a similare fashion as + it is on other platforms; sans Xcode. Mac OS X only. + +`--disable-gtk' + Disable building the GTK GUI on applicable platforms such as + Linux. + +`--debug=MODE' + Select debug mode. Must be one of `none', `min', `std', `max'. + This generally maps to gcc options `-g0', `-g1', `-g2', `-g3'. + +`--optimize=MODE' + Select optimize mode. Must be one of `none', `speed', `size'. + This generally maps to gcc options `-g0', `-O0', `-O3', `-Os'. + +`--arch=MODE' + Select build architecture. The available architectures vary by + platform. Most platforms support exactly one architecture except + Mac OS X which has support for various universal binary + architectures. The available choices are hard-coded per platform + and no sanity checks for the required tools are performed. + + +Clean-room procedures dictate that when certain factors change, old +builds should be scrapped and new builds configured. This is the main +reason for requiring a scratch directory; to promote consistent, +reliable and clean software builds. The following is a short list of +some of the reasons why someone may choose to scrap an existing build: + + * configure with different options + + * subversion working dir is updated and you want configure to + re-evaluate working dir metadata. + + * build corruption is suspected + +There are generally two methods for scrapping a build. The `build' +directory can be recusrively removed which has the effect of loosing +your existing configuration but does guarantee no residuals are left +behind. The other method is to ask the build system to perform an `make +xclean'. This is known to work well but will leave empty directories +behind. However, the configuration is left intact. + +5.3 Build +========= + +Build main product. All necessary dependencies are also built if +required. + + make + +Parallel builds may optionally be enabled. Be aware that while a +parallel build may save time on systems with additional cores, the +output is often mixed, overlapped and sometimes even corrupted with +binary characters. Thus if you experience a build issue, you should +clean and redo the build in default serial mode to produce a readable +log. The following command allows for up to 4 concurrent jobs via make: + + make -j4 + +5.4 Make Targets +================ + +The build system supports passing many kinds of targets some of which +become very useful in normal development cycles. The targets by +convention are lower-case words passed to `make'. Global targets are +one-word targets. Scoped targets are usually two-words seperated by a +period. + +5.4.1 Global +------------ + +`make' + Alias for `make build'. + +`make build' + Build main product. All necessary dependencies are also built if + required. + +`make clean' + Clean all build output excluding contrib modules. Configuration is + retained. + +`make install' + Perform final product(s) install. This will install build + products to a standard directory or one specified via `configure + --prefix' option. + +`make uninstall' + Perform final product(s) uninstall. This will uninstall any + products which may have been previously installed. + +`make xclean' + Clean all build output including contrib modules. Configuration is + retained. + +`make doc' + Build auto-generated project documentation. Various articles are + produced and may be found in `build/doc/articles'. + +`make report.help' + Print list of available makefile vars report targets. These + reports detail var definitions and expanded values used by the + build system. For experts only. + +`make report.all' + Convenience target which aggregates all reports. For experts only. + +5.4.2 General Modules +--------------------- + +General modules such as `libhb', `test' and `gtk' have the following +scoped targets: + +`make MODULE.build' + Build MODULE. + +`make MODULE.clean' + Clean build output for MODULE. + +5.4.3 Contrib Modules +--------------------- + +Contrib modules such as `a52dec', `bzip2', `faac', `faad2', `ffmpeg', +`lame', `libdca', `libdvdread', `libmkv', `libmp4v2', `libogg', +`libsamplerate', `libtheora', `libvorbis', `mpeg2dec', `x264', +`xvidcore' and `zlib' have the following scoped targets: + +`make MODULE.fetch' + Download source tarball from the Internet and save to + `TOP/downloads' directory. No checksumming is performed. + +`make MODULE.extract' + Extract source tarball into `build' tree. + +`make MODULE.patch' + Apply appropriate patches (if any) to module sources. + +`make MODULE.configure' + Configure module sources. This usually invokes autotool configure. + +`make MODULE.build' + Build module. This usually invokes autotool build. + +`make MODULE.install' + Install module products such as headers and libraries into `build' + tree. This usually invokes autotool install. + +`make MODULE.uninstall' + Uninstall module products; generally the reverse of install. This + usually invokes autotool uninstall. + +`make MODULE.clean' + Clean module; generally the reverse of build. This usually + invokes autotool clean. + +`make MODULE.xclean' + Extra clean module; first invokes uninstall then recursively + removes the module build directory. + +5.4.4 Contrib Touch and Untouch +------------------------------- + +Also available are some very granular targets which help force builds +from specific cycle points. The following targets are available to +touch and untouch the respective module target; this will force the +build system to treat the target as satisfied after a touch or +unsatisfied after an untouch: + + * make MODULE.extract.touch + + * make MODULE.extract.untouch + + * make MODULE.patch.touch + + * make MODULE.patch.untouch + + * make MODULE.configure.touch + + * make MODULE.configure.untouch + + * make MODULE.build.touch + + * make MODULE.build.untouch + + * make MODULE.install.touch + + * make MODULE.install.untouch + +5.4.5 Contrib Aggregates +------------------------ + +For convenience, the following targets aggregate the all contrib +modules' respective targets together: + + * make contrib.fetch + + * make contrib.extract + + * make contrib.patch + + * make contrib.configure + + * make contrib.build + + * make contrib.install + + * make contrib.uninstall + + * make contrib.clean + + * make contrib.xclean + +5.5 Customizing Make +==================== + +If the need arises to override settings in the build system +(essentially gnu-make variables) the recommended method is to create +optional include files which are automatically included if present and +follow this naming convention; Do not check these files into the +respository: + +`_SRC_/custom.defs' + Custom makevar definitions outside `build'. Suitable for settings + which apply across all builds for a particular checkout; or which + survives manual removal of `build'. + +`_SRC_/custom.rules' + Custom make rules outside `build'. Suitable for rules which apply + across all builds for a particular checkout; or which survives + manual removal of `build'. + +`_BUILD_/GNUmakefile.custom.defs' + Custom makevar definitions specific to a `build' directory. + +`_BUILD_/GNUmakefile.custom.rules' + Custom makevar rules specific to a `build' directory. + + +The purpose is to allow a place to store local build settings for +testing, tweaking, and experimenting with build configuration without +losing your settings if `configure' is invoked; ie: `configure' would +overwrite `GNUmakefile' and any customizations contained therein would +be lost. Here is a short example of what the contents of +`_SRC_/custom.defs' might contain: + + ## bump to gcc-4.2 in current path + GCC.gcc = gcc-4.2 + + ## replace optimize for 'speed' with more agressive settings + GCC.args.O.speed = -O3 -fomit-frame-pointer -msse4.2 + +See also `make report.help' which displays a set of reports used to +dump makefile vars. + +Appendix A Project Repository Details +************************************* + + url: svn://svn.handbrake.fr/HandBrake/trunk + root: svn://svn.handbrake.fr/HandBrake + branch: trunk + uuid: b64f7644-9d1e-0410-96f1-a4d463321fa5 + rev: 2252 + date: 2009-03-10 18:43:11 -0400 + type: developer + diff --git a/doc/BUILD-Linux b/doc/BUILD-Linux new file mode 100644 index 000000000..a6c3fb0cd --- /dev/null +++ b/doc/BUILD-Linux @@ -0,0 +1,510 @@ +Guide to Building HandBrake svn2252 (2009031001) on Linux +********************************************************* + +Table of Contents +***************** + +1 Introduction +2 Prerequisites +3 QuickStart +4 Overview +5 Building via Terminal + 5.1 Checkout Sources + 5.2 Configure + 5.3 Build + 5.4 Make Targets + 5.4.1 Global + 5.4.2 General Modules + 5.4.3 Contrib Modules + 5.4.4 Contrib Touch and Untouch + 5.4.5 Contrib Aggregates + 5.5 Customizing Make +Appendix A Project Repository Details + + +1 Introduction +************** + +This guide documents the recommended process to build HandBrake on +Linux hosts from the official source-code repository. Building from any +other source is not supported. + +2 Prerequisites +*************** + +The following are the recommended specifications for building on +Linux; but is not necessarily the only configuration that is possible: + + * Intel 32-bit or 64-bit kernel + + * Ubuntu 8.0.4, gcc 4.3.0, yasm 0.7.1.2093 + + * Ubuntu 8.10, gcc 4.3.2, yasm 0.7.1.2093 + + * Fedora 9, gcc 4.3.0, yasm 0.7.1.2093 + + * Fedora 10, gcc 4.3.2, yasm 0.7.1.2093 + + * gcc 4.0.0 or higher is reported to work + + Note: It is recommended to use the platform distribution's bundled + compiler for maximum C++ compatibility. If you build with a custom + compiler it will likely introduce non-standard runtime + requirements. There are of course many valid reasons to build with + unbundled compilers, but be aware it is generally unsupported and + left as an exercise to the reader. + +The following general tools are used on various platforms and it is +recommended you use these versions or similar: + + * subversion - 1.5.5 + + * python - Python 2.4.6 + + * curl - curl 7.19.3 (or wget) + + * m4 - GNU M4 1.4.6 + + * make - GNU Make 3.81 + + * patch - Patch 2.5.8 + + * tar - GNU tar 1.15.1 + + * wget - GNU Wget 1.11.4 (or curl) + +The GTK UI introduces some significant extra build requirements. If you +intend to disable building the GUI with `configure --disable-gtk' you +will not need many of these packages installed: + +Ubuntu 8.10 packages: + * build-essential + + * autoconf (gui) + + * intltool (gui) + + * libtool (gui) + + * zlib1g-dev (gui) + + * libbz2-dev + + * libglib2.0-dev (gui) + + * libdbus-glib-1-dev (gui) + + * libgtk2.0-dev (gui) + + * libhal-dev (gui) + + * libhal-storage-dev (gui) + + * libgtkhtml3.14-dev (gui) + + * libgstreamer0.10-dev (gui) + + * libgstreamer-plugins-base0.10-dev (gui) + +To install these packages: + sudo apt-get install subversion yasm build-essential \ + autoconf intltool libtool zlib1g-dev libbz2-dev libglib2.0-dev \ + libdbus-glib-1-dev libgtk2.0-dev libhal-dev libhal-storage-dev \ + libgtkhtml3.14-dev libgstreamer0.10-dev libgstreamer-plugins-base0.10-dev + +Fedora 10 package groups: + * Development Tools + + * Development Libraries + + * X Software Development (gui) + + * GNOME Software Development (gui) + +To install these package groups: + sudo yum groupinstall "Development Tools" "Development Libraries" \ + "X Software Development" "GNOME Software Development" + +Additional Fedora 10 packages: + * zlib-devel (gui) + + * bzip2-devel + + * dbus-glib-devel (gui) + + * hal-devel (gui) + + * gtkhtml3-devel (gui) + + * gstreamer-devel (gui) + + * gstreamer-plugins-base-devel (gui) + +To install these packages: + sudo yum install yasm zlib-devel bzip2-devel \ + dbus-glib-devel hal-devel gtkhtml3-devel \ + gstreamer-devel gstreamer-plugins-base-devel + +3 QuickStart +************ + +This chapter is for building from a terminal/shell environment in as +few commands as possible. Upon completion of the following commands you +should have a fresh build of HandBrake. Further instructions are +available beginning with *Note overview:: which describes procedures +suitable for repeating builds. This chapter should be skipped by those +seeking more than a minimalist build. + + svn checkout svn://svn.handbrake.fr/HandBrake/trunk hb-trunk + cd hb-trunk + ./configure --launch + +The special option `--launch' selects launch mode and performs the +following steps: + + * assert scratch directory `build/' does not exist + + * create scratch directory `build/' + + * change to directory `build/' + + * launch `make' + + * capture build output to `build/log/build.txt' + + * echo build output + + * print elapsed time + + * indicate if build ultimately succeeded or failed + +4 Overview +********** + +Linux builds are performed from a terminal. There is no support for +building from any IDEs. + +5 Building via Terminal +*********************** + +5.1 Checkout Sources +==================== + +Checkout HandBrake from the official source-code repository. + + svn checkout svn://svn.handbrake.fr/HandBrake/trunk hb-trunk + cd hb-trunk + +Sources are checked out from the `trunk' branch. This document was +generated from that very branch, and for example purposes, we will use +exactly the same branch. + +If you have write-access to the repository, then you may add the +appropriate login/password information as needed. It is recommended to +use Subversion 1.5.0 or higher. Lower versions should also work. + +5.2 Configure +============= + +Configure the build system. + + ./configure + +Configure will automatically create a scratch build directory `build' +unless you use GNU-style build procedures and first `cd' to a directory +other than top-level source. Additionally you may specify use `--build' +to specify the directory. The name of the directory is arbitrary but it +is recommended to use something which indicates transient files which +are not checked into the repository. + +The `configure' utility accepts many options. It is recommended that +you specify `--help' for the complete list of options. The following +options are also documented here: + +`--help' + List available options. + +`--src=DIR' + Specify top-level source directory for HandBrake sources. + +`--build=DIR' + Specify destination directory for final product install. The + default is to use either `build' if in the top-level source + directory, otherwise `.' + +`--prefix=DIR' + Specify destination directory for final product install. This + defaults to a reasonable platform-specific value. + +`--launch' + All-in-one option which launches the build and logs output + automatically. Useful for novices and quickstart procedures. + +`--disable-xcode' + Disable shunting the build through Xcode. If this option is + applied, `HandBrakeCLI' will be produced in a similare fashion as + it is on other platforms; sans Xcode. Mac OS X only. + +`--disable-gtk' + Disable building the GTK GUI on applicable platforms such as + Linux. + +`--debug=MODE' + Select debug mode. Must be one of `none', `min', `std', `max'. + This generally maps to gcc options `-g0', `-g1', `-g2', `-g3'. + +`--optimize=MODE' + Select optimize mode. Must be one of `none', `speed', `size'. + This generally maps to gcc options `-g0', `-O0', `-O3', `-Os'. + +`--arch=MODE' + Select build architecture. The available architectures vary by + platform. Most platforms support exactly one architecture except + Mac OS X which has support for various universal binary + architectures. The available choices are hard-coded per platform + and no sanity checks for the required tools are performed. + + +Clean-room procedures dictate that when certain factors change, old +builds should be scrapped and new builds configured. This is the main +reason for requiring a scratch directory; to promote consistent, +reliable and clean software builds. The following is a short list of +some of the reasons why someone may choose to scrap an existing build: + + * configure with different options + + * subversion working dir is updated and you want configure to + re-evaluate working dir metadata. + + * build corruption is suspected + +There are generally two methods for scrapping a build. The `build' +directory can be recusrively removed which has the effect of loosing +your existing configuration but does guarantee no residuals are left +behind. The other method is to ask the build system to perform an `make +xclean'. This is known to work well but will leave empty directories +behind. However, the configuration is left intact. + +5.3 Build +========= + +Build main product. All necessary dependencies are also built if +required. + + make + +Parallel builds may optionally be enabled. Be aware that while a +parallel build may save time on systems with additional cores, the +output is often mixed, overlapped and sometimes even corrupted with +binary characters. Thus if you experience a build issue, you should +clean and redo the build in default serial mode to produce a readable +log. The following command allows for up to 4 concurrent jobs via make: + + make -j4 + +5.4 Make Targets +================ + +The build system supports passing many kinds of targets some of which +become very useful in normal development cycles. The targets by +convention are lower-case words passed to `make'. Global targets are +one-word targets. Scoped targets are usually two-words seperated by a +period. + +5.4.1 Global +------------ + +`make' + Alias for `make build'. + +`make build' + Build main product. All necessary dependencies are also built if + required. + +`make clean' + Clean all build output excluding contrib modules. Configuration is + retained. + +`make install' + Perform final product(s) install. This will install build + products to a standard directory or one specified via `configure + --prefix' option. + +`make uninstall' + Perform final product(s) uninstall. This will uninstall any + products which may have been previously installed. + +`make xclean' + Clean all build output including contrib modules. Configuration is + retained. + +`make doc' + Build auto-generated project documentation. Various articles are + produced and may be found in `build/doc/articles'. + +`make report.help' + Print list of available makefile vars report targets. These + reports detail var definitions and expanded values used by the + build system. For experts only. + +`make report.all' + Convenience target which aggregates all reports. For experts only. + +5.4.2 General Modules +--------------------- + +General modules such as `libhb', `test' and `gtk' have the following +scoped targets: + +`make MODULE.build' + Build MODULE. + +`make MODULE.clean' + Clean build output for MODULE. + +5.4.3 Contrib Modules +--------------------- + +Contrib modules such as `a52dec', `bzip2', `faac', `faad2', `ffmpeg', +`lame', `libdca', `libdvdread', `libmkv', `libmp4v2', `libogg', +`libsamplerate', `libtheora', `libvorbis', `mpeg2dec', `x264', +`xvidcore' and `zlib' have the following scoped targets: + +`make MODULE.fetch' + Download source tarball from the Internet and save to + `TOP/downloads' directory. No checksumming is performed. + +`make MODULE.extract' + Extract source tarball into `build' tree. + +`make MODULE.patch' + Apply appropriate patches (if any) to module sources. + +`make MODULE.configure' + Configure module sources. This usually invokes autotool configure. + +`make MODULE.build' + Build module. This usually invokes autotool build. + +`make MODULE.install' + Install module products such as headers and libraries into `build' + tree. This usually invokes autotool install. + +`make MODULE.uninstall' + Uninstall module products; generally the reverse of install. This + usually invokes autotool uninstall. + +`make MODULE.clean' + Clean module; generally the reverse of build. This usually + invokes autotool clean. + +`make MODULE.xclean' + Extra clean module; first invokes uninstall then recursively + removes the module build directory. + +5.4.4 Contrib Touch and Untouch +------------------------------- + +Also available are some very granular targets which help force builds +from specific cycle points. The following targets are available to +touch and untouch the respective module target; this will force the +build system to treat the target as satisfied after a touch or +unsatisfied after an untouch: + + * make MODULE.extract.touch + + * make MODULE.extract.untouch + + * make MODULE.patch.touch + + * make MODULE.patch.untouch + + * make MODULE.configure.touch + + * make MODULE.configure.untouch + + * make MODULE.build.touch + + * make MODULE.build.untouch + + * make MODULE.install.touch + + * make MODULE.install.untouch + +5.4.5 Contrib Aggregates +------------------------ + +For convenience, the following targets aggregate the all contrib +modules' respective targets together: + + * make contrib.fetch + + * make contrib.extract + + * make contrib.patch + + * make contrib.configure + + * make contrib.build + + * make contrib.install + + * make contrib.uninstall + + * make contrib.clean + + * make contrib.xclean + +5.5 Customizing Make +==================== + +If the need arises to override settings in the build system +(essentially gnu-make variables) the recommended method is to create +optional include files which are automatically included if present and +follow this naming convention; Do not check these files into the +respository: + +`_SRC_/custom.defs' + Custom makevar definitions outside `build'. Suitable for settings + which apply across all builds for a particular checkout; or which + survives manual removal of `build'. + +`_SRC_/custom.rules' + Custom make rules outside `build'. Suitable for rules which apply + across all builds for a particular checkout; or which survives + manual removal of `build'. + +`_BUILD_/GNUmakefile.custom.defs' + Custom makevar definitions specific to a `build' directory. + +`_BUILD_/GNUmakefile.custom.rules' + Custom makevar rules specific to a `build' directory. + + +The purpose is to allow a place to store local build settings for +testing, tweaking, and experimenting with build configuration without +losing your settings if `configure' is invoked; ie: `configure' would +overwrite `GNUmakefile' and any customizations contained therein would +be lost. Here is a short example of what the contents of +`_SRC_/custom.defs' might contain: + + ## bump to gcc-4.2 in current path + GCC.gcc = gcc-4.2 + + ## replace optimize for 'speed' with more agressive settings + GCC.args.O.speed = -O3 -fomit-frame-pointer -msse4.2 + +See also `make report.help' which displays a set of reports used to +dump makefile vars. + +Appendix A Project Repository Details +************************************* + + url: svn://svn.handbrake.fr/HandBrake/trunk + root: svn://svn.handbrake.fr/HandBrake + branch: trunk + uuid: b64f7644-9d1e-0410-96f1-a4d463321fa5 + rev: 2252 + date: 2009-03-10 18:43:11 -0400 + type: developer + diff --git a/doc/BUILD-Mac b/doc/BUILD-Mac new file mode 100644 index 000000000..6dc74692d --- /dev/null +++ b/doc/BUILD-Mac @@ -0,0 +1,623 @@ +Build Guide for HandBrake svn2252 on Mac OS X +********************************************* + +Table of Contents +***************** + +1 Introduction +2 Prerequisites +3 QuickStart +4 Overview +5 Building via Terminal + 5.1 Checkout Sources + 5.2 Configure + 5.3 Build + 5.4 Make Targets + 5.4.1 Global + 5.4.2 General Modules + 5.4.3 Contrib Modules + 5.4.4 Contrib Touch and Untouch + 5.4.5 Contrib Aggregates + 5.5 Customizing Make + 5.6 Universal Binaries +6 Building via Xcode + 6.1 Checkout Sources + 6.2 Build + 6.3 External Targets + 6.4 User-Defined Settings +Appendix A Project Repository Details + + +1 Introduction +************** + +This guide documents the recommended process to build HandBrake on +Mac OS X hosts from the official source-code repository. Building from +any other source is not supported. + +2 Prerequisites +*************** + +Building on Mac OS X is well supported. It is the reference platform +for HandBrake. The following are the recommended specifications for +this platform; but is not necessarily the only configuration that is +possible: + + * Mac Intel hardware + + * Mac OS X 10.5.6 + + * Xcode-3.1.2 + + * gcc 4.0.1 (Apple Inc. build 5490) + + * yasm 0.7.2.2153 (for i386 and x86_64 architectures) + + Note: It is recommended to use the platform distribution's bundled + compiler for maximum C++ compatibility. If you build with a custom + compiler it will likely introduce non-standard runtime + requirements. There are of course many valid reasons to build with + unbundled compilers, but be aware it is generally unsupported and + left as an exercise to the reader. + +The following general tools are used on various platforms and it is +recommended you use these versions or similar: + + * subversion - 1.5.5 + + * python - Python 2.4.6 + + * curl - curl 7.19.3 (or wget) + + * m4 - GNU M4 1.4.6 + + * make - GNU Make 3.81 + + * patch - Patch 2.5.8 + + * tar - GNU tar 1.15.1 + + * wget - GNU Wget 1.11.4 (or curl) + +3 QuickStart +************ + +This chapter is for building from a terminal/shell environment in as +few commands as possible. Upon completion of the following commands you +should have a fresh build of HandBrake. Further instructions are +available beginning with *Note overview:: which describes procedures +suitable for repeating builds. This chapter should be skipped by those +seeking more than a minimalist build. + + svn checkout svn://svn.handbrake.fr/HandBrake/trunk hb-trunk + cd hb-trunk + ./configure --launch + +The special option `--launch' selects launch mode and performs the +following steps: + + * assert scratch directory `build/' does not exist + + * create scratch directory `build/' + + * change to directory `build/' + + * launch `make' + + * capture build output to `build/log/build.txt' + + * echo build output + + * print elapsed time + + * indicate if build ultimately succeeded or failed + +4 Overview +********** + +The two general methods to build on Mac OS X are building from terminal +or Xcode. The preferred method for automated and repeatable builds is +to use the terminal. Otherwise the choice is generally up to the +individual. In essence, the terminal actually invokes `xcodebuild' to +build the very same targets contained in the Xcode project. + +5 Building via Terminal +*********************** + +5.1 Checkout Sources +==================== + +Checkout HandBrake from the official source-code repository. + + svn checkout svn://svn.handbrake.fr/HandBrake/trunk hb-trunk + cd hb-trunk + +Sources are checked out from the `trunk' branch. This document was +generated from that very branch, and for example purposes, we will use +exactly the same branch. + +If you have write-access to the repository, then you may add the +appropriate login/password information as needed. It is recommended to +use Subversion 1.5.0 or higher. Lower versions should also work. + +5.2 Configure +============= + +Configure the build system. + + ./configure + +Configure will automatically create a scratch build directory `build' +unless you use GNU-style build procedures and first `cd' to a directory +other than top-level source. Additionally you may specify use `--build' +to specify the directory. The name of the directory is arbitrary but it +is recommended to use something which indicates transient files which +are not checked into the repository. + +The `configure' utility accepts many options. It is recommended that +you specify `--help' for the complete list of options. The following +options are also documented here: + +`--help' + List available options. + +`--src=DIR' + Specify top-level source directory for HandBrake sources. + +`--build=DIR' + Specify destination directory for final product install. The + default is to use either `build' if in the top-level source + directory, otherwise `.' + +`--prefix=DIR' + Specify destination directory for final product install. This + defaults to a reasonable platform-specific value. + +`--launch' + All-in-one option which launches the build and logs output + automatically. Useful for novices and quickstart procedures. + +`--disable-xcode' + Disable shunting the build through Xcode. If this option is + applied, `HandBrakeCLI' will be produced in a similare fashion as + it is on other platforms; sans Xcode. Mac OS X only. + +`--disable-gtk' + Disable building the GTK GUI on applicable platforms such as + Linux. + +`--debug=MODE' + Select debug mode. Must be one of `none', `min', `std', `max'. + This generally maps to gcc options `-g0', `-g1', `-g2', `-g3'. + +`--optimize=MODE' + Select optimize mode. Must be one of `none', `speed', `size'. + This generally maps to gcc options `-g0', `-O0', `-O3', `-Os'. + +`--arch=MODE' + Select build architecture. The available architectures vary by + platform. Most platforms support exactly one architecture except + Mac OS X which has support for various universal binary + architectures. The available choices are hard-coded per platform + and no sanity checks for the required tools are performed. + + +Clean-room procedures dictate that when certain factors change, old +builds should be scrapped and new builds configured. This is the main +reason for requiring a scratch directory; to promote consistent, +reliable and clean software builds. The following is a short list of +some of the reasons why someone may choose to scrap an existing build: + + * configure with different options + + * subversion working dir is updated and you want configure to + re-evaluate working dir metadata. + + * build corruption is suspected + +There are generally two methods for scrapping a build. The `build' +directory can be recusrively removed which has the effect of loosing +your existing configuration but does guarantee no residuals are left +behind. The other method is to ask the build system to perform an `make +xclean'. This is known to work well but will leave empty directories +behind. However, the configuration is left intact. + +5.3 Build +========= + +Build main product. All necessary dependencies are also built if +required. + + make + +Parallel builds may optionally be enabled. Be aware that while a +parallel build may save time on systems with additional cores, the +output is often mixed, overlapped and sometimes even corrupted with +binary characters. Thus if you experience a build issue, you should +clean and redo the build in default serial mode to produce a readable +log. The following command allows for up to 4 concurrent jobs via make: + + make -j4 + +5.4 Make Targets +================ + +The build system supports passing many kinds of targets some of which +become very useful in normal development cycles. The targets by +convention are lower-case words passed to `make'. Global targets are +one-word targets. Scoped targets are usually two-words seperated by a +period. + +5.4.1 Global +------------ + +`make' + Alias for `make build'. + +`make build' + Build main product. All necessary dependencies are also built if + required. + +`make clean' + Clean all build output excluding contrib modules. Configuration is + retained. + +`make install' + Perform final product(s) install. This will install build + products to a standard directory or one specified via `configure + --prefix' option. + +`make uninstall' + Perform final product(s) uninstall. This will uninstall any + products which may have been previously installed. + +`make xclean' + Clean all build output including contrib modules. Configuration is + retained. + +`make doc' + Build auto-generated project documentation. Various articles are + produced and may be found in `build/doc/articles'. + +`make report.help' + Print list of available makefile vars report targets. These + reports detail var definitions and expanded values used by the + build system. For experts only. + +`make report.all' + Convenience target which aggregates all reports. For experts only. + +5.4.2 General Modules +--------------------- + +General modules such as `libhb', `test' and `gtk' have the following +scoped targets: + +`make MODULE.build' + Build MODULE. + +`make MODULE.clean' + Clean build output for MODULE. + +5.4.3 Contrib Modules +--------------------- + +Contrib modules such as `a52dec', `bzip2', `faac', `faad2', `ffmpeg', +`lame', `libdca', `libdvdread', `libmkv', `libmp4v2', `libogg', +`libsamplerate', `libtheora', `libvorbis', `mpeg2dec', `x264', +`xvidcore' and `zlib' have the following scoped targets: + +`make MODULE.fetch' + Download source tarball from the Internet and save to + `TOP/downloads' directory. No checksumming is performed. + +`make MODULE.extract' + Extract source tarball into `build' tree. + +`make MODULE.patch' + Apply appropriate patches (if any) to module sources. + +`make MODULE.configure' + Configure module sources. This usually invokes autotool configure. + +`make MODULE.build' + Build module. This usually invokes autotool build. + +`make MODULE.install' + Install module products such as headers and libraries into `build' + tree. This usually invokes autotool install. + +`make MODULE.uninstall' + Uninstall module products; generally the reverse of install. This + usually invokes autotool uninstall. + +`make MODULE.clean' + Clean module; generally the reverse of build. This usually + invokes autotool clean. + +`make MODULE.xclean' + Extra clean module; first invokes uninstall then recursively + removes the module build directory. + +5.4.4 Contrib Touch and Untouch +------------------------------- + +Also available are some very granular targets which help force builds +from specific cycle points. The following targets are available to +touch and untouch the respective module target; this will force the +build system to treat the target as satisfied after a touch or +unsatisfied after an untouch: + + * make MODULE.extract.touch + + * make MODULE.extract.untouch + + * make MODULE.patch.touch + + * make MODULE.patch.untouch + + * make MODULE.configure.touch + + * make MODULE.configure.untouch + + * make MODULE.build.touch + + * make MODULE.build.untouch + + * make MODULE.install.touch + + * make MODULE.install.untouch + +5.4.5 Contrib Aggregates +------------------------ + +For convenience, the following targets aggregate the all contrib +modules' respective targets together: + + * make contrib.fetch + + * make contrib.extract + + * make contrib.patch + + * make contrib.configure + + * make contrib.build + + * make contrib.install + + * make contrib.uninstall + + * make contrib.clean + + * make contrib.xclean + +5.5 Customizing Make +==================== + +If the need arises to override settings in the build system +(essentially gnu-make variables) the recommended method is to create +optional include files which are automatically included if present and +follow this naming convention; Do not check these files into the +respository: + +`_SRC_/custom.defs' + Custom makevar definitions outside `build'. Suitable for settings + which apply across all builds for a particular checkout; or which + survives manual removal of `build'. + +`_SRC_/custom.rules' + Custom make rules outside `build'. Suitable for rules which apply + across all builds for a particular checkout; or which survives + manual removal of `build'. + +`_BUILD_/GNUmakefile.custom.defs' + Custom makevar definitions specific to a `build' directory. + +`_BUILD_/GNUmakefile.custom.rules' + Custom makevar rules specific to a `build' directory. + + +The purpose is to allow a place to store local build settings for +testing, tweaking, and experimenting with build configuration without +losing your settings if `configure' is invoked; ie: `configure' would +overwrite `GNUmakefile' and any customizations contained therein would +be lost. Here is a short example of what the contents of +`_SRC_/custom.defs' might contain: + + ## bump to gcc-4.2 in current path + GCC.gcc = gcc-4.2 + + ## replace optimize for 'speed' with more agressive settings + GCC.args.O.speed = -O3 -fomit-frame-pointer -msse4.2 + +See also `make report.help' which displays a set of reports used to +dump makefile vars. + +5.6 Universal Binaries +====================== + +This section outlines convenience procedures for creating Universal +Binaries for all the architectures. + + Note: The dummy (container) build configuration uses + `--disable-xcode'; but the nested architecture builds will all + make full use of Xcode. + +Create a dummy (container) build configuration and use it to launch a +nested-build for each architecture serially; optionally you may +substitute `make ub.build.serial' for `make ub.build.parallel' if your +machine has the horsepower: + + ./configure --disable-xcode + cd build/ + make ub.build.serial + make ub.combine + +To specify a subset of architectures to be built first create/edit +`_SRC_/custom.defs' with the following override to build UB for `i386' +and `x86_64' before invoking `make': + + ## prefer i386 (order is important) + UB.archs = i386 x86_64 + +6 Building via Xcode +******************** + +6.1 Checkout Sources +==================== + +Checkout HandBrake from the official source-code repository. + + svn checkout svn://svn.handbrake.fr/HandBrake/trunk hb-trunk + cd hb-trunk + +Sources are checked out from the `trunk' branch. This document was +generated from that very branch, and for example purposes, we will use +exactly the same branch. + +If you have write-access to the repository, then you may add the +appropriate login/password information as needed. It is recommended to +use Subversion 1.5.0 or higher. Lower versions should also work. + +6.2 Build +========= + +In Xcode perform the following steps to build the default configuration: + + * open `macosx/HandBrake.xcodeproj' + + * select active configuration standard + + * select active target HandBrake + + * click Build or Build and Go + +The first build (on an empty `build' directory) will take a bit of +time. You may use the Build Results window to observe progress. The +most time-consuming part of the build is when the external build system +(essentially the terminal method) is triggered by Xcode and a +substantial amount of log transcript ensues. Much of that transcript +are warnings and errors that are part of the normal build process for +3rd-party contributed modules so in general you need not do anything. +However, if Xcode itself reports the build failed, then you must take +corrective action. + +Unfortunately, due to limitations of Xcode we do not have hooks in +place to offer finer-grained control over per-module make actions for +the (external) build system. Thus, you will have to use terminal to +accomplish those tasks. Just `cd' into the build directory which is +associated with your active configuration and perform any necessary +`make' commands. Be careful not to issue commands from the terminal +simultaneously with Xcode tasks as that will confuse both Xcode and +make and likely corrupt your build directory. + +When you click clean in Xcode it will not perform an external build +clean. Basically HandBrakeCLI and HandBrake.app are the only products +which have full Xcode iterative development flexibility. + +Each configuration uses a different `build' directory. This makes it +possible to build each configuration and switch between them without +losing their respective build state. The description of each +configuration and the name convention for build directories are as +follows: + +`standard' + This configuration will build host native architecture. Build + directory is `build.standard' . The standard variant produces + optimized code without debug information. + +`standard.i386' + This configuration will build i386 architecture. Build directory + is `build.standard.i386' . + +`standard.x86_64' + This configuration will build x86_64 architecture. Build directory + is `build.standard.x86_64' . + +`standard.ppc' + This configuration will build ppc architecture. Build directory is + `build.standard.ppc' . + +`standard.ppc64' + This configuration will build ppc64 architecture. Build directory + is `build.standard.ppc64' . + +`debug' + This configuration will build host native architecture. Build + directory is `build.debug' . The debug variant produces + unoptimized code with debug information. + +`debug.i386' + This configuration will build i386 architecture. Build directory + is `build.debug.i386' . The debug variant produces unoptimized + code with debug information. + +`debug.x86_64' + This configuration will build x86_64 architecture. Build directory + is `build.debug.x86_64' . The debug variant produces unoptimized + code with debug information. + +`debug.ppc' + This configuration will build ppc architecture. Build directory is + `build.debug.ppc' . The debug variant produces unoptimized code + with debug information. + +`debug.ppc64' + This configuration will build ppc64 architecture. Build directory + is `build.debug.ppc64' . The debug variant produces unoptimized + code with debug information. + +6.3 External Targets +==================== + +The following external targets appear in the Xcode project and perform +build and clean actions. + +`external' + Target maps to `make build' and `make clean' for everything Xcode + products depend upon from the external build system. + +`libhb' + Target maps to `make libhb.build' and `make libhb.clean'. + +`contrib' + Target maps to `make contrib.build' and `make contrib.xclean'. + + +6.4 User-Defined Settings +========================= + +The following user defined settings are used in Xcode project for the +external build system: + +`EXTERNAL_BUILD' + Specifies the build (scratch) directory for each configuration. + +`EXTERNAL_JOBS' + Specifies the concurrency factor for the external build system + when builds are launched from within Xcode. Modify for faster + external builds if your system has the horsepower and resources. + Specifying a value greater than the number of CPU cores (or + virtual cores) in your system is unlikely to produce gains and + will needlessly consume extra resources. + +`EXTERNAL_METHOD' + Do not modify; Used for internal/external build coordination and + must always be `xcode'. + +`EXTERNAL_SRC' + Specifies the top-level source directory for HandBrake. + + +Appendix A Project Repository Details +************************************* + + url: svn://svn.handbrake.fr/HandBrake/trunk + root: svn://svn.handbrake.fr/HandBrake + branch: trunk + uuid: b64f7644-9d1e-0410-96f1-a4d463321fa5 + rev: 2252 + date: 2009-03-10 18:43:11 -0400 + type: developer + diff --git a/doc/module.defs b/doc/module.defs index 8047022bd..de427a3fe 100644 --- a/doc/module.defs +++ b/doc/module.defs @@ -21,13 +21,10 @@ DOC.texi2html.out = $(patsubst $(DOC.in/)texi/%.texi,$(DOC.out.articles/)html/%. DOC.texi2txt.out = $(patsubst $(DOC.in/)texi/%.texi,$(DOC.out.articles/)txt/%.txt,$(DOC.texi.articles)) DOC.texi2xml.out = $(patsubst $(DOC.in/)texi/%.texi,$(DOC.out.articles/)xml/%.xml,$(DOC.texi.articles)) -DOC.xml2wiki.out = $(DOC.texi2xml.out:$(DOC.out.articles/)xml/%.xml=$(DOC.out.articles/)wiki/%.wiki) - BUILD.out += $(DOC.m4.out) BUILD.out += $(DOC.texi2html.out) BUILD.out += $(DOC.texi2txt.out) BUILD.out += $(DOC.texi2xml.out) -BUILD.out += $(DOC.xml2wiki.out) ############################################################################### @@ -42,7 +39,3 @@ MAKEINFO.flags.html = --html --no-headers --no-split MAKEINFO.flags.txt = --plaintext --no-headers MAKEINFO.flags.xml = --xml --output-indent=4 MAKEINFO = $(MAKEINFO.exe) $(MAKEINFO.flags) $(MAKEINFO.flags.$(1)) $(2) -o $(3) - -XML2WIKI.exe = python3.0 $(DOC.in/)xml2wiki.py -XML2WIKI.flags = --toc -XML2WIKI = $(XML2WIKI.exe) $(XML2WIKI.flags) $(1) > $(2) diff --git a/doc/module.rules b/doc/module.rules index ac30a2a55..fc1d0b526 100644 --- a/doc/module.rules +++ b/doc/module.rules @@ -2,9 +2,13 @@ $(eval $(call import.MODULE.rules,DOC)) doc: doc.txt +doc.post: doc.txt + $(CP.exe) $(DOC.out.articles/)txt/Building.osx.txt $(DOC.in/)BUILD-Mac + $(CP.exe) $(DOC.out.articles/)txt/Building.linux.txt $(DOC.in/)BUILD-Linux + $(CP.exe) $(DOC.out.articles/)txt/Building.cygwin.txt $(DOC.in/)BUILD-Cygwin + doc.txt: $(DOC.texi2txt.out) doc.xml: $(DOC.texi2xml.out) -doc.wiki: $(DOC.xml2wiki.out) doc.clean: $(RM.exe) -fr $(DOC.out/) @@ -23,10 +27,6 @@ $(DOC.texi2xml.out): $(DOC.out.articles/)xml/%.xml: $(DOC.in/)texi/%.texi $(call MAKEINFO,xml,$<,$@) @echo $^ -$(DOC.xml2wiki.out): | $(dir $(DOC.xml2wiki.out)) -$(DOC.xml2wiki.out): $(DOC.out.articles/)wiki/%.wiki: $(DOC.out.articles/)xml/%.xml - $(call XML2WIKI,$<,$@) - $(DOC.m4.out): | $(dir $(DOC.m4.out)) $(DOC.m4.out): $(DOC.M4.deps) $(DOC.m4.out): $(DOC.out/)%: $(DOC.in/)%.m4 diff --git a/doc/xml2wiki.py b/doc/xml2wiki.py deleted file mode 100755 index 2b7eb4827..000000000 --- a/doc/xml2wiki.py +++ /dev/null @@ -1,387 +0,0 @@ -import io -import re -import sys -import time -import xml.parsers.expat - -from optparse import OptionParser - -############################################################################### - -writer = None - -############################################################################### - -class StreamEntry: - def __init__( self, object, isElement ): - self.object = object - self.isElement = isElement - -############################################################################### - -class Element: - def __init__( self, parent, text=True, strip=True, delimBegin=None, delimEnd=None, newline=0 ): - self._parent = parent - self._text = text - self._strip = strip - self._delimBegin = delimBegin - self._delimEnd = delimEnd - self._newline = newline - self._stream = [] - - def _addElement( self, child ): - self._stream.append( StreamEntry( child, True )) - - def _addText( self, text ): - if self._text: - self._stream.append( StreamEntry( text, False )) - - def _write( self, file ): - if self._delimBegin: - file.write( self._delimBegin ) - for entry in self._stream: - if entry.isElement: - entry.object.write( file ) - else: - file.write( str(entry.object) ) - if self._delimEnd: - file.write( self._delimEnd ) - - def write( self, file ): - if self._newline > writer.newlineCount: - file.write( '\n' * (self._newline - writer.newlineCount)) - self._write( file ) - -############################################################################### - -class Document( Element ): - def __init__( self ): - Element.__init__( self, None ) - self._stack = [ self ] - self._pending = self - self._summary = None - self._debugIndent = '' - self._chapterLevel = 0 - self._sectionLevel = 0 - self._dividerCount = 0 - self._majorHeading = Element( self, delimBegin='= ', delimEnd=' =\n\n' ) - - def _pop( self ): - self._stack.pop() - self._pending = self._stack[-1] - return self._pending - - def _pushChild( self, child, add=True ): - if add: - self._pending._addElement( child ); - self._stack.append( child ) - self._pending = child - return self._pending - - def _chapterBegin( self ): - self._chapterLevel = self._chapterLevel + 1 - - def _chapterEnd( self ): - self._chapterLevel = self._chapterLevel - 1 - - def _sectionBegin( self ): - self._sectionLevel = self._sectionLevel + 1 - - def _sectionEnd( self ): - self._sectionLevel = self._sectionLevel - 1 - - def _write( self, file ): - if options.date: - file.write( "\n\n ===== `[`generated by xml2wiki on %s`]` =====" % (time.strftime( '%c' ) )) - Element._write( self, file ) - file.write( '\n' ) - - def handleElementBegin( self, name, attrs ): - self._debugIndent = ' ' * (len(self._stack) - 1) - if options.verbose: - print( '%sBEGIN %s %s' % (self._debugIndent, name, attrs)) - - e = None - shouldAdd = True - - if name == 'anchor': - global anchor - anchor = attrs['name'] - elif name == 'b': - e = Element( self._pending, delimBegin="'''", delimEnd="'''" ) - elif name == 'chapter': - self._chapterBegin() - elif name == 'code': - e = Element( self._pending, delimBegin='{{{{', delimEnd='}}}' ) - elif name == 'command': - e = Element( self._pending, delimBegin='{{{', delimEnd='}}}' ) - elif name == 'enumerate': - e = EnumerateElement( self._pending ) - elif name == 'example': - e = CodeElement( self._pending ) - elif name == 'file': - e = Element( self._pending, delimBegin='{{{', delimEnd='}}}' ) - elif name == 'i': - e = Element( self._pending, delimBegin="''", delimEnd="''" ) - elif name == 'itemize': - e = ItemizeElement( self._pending ) - elif name == 'item': - e = ItemElement( self._pending ) - elif name == 'majorheading': - e = self._majorHeading - shouldAdd = False - elif name == 'para': - e = ParagraphElement( self._pending ) - elif name == 'quotation': - e = IndentedElement( self._pending ) - elif name == 'samp': - e = Element( self._pending, delimBegin='{{{', delimEnd='}}}' ) - elif name == 'section' or name == 'subsection': - self._sectionBegin() - #elif name == 'table': - # e = Element( self._pending, newline=1, delimBegin='<table border="1" cellpadding="4">', delimEnd='</table>', strip=True ) - elif name == 'tableitem': - e = TableItemElement( self._pending ) - elif name == 'tableterm': - e = Element( self._pending, delimBegin=' ', delimEnd='::\n' ) - elif name == 'title': - e = HeadingElement( self._pending, self._chapterLevel + self._sectionLevel ) - elif name == 'unnumbered' or name == 'unnumberedsec': - self._chapterBegin() - elif name == 'uref': - e = UrefInline( self._pending ) - elif name == 'urefdesc': - e = UrefDescInline( self._pending ) - elif name == 'urefurl': - e = UrefUrlInline( self._pending ) - elif name == 'xref': - e = XrefInline( self._pending ) - elif name == 'xrefnodename': - e = XrefNodenameInline( self._pending ) - - if not e: - self._pushChild( UnknownElement( self._pending ) ) - if options.verbose > 2: - print( 'UNKNOWN:', name ) - else: - self._pushChild( e, add=shouldAdd ) - - def handleElementEnd( self, name ): - if name == 'chapter': - self._chapterEnd() - elif name == 'section' or name == 'subsection': - self._sectionEnd() - elif name == 'unnumbered' or name == 'unnumberedsec': - self._sectionEnd() - - self._pop() - self._debugIndent = ' ' * (len(self._stack) - 1) - if options.verbose: - print( '%sEND %s' % (self._debugIndent, name)) - - def handleCharacterData( self, data ): - if options.verbose > 1: - print( '%s[%s]' % (self._debugIndent, data.strip())) - self._pending._addText( data ) - -############################################################################### - -class UnknownElement( Element ): - def __init__( self, parent ): - Element.__init__( self, parent, text=False ) - -############################################################################### - -class PragmaElement( Element ): - def __init__( self, parent, keyword ): - Element.__init__( self, parent, delimBegin=('#' + keyword + ' ') ) - -############################################################################### - -class BlockElement( Element ): - def __init__( self, parent ): - Element.__init__( self, parent, newline=2, text=False ) - -############################################################################### - -class CodeElement( Element ): - def __init__( self, parent ): - Element.__init__( self, parent, newline=2, delimBegin='{{{\n', delimEnd='\n}}}\n' ) - -############################################################################### - -class HeadingElement( Element ): - def __init__( self, parent, level ): - Element.__init__( self, parent, newline=2 ) - global anchor - self._anchor = anchor - - self._level = level - self._delimBegin = ('=' * level) + ' ' - self._delimEnd = ' %s #%s\n' % (('=' * level), self._anchor) - #self._delimEnd = ' ' + ('=' * level) + ' #%s\n' % (self._anchor) - - # insert divider for level 1 headers - if level == 1: - if options.toc or doc._dividerCount: - self._delimBegin = '----\n%s' % (self._delimBegin) - doc._dividerCount = doc._dividerCount + 1 - - toc.append( self ) - -############################################################################### - -class IndentedElement( BlockElement ): - def _write( self, file ): - writer.increase() - Element._write( self, file ) - writer.decrease() - -############################################################################### - -class EnumerateElement( IndentedElement ): - pass - -############################################################################### - -class ItemizeElement( IndentedElement ): - pass - -############################################################################### - -class ItemElement( BlockElement ): - def __init__( self, parent ): - BlockElement.__init__( self, parent ) - self._newline = 1 - if isinstance( parent, TableItemElement ): - self._newline = 0 - #self._delimBegin = '<td>' - #self._delimEnd = '</td>' - self._delimBegin = ' ' - self._delimEnd = '\n' - -############################################################################### - -class ParagraphElement( Element ): - def __init__( self, parent ): - Element.__init__( self, parent, newline=2 ) - if isinstance( parent, ItemElement ): - if isinstance( parent._parent, TableItemElement ): - self._newline = 0 - elif isinstance( parent._parent, EnumerateElement ): - self._newline = 1 - self._delimBegin = '# ' - else: - self._newline = 1 - self._delimBegin = '* ' - -############################################################################### - -class TableItemElement( Element ): - def __init__( self, parent ): - Element.__init__( self, parent, newline=1, text=False ) - #self._delimBegin = '<tr>' - #self._delimEnd = '</tr>' - -############################################################################### - -class UrefInline( Element ): - def __init__( self, parent ): - Element.__init__( self, parent, text=False, delimBegin='[', delimEnd=']' ) - -############################################################################### - -class UrefDescInline( Element ): - def __init__( self, parent ): - Element.__init__( self, parent, delimBegin=' ' ) - -############################################################################### - -class UrefUrlInline( Element ): - def __init__( self, parent ): - Element.__init__( self, parent ) - -############################################################################### - -class XrefInline( Element ): - def __init__( self, parent ): - Element.__init__( self, parent, text=False ) - -############################################################################### - -class XrefNodenameInline( Element ): - def __init__( self, parent ): - Element.__init__( self, parent ) - - def _write( self, file ): - buffer = io.StringIO() - Element._write( self, buffer ) - name = str( buffer.getvalue() ) - anchor = re.sub( ' ', '_', name ) - file.write( '[#%s %s]' % (anchor, name) ) - -############################################################################### - -class IndentedWriter: - def __init__( self, size, file ): - self._chunk = ' ' * size - self._file = file - self._level = 0 - self._indent = '' - self._pending = False - - self.newlineCount = 0 - - def decrease( self ): - self._level = self._level - 1 - self._indent = self._chunk * self._level - - def increase( self ): - self._level = self._level + 1 - self._indent = self._chunk * self._level - - def write( self, data ): - for b in data: - if self._pending: - self._pending = False - self._file.write( self._indent ) - if b == '\n': - self.newlineCount = self.newlineCount + 1 - self._pending = True - else: - self.newlineCount = 0 - self._file.write( b ) - -############################################################################### - -parser = OptionParser( 'Usage: %prog [OPTIONS] xml' ) -parser.add_option( '-d', '--date', action='store_true', default=False, help='generate date-stamp under title' ) -parser.add_option( '-t', '--toc', action='store_true', default=False, help='generate table of contents' ) -parser.add_option( '-v', '--verbose', action='count', default=False, help='increase verbosity' ) - -(options, args) = parser.parse_args() - -if( len(args) != 1 ): - parser.error( 'incorrect number of arguments' ) - -############################################################################### - -doc = Document() -xml = xml.parsers.expat.ParserCreate() - -xml.StartElementHandler = doc.handleElementBegin -xml.EndElementHandler = doc.handleElementEnd -xml.CharacterDataHandler = doc.handleCharacterData - -anchor = None -toc = [] -with open( args[0], 'rb' ) as fin: - xml.ParseFile( fin ) - -writer = IndentedWriter( 4, sys.stdout ) - -doc._majorHeading.write( writer ) -if options.toc: - for e in toc: - writer.write( '%s* [#%s %s]\n' % (' ' * e._level,e._anchor,e._stream[0].object) ) -doc.write( writer ) |