From d26832c2ad2e62500fed8b9168098c4b5c61ce6e Mon Sep 17 00:00:00 2001 From: Hans Ulrich Niedermann Date: Fri, 2 Nov 2007 06:47:34 +0100 Subject: Initial standalone version of nbb. --- .gitignore | 8 + INSTALL | 12 + LICENSE.GPL | 340 ++++++++++++++++++ LICENSE.MIT | 26 ++ Makefile-files | 10 + Makefile.am | 91 +++++ NEWS | 2 + README | 54 +++ README-alpha | 3 + build-helpers/package-version | 27 ++ build-helpers/package-version.mk | 58 +++ build-helpers/text2html.sed | 11 + configure.ac | 40 +++ doc/.htaccess | 15 + m4/ndim-check-sh-command-substitution.m4 | 26 ++ m4/ndim-check-sh-functions.m4 | 29 ++ m4/ndim-check-sh-param-expansion.m4 | 31 ++ m4/ndim-detect-man2txt.m4 | 45 +++ m4/ndim-require-posix-sh.m4 | 15 + nbb/Makefile-files | 15 + nbb/nbb.in | 35 ++ nbb/nbb_lib.in | 584 +++++++++++++++++++++++++++++++ test/.gitignore | 3 + test/Makefile.am | 101 ++++++ test/atlocal.in | 0 test/autotest.at | 9 + test/local.at | 3 + test/nbb-basic.at | 41 +++ test/nbb-commands.at | 44 +++ 29 files changed, 1678 insertions(+) create mode 100644 .gitignore create mode 100644 INSTALL create mode 100644 LICENSE.GPL create mode 100644 LICENSE.MIT create mode 100644 Makefile-files create mode 100644 Makefile.am create mode 100644 NEWS create mode 100644 README create mode 100644 README-alpha create mode 100755 build-helpers/package-version create mode 100644 build-helpers/package-version.mk create mode 100644 build-helpers/text2html.sed create mode 100644 configure.ac create mode 100644 doc/.htaccess create mode 100644 m4/ndim-check-sh-command-substitution.m4 create mode 100644 m4/ndim-check-sh-functions.m4 create mode 100644 m4/ndim-check-sh-param-expansion.m4 create mode 100644 m4/ndim-detect-man2txt.m4 create mode 100644 m4/ndim-require-posix-sh.m4 create mode 100644 nbb/Makefile-files create mode 100644 nbb/nbb.in create mode 100644 nbb/nbb_lib.in create mode 100644 test/.gitignore create mode 100644 test/Makefile.am create mode 100644 test/atlocal.in create mode 100644 test/autotest.at create mode 100644 test/local.at create mode 100644 test/nbb-basic.at create mode 100644 test/nbb-commands.at diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..ce3120c --- /dev/null +++ b/.gitignore @@ -0,0 +1,8 @@ +*~ +Makefile.in +Makefile +aclocal.m4 +auto-aux +autom4te.cache +configure +_local-build diff --git a/INSTALL b/INSTALL new file mode 100644 index 0000000..d01930e --- /dev/null +++ b/INSTALL @@ -0,0 +1,12 @@ +If this is a git repository checkout (as opposed to sources extracted +from a source tarball): + + $ autoreconf -vis . + +Regardless of whether this is a git repo checkout or an extracted +source tarball: + + $ ./configure --prefix=/what/ever + $ make + $ make check # optional + $ make install diff --git a/LICENSE.GPL b/LICENSE.GPL new file mode 100644 index 0000000..3912109 --- /dev/null +++ b/LICENSE.GPL @@ -0,0 +1,340 @@ + GNU GENERAL PUBLIC LICENSE + Version 2, June 1991 + + Copyright (C) 1989, 1991 Free Software Foundation, Inc. + 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The licenses for most software are designed to take away your +freedom to share and change it. By contrast, the GNU General Public +License is intended to guarantee your freedom to share and change free +software--to make sure the software is free for all its users. This +General Public License applies to most of the Free Software +Foundation's software and to any other program whose authors commit to +using it. (Some other Free Software Foundation software is covered by +the GNU Library General Public License instead.) You can apply it to +your programs, too. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +this service if you wish), that you receive source code or can get it +if you want it, that you can change the software or use pieces of it +in new free programs; and that you know you can do these things. + + To protect your rights, we need to make restrictions that forbid +anyone to deny you these rights or to ask you to surrender the rights. +These restrictions translate to certain responsibilities for you if you +distribute copies of the software, or if you modify it. + + For example, if you distribute copies of such a program, whether +gratis or for a fee, you must give the recipients all the rights that +you have. You must make sure that they, too, receive or can get the +source code. And you must show them these terms so they know their +rights. + + We protect your rights with two steps: (1) copyright the software, and +(2) offer you this license which gives you legal permission to copy, +distribute and/or modify the software. + + Also, for each author's protection and ours, we want to make certain +that everyone understands that there is no warranty for this free +software. If the software is modified by someone else and passed on, we +want its recipients to know that what they have is not the original, so +that any problems introduced by others will not reflect on the original +authors' reputations. + + Finally, any free program is threatened constantly by software +patents. We wish to avoid the danger that redistributors of a free +program will individually obtain patent licenses, in effect making the +program proprietary. To prevent this, we have made it clear that any +patent must be licensed for everyone's free use or not licensed at all. + + The precise terms and conditions for copying, distribution and +modification follow. + + GNU GENERAL PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. This License applies to any program or other work which contains +a notice placed by the copyright holder saying it may be distributed +under the terms of this General Public License. The "Program", below, +refers to any such program or work, and a "work based on the Program" +means either the Program or any derivative work under copyright law: +that is to say, a work containing the Program or a portion of it, +either verbatim or with modifications and/or translated into another +language. (Hereinafter, translation is included without limitation in +the term "modification".) Each licensee is addressed as "you". + +Activities other than copying, distribution and modification are not +covered by this License; they are outside its scope. The act of +running the Program is not restricted, and the output from the Program +is covered only if its contents constitute a work based on the +Program (independent of having been made by running the Program). +Whether that is true depends on what the Program does. + + 1. You may copy and distribute verbatim copies of the Program's +source code as you receive it, in any medium, provided that you +conspicuously and appropriately publish on each copy an appropriate +copyright notice and disclaimer of warranty; keep intact all the +notices that refer to this License and to the absence of any warranty; +and give any other recipients of the Program a copy of this License +along with the Program. + +You may charge a fee for the physical act of transferring a copy, and +you may at your option offer warranty protection in exchange for a fee. + + 2. You may modify your copy or copies of the Program or any portion +of it, thus forming a work based on the Program, and copy and +distribute such modifications or work under the terms of Section 1 +above, provided that you also meet all of these conditions: + + a) You must cause the modified files to carry prominent notices + stating that you changed the files and the date of any change. + + b) You must cause any work that you distribute or publish, that in + whole or in part contains or is derived from the Program or any + part thereof, to be licensed as a whole at no charge to all third + parties under the terms of this License. + + c) If the modified program normally reads commands interactively + when run, you must cause it, when started running for such + interactive use in the most ordinary way, to print or display an + announcement including an appropriate copyright notice and a + notice that there is no warranty (or else, saying that you provide + a warranty) and that users may redistribute the program under + these conditions, and telling the user how to view a copy of this + License. (Exception: if the Program itself is interactive but + does not normally print such an announcement, your work based on + the Program is not required to print an announcement.) + +These requirements apply to the modified work as a whole. If +identifiable sections of that work are not derived from the Program, +and can be reasonably considered independent and separate works in +themselves, then this License, and its terms, do not apply to those +sections when you distribute them as separate works. But when you +distribute the same sections as part of a whole which is a work based +on the Program, the distribution of the whole must be on the terms of +this License, whose permissions for other licensees extend to the +entire whole, and thus to each and every part regardless of who wrote it. + +Thus, it is not the intent of this section to claim rights or contest +your rights to work written entirely by you; rather, the intent is to +exercise the right to control the distribution of derivative or +collective works based on the Program. + +In addition, mere aggregation of another work not based on the Program +with the Program (or with a work based on the Program) on a volume of +a storage or distribution medium does not bring the other work under +the scope of this License. + + 3. You may copy and distribute the Program (or a work based on it, +under Section 2) in object code or executable form under the terms of +Sections 1 and 2 above provided that you also do one of the following: + + a) Accompany it with the complete corresponding machine-readable + source code, which must be distributed under the terms of Sections + 1 and 2 above on a medium customarily used for software interchange; or, + + b) Accompany it with a written offer, valid for at least three + years, to give any third party, for a charge no more than your + cost of physically performing source distribution, a complete + machine-readable copy of the corresponding source code, to be + distributed under the terms of Sections 1 and 2 above on a medium + customarily used for software interchange; or, + + c) Accompany it with the information you received as to the offer + to distribute corresponding source code. (This alternative is + allowed only for noncommercial distribution and only if you + received the program in object code or executable form with such + an offer, in accord with Subsection b above.) + +The source code for a work means the preferred form of the work for +making modifications to it. For an executable work, complete source +code means all the source code for all modules it contains, plus any +associated interface definition files, plus the scripts used to +control compilation and installation of the executable. However, as a +special exception, the source code distributed need not include +anything that is normally distributed (in either source or binary +form) with the major components (compiler, kernel, and so on) of the +operating system on which the executable runs, unless that component +itself accompanies the executable. + +If distribution of executable or object code is made by offering +access to copy from a designated place, then offering equivalent +access to copy the source code from the same place counts as +distribution of the source code, even though third parties are not +compelled to copy the source along with the object code. + + 4. You may not copy, modify, sublicense, or distribute the Program +except as expressly provided under this License. Any attempt +otherwise to copy, modify, sublicense or distribute the Program is +void, and will automatically terminate your rights under this License. +However, parties who have received copies, or rights, from you under +this License will not have their licenses terminated so long as such +parties remain in full compliance. + + 5. You are not required to accept this License, since you have not +signed it. However, nothing else grants you permission to modify or +distribute the Program or its derivative works. These actions are +prohibited by law if you do not accept this License. Therefore, by +modifying or distributing the Program (or any work based on the +Program), you indicate your acceptance of this License to do so, and +all its terms and conditions for copying, distributing or modifying +the Program or works based on it. + + 6. Each time you redistribute the Program (or any work based on the +Program), the recipient automatically receives a license from the +original licensor to copy, distribute or modify the Program subject to +these terms and conditions. You may not impose any further +restrictions on the recipients' exercise of the rights granted herein. +You are not responsible for enforcing compliance by third parties to +this License. + + 7. If, as a consequence of a court judgment or allegation of patent +infringement or for any other reason (not limited to patent issues), +conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot +distribute so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you +may not distribute the Program at all. For example, if a patent +license would not permit royalty-free redistribution of the Program by +all those who receive copies directly or indirectly through you, then +the only way you could satisfy both it and this License would be to +refrain entirely from distribution of the Program. + +If any portion of this section is held invalid or unenforceable under +any particular circumstance, the balance of the section is intended to +apply and the section as a whole is intended to apply in other +circumstances. + +It is not the purpose of this section to induce you to infringe any +patents or other property right claims or to contest validity of any +such claims; this section has the sole purpose of protecting the +integrity of the free software distribution system, which is +implemented by public license practices. Many people have made +generous contributions to the wide range of software distributed +through that system in reliance on consistent application of that +system; it is up to the author/donor to decide if he or she is willing +to distribute software through any other system and a licensee cannot +impose that choice. + +This section is intended to make thoroughly clear what is believed to +be a consequence of the rest of this License. + + 8. If the distribution and/or use of the Program is restricted in +certain countries either by patents or by copyrighted interfaces, the +original copyright holder who places the Program under this License +may add an explicit geographical distribution limitation excluding +those countries, so that distribution is permitted only in or among +countries not thus excluded. In such case, this License incorporates +the limitation as if written in the body of this License. + + 9. The Free Software Foundation may publish revised and/or new versions +of the General Public License from time to time. Such new versions will +be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + +Each version is given a distinguishing version number. If the Program +specifies a version number of this License which applies to it and "any +later version", you have the option of following the terms and conditions +either of that version or of any later version published by the Free +Software Foundation. If the Program does not specify a version number of +this License, you may choose any version ever published by the Free Software +Foundation. + + 10. If you wish to incorporate parts of the Program into other free +programs whose distribution conditions are different, write to the author +to ask for permission. For software which is copyrighted by the Free +Software Foundation, write to the Free Software Foundation; we sometimes +make exceptions for this. Our decision will be guided by the two goals +of preserving the free status of all derivatives of our free software and +of promoting the sharing and reuse of software generally. + + NO WARRANTY + + 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY +FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN +OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES +PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED +OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS +TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE +PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, +REPAIR OR CORRECTION. + + 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR +REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, +INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING +OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED +TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY +YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER +PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE +POSSIBILITY OF SUCH DAMAGES. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Programs + + If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + + To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +convey the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + + Copyright (C) + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + + +Also add information on how to contact you by electronic and paper mail. + +If the program is interactive, make it output a short notice like this +when it starts in an interactive mode: + + Gnomovision version 69, Copyright (C) year name of author + Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. + This is free software, and you are welcome to redistribute it + under certain conditions; type `show c' for details. + +The hypothetical commands `show w' and `show c' should show the appropriate +parts of the General Public License. Of course, the commands you use may +be called something other than `show w' and `show c'; they could even be +mouse-clicks or menu items--whatever suits your program. + +You should also get your employer (if you work as a programmer) or your +school, if any, to sign a "copyright disclaimer" for the program, if +necessary. Here is a sample; alter the names: + + Yoyodyne, Inc., hereby disclaims all copyright interest in the program + `Gnomovision' (which makes passes at compilers) written by James Hacker. + + , 1 April 1989 + Ty Coon, President of Vice + +This General Public License does not permit incorporating your program into +proprietary programs. If your program is a subroutine library, you may +consider it more useful to permit linking proprietary applications with the +library. If this is what you want to do, use the GNU Library General +Public License instead of this License. diff --git a/LICENSE.MIT b/LICENSE.MIT new file mode 100644 index 0000000..c662ae7 --- /dev/null +++ b/LICENSE.MIT @@ -0,0 +1,26 @@ +ndim's git utilities +Copyright (C) 2007 Hans Ulrich Niedermann +Portions (C) by others + +Files contained herein are distributed under the following license: + +Permission is hereby granted, free of charge, to any person obtaining a +copy of this software and associated documentation files (the "Software"), +to deal in the Software without restriction, including without limitation +the rights to use, copy, modify, merge, publish, distribute, sublicense, +and/or sell copies of the Software, and to permit persons to whom the +Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR +OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, +ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +OTHER DEALINGS IN THE SOFTWARE. + +All licensing questions regarding this software should be directed to + Hans Ulrich Niedermann diff --git a/Makefile-files b/Makefile-files new file mode 100644 index 0000000..ca6b323 --- /dev/null +++ b/Makefile-files @@ -0,0 +1,10 @@ +# -*- makefile -*- + +dist_doc_DATA += LICENSE.GPL LICENSE.MIT +UPLOAD_FILES += LICENSE.GPL LICENSE.MIT + +dist_doc_DATA += INSTALL +UPLOAD_FILES += INSTALL + +dist_doc_DATA += README +UPLOAD_FILES += README diff --git a/Makefile.am b/Makefile.am new file mode 100644 index 0000000..a6443da --- /dev/null +++ b/Makefile.am @@ -0,0 +1,91 @@ +CLEANFILES = +BUILT_SOURCES = +EXTRA_DIST = +man1_MANS = +UPLOAD_FILES = +doc_DATA = +dist_doc_DATA = +bin_PROGRAMS = +check_PROGRAMS = +bin_SCRIPTS = +check_SCRIPTS = +python_PYTHON = +nodist_python_PYTHON = +TESTS = +AM_INSTALLCHECK_STD_OPTIONS_EXEMPT = + +# For the test cases +export top_srcdir + +AM_CPPFLAGS = -I${top_builddir}/include + +ACLOCAL_AMFLAGS = -I m4 --install + +SUBDIRS = . test + +include build-helpers/package-version.mk + +include Makefile-files +include nbb/Makefile-files + +if HAVE_PYTHON +PYTHONPATH = $(DESTDIR)$(pythondir) +export PYTHONPATH +endif + +if HAVE_NDIM_MAN2TXT +.man.txt: + $(NDIM_MAN2TXT) "$<" > "$@.new" + test -s "$@.new" + mv -f "$@.new" "$@" +endif + +# Requires git 1.5 to work properly. +GIT = git +tag: + test -d "$(top_srcdir)/.git" + @cd "$(top_srcdir)" && $(GIT) status;: + @cd "$(top_srcdir)" && if $(GIT) diff-files --quiet; then :; else \ + echo "Uncommitted local changes detected."; \ + exit 1; fi + @cd "$(top_srcdir)" && if $(GIT) diff-index --cached --quiet HEAD; then :; else \ + echo "Uncommitted cached changes detected."; \ + exit 2; fi + @if test "x$(TAG)" = "x"; then \ + echo "TAG not defined. Try 'make tag TAG=2.11' or something similar."; \ + exit 3; \ + fi + @test "x$$(echo "$(TAG)" | $(SED) 's/^[0-9]\{1,\}\.[0-9]\{1,\}//')" = "x" || { \ + echo "TAG=$(TAG) is not in numerical 'x.y' format."; \ + exit 4; } + @test "x$$($(SED) '1q' '$(top_srcdir)/NEWS')" = "x$(PACKAGE_TARNAME) $(TAG)" || { \ + echo "NEWS does not start with entry for '$(PACKAGE_TARNAME) $(TAG)'"; \ + exit 5; } + @$(SED) -n '1p; 2,/^$(PACKAGE_TARNAME) / p' '$(top_srcdir)/NEWS' \ + | $(SED) '$$ { /^$(PACKAGE_TARNAME) / d }' | $(SED) '$$ { /^$$/d }' \ + > TAG-MESSAGE + @echo "=======================================================================" + @cat TAG-MESSAGE + @echo "=======================================================================" + @echo "Do you really want to tag this as release 'v$(TAG)'? Enter to continue, Ctrl-C to abort." + @read + msgfile="$$PWD/TAG-MESSAGE"; \ + cd "$(top_srcdir)" && $(GIT) tag -s -F "$$msgfile" "v$(TAG)"; \ + rm -f "$$msgfile" + +UPLOAD_DIR = upload-dir +ALL_UPLOAD_FILES = $(UPLOAD_FILES) $(distdir).tar.bz2 +upload: $(UPLOAD_FILES) dist tag + rm -rf "$(UPLOAD_DIR)" + mkdir -p "$(UPLOAD_DIR)" + for f in $(ALL_UPLOAD_FILES); do \ + ln "$$(test -e "$$f" || echo "$(top_srcdir)/")$$f" "$(UPLOAD_DIR)/"; \ + done + rsync -avz --delete "$(UPLOAD_DIR)/" $(RSYNC_HOST):$(RSYNC_DIR)/$(PACKAGE_TARNAME)/ + rm -rf "$(UPLOAD_DIR)" + if test -d "$(top_srcdir)/.git"; then cd "$(top_srcdir)" && git push public master; fi + +clean-local: + rm -rf "$(UPLOAD_DIR)" + +# End of Makefile.am. diff --git a/NEWS b/NEWS new file mode 100644 index 0000000..1920cf0 --- /dev/null +++ b/NEWS @@ -0,0 +1,2 @@ +nbb 1.20 + * Initial standalone version of nbb. diff --git a/README b/README new file mode 100644 index 0000000..82488a1 --- /dev/null +++ b/README @@ -0,0 +1,54 @@ +======================================================================== +ndim's git utilities - a collection of scripts and docs around git +Copyright (C) 2007, 2008 Hans Ulrich Niedermann +======================================================================== + + +The utilities in detail +======================= + + git-amb (status: stable) + Makes building, installing, and testing multiple git branches of + some source tree built with automake easy, clean and flexible. + The name stands for "git *a*uto*m*ake *b*uild". For details, see + git-amb(1) man page. + + git-buildmsg (status: testing) + Generate .h file containing information about the current git + working tree. Useful for programs' version messages in logs etc. + Generating the version message from git describe output appears + to be much cleaner, though. + + git-rebase-subtree (status: stale) + Rebase not only a single branch, but a whole "subtree of branches". + Useful for maintaining your own subtree of branches close to some + upstream's branch. + Probably obsoleted by automatic branch..rebase setup in git 1.5.6. + + nbb (status: experimental) + ndim's branch builder + Genericized extrapolation of git-amb. + Handles git and bzr. + Handles automake/autoconf. + Still very much work in progress, only useful for nbb development. + + +Updates +======= + + Home page: + http://nix.lauft.net/ndim-git-utils.git/ + + Git repository: + $ git clone http://nix.lauft.net/ndim-git-utils.git/ + + +License +======= + + Partly MIT, partly GPL. Shared parts dual-licensed. + + +======================================================================== +End of README for ndim's git utilities. +======================================================================== diff --git a/README-alpha b/README-alpha new file mode 100644 index 0000000..0d08d28 --- /dev/null +++ b/README-alpha @@ -0,0 +1,3 @@ +x.y versions are official releases +x.y.z-ccccccc versions are intermediate (alpha) versions, + where ccccccc is the ID of the git commit. diff --git a/build-helpers/package-version b/build-helpers/package-version new file mode 100755 index 0000000..61a3018 --- /dev/null +++ b/build-helpers/package-version @@ -0,0 +1,27 @@ +#!/bin/sh +# Syntax: +# $0 +# +# may be relative +# is relative to src/build topdir + +top_srcdir="${1-.}" +test -d "$top_srcdir" || { \ + echo "Could not change to top_srcdir '$1'" >&2; \ + exit 1; \ +} +version_stamp="${2-version-stamp}" + +# If GIT_DIR is set, use it. If not, try top_srcdir/.git. +if test -n "$GIT_DIR"; then :; +else GIT_DIR="$top_srcdir/.git"; export GIT_DIR +fi + +if test -f "$top_srcdir/$version_stamp"; then # dist source tree + cat "$top_srcdir/$version_stamp" | ${TR-tr} -d '\012' +elif test -d "$GIT_DIR"; then # git source tree + git_describe=`${GIT-git} describe 2>/dev/null || echo devel` + echo "$git_describe" | ${SED-sed} 's/^v//;s/-/./;s/-g/-/' | ${TR-tr} -d '\012' +else # ??? + echo "devel" | ${TR-tr} -d '\012' +fi diff --git a/build-helpers/package-version.mk b/build-helpers/package-version.mk new file mode 100644 index 0000000..4b191c5 --- /dev/null +++ b/build-helpers/package-version.mk @@ -0,0 +1,58 @@ +BUILD_SCRIPT_DIR = build-helpers + +# Check that package version matches git version before creating dist tarballs +dist-hook: git-version-check git-version-check-news git-version-stamp +distcheck-hook: git-version-check + +# Note: We cannot run autogen.sh from here, because we would need some way to +# restart the whole dist process from the start and there is none. +EXTRA_DIST += $(top_srcdir)/$(BUILD_SCRIPT_DIR)/package-version +git-version-check: + @git_ver=`$(top_srcdir)/$(BUILD_SCRIPT_DIR)/package-version $(top_srcdir) version-stamp`; \ + if test "x$${git_ver}" = "x$(PACKAGE_VERSION)"; then :; else \ + echo "ERROR: PACKAGE_VERSION and 'git describe' version do not match:"; \ + echo " current 'git describe' version: $${git_ver}"; \ + echo " current PACKAGE_VERSION: $(PACKAGE_VERSION)"; \ + rm -rf "$(top_srcdir)/autom4te.cache"; \ + if test -f "$(top_srcdir)/autogen.sh"; then \ + echo "Update PACKAGE_VERSION by running $(top_srcdir)/autogen.sh."; \ + else \ + echo "Update PACKAGE_VERSION by running autoreconf(1)."; \ + fi; \ + exit 1; \ + fi + +# FIXME: NEWS check uses ${foo%%-*} POSIX shell, tested +# with bash, dash, busybox. +git-version-check-news: + @git_ver=`$(top_srcdir)/$(BUILD_SCRIPT_DIR)/package-version $(top_srcdir) version-stamp`; \ + gv_xyz="$${git_ver%%-*}"; \ + gv_xy="$${gv_xyz%.*}"; \ + case `sed 1q $(top_srcdir)/NEWS` in \ + "$(PACKAGE_TARNAME) $${gv_xyz}") : ;; \ + "$(PACKAGE_TARNAME) $${gv_xy}.x") : ;; \ + *) \ + echo "NEWS not updated for version $${git_ver%%-*}; not releasing" 1>&2; \ + exit 1;; \ + esac + +# Version stamp files can only exist in tarball source trees. +# +# So there is no need to generate them anywhere else or to clean them +# up anywhere. +git-version-stamp: + echo "$(PACKAGE_VERSION)" > "$(distdir)/version-stamp" + +# Update *.h file to contain up-to-date version number +A_V = package-version-internal +CLEANFILES += $(A_V).h +BUILT_SOURCES += $(A_V).h.stamp +$(A_V).h.stamp: + @current_ver=`$(SHELL) $(top_srcdir)/$(BUILD_SCRIPT_DIR)/package-version $(top_srcdir) version-stamp`; \ + { echo '#ifndef PACKAGE_VERSION_INTERNAL_H'; \ + echo "#define PACKAGE_VERSION_INTERNAL \"$${current_ver}\""; \ + echo "#endif /* !PACKAGE_VERSION_INTERNAL */"; } > "$(A_V).h.new" + @if test -f "$(A_V).h" \ + && cmp "$(A_V).h.new" "$(A_V).h"; then :; \ + else cat "$(A_V).h.new" > "$(A_V).h"; fi; \ + rm -f "$(A_V).h.new" diff --git a/build-helpers/text2html.sed b/build-helpers/text2html.sed new file mode 100644 index 0000000..e8017dd --- /dev/null +++ b/build-helpers/text2html.sed @@ -0,0 +1,11 @@ +# Convert certain text files to HTML fragment +s/&/\&/g; +s//\>/g; +1s/^/
\
+/;
+$s/$/\
+<\/pre>/;
+s|\([a-z]\{1,\}\)@\([a-z0-9.-]\{1,\}\)|\1\@\2|;
+s|\([a-zA-Z0-9_-]\{1,\}\)\(([1-9])\)|\1\2|;
+s|\(http://[a-zA-Z0-9./_-]\{1,\}\)|\1|g;
diff --git a/configure.ac b/configure.ac
new file mode 100644
index 0000000..8be536a
--- /dev/null
+++ b/configure.ac
@@ -0,0 +1,40 @@
+########################################################################
+
+AC_PREREQ(2.61)
+AC_INIT([ndims branch builder],
+	[m4_esyscmd([./build-helpers/package-version . version-stamp])],
+	[hun@n-dimensional.de],
+	[nbb])
+AC_CONFIG_AUX_DIR([auto-aux])
+AC_CONFIG_SRCDIR([nbb/nbb.in])
+AC_CONFIG_MACRO_DIR([m4])
+AC_CONFIG_TESTDIR([test])
+AM_INIT_AUTOMAKE([-Wall -Werror foreign 1.10 dist-bzip2
+                  readme-alpha std-options])
+
+########################################################################
+
+AC_PROG_SED
+
+########################################################################
+
+AM_PATH_PYTHON([2.4], [:], [:])
+AM_CONDITIONAL([HAVE_PYTHON], [ test "x$PYTHON" != "x:" ])
+
+########################################################################
+
+m4_pattern_forbid([NDIM_REQUIRE_POSIX_SH])dnl
+NDIM_REQUIRE_POSIX_SH()dnl
+m4_pattern_forbid([NDIM_DETECT_MAN2TXT])dnl
+NDIM_DETECT_MAN2TXT()dnl
+
+########################################################################
+
+AC_CONFIG_FILES([Makefile])
+AC_CONFIG_FILES([nbb/nbb_lib.py:nbb/nbb_lib.in])
+AC_CONFIG_FILES([nbb/nbb:nbb/nbb.in], [chmod +x nbb/nbb])
+AC_CONFIG_FILES([test/atlocal])
+AC_CONFIG_FILES([test/Makefile])
+AC_OUTPUT
+
+########################################################################
diff --git a/doc/.htaccess b/doc/.htaccess
new file mode 100644
index 0000000..5558f6e
--- /dev/null
+++ b/doc/.htaccess
@@ -0,0 +1,15 @@
+AddDescription "MIT LICENSE" LICENSE.MIT
+AddDescription "GNU GENERAL PUBLIC LICENSE" LICENSE.GPL
+AddDescription "General description of ndim-git-utils" README
+AddDescription "Common code to several scripts" git-ndim-sh
+AddDescription "The git-amb(1) man page" git-amb.txt
+AddDescription "The git-amb script" git-amb
+AddDescription "The git-rebase-subtree(1) man page" git-rebase-subtree.txt
+AddDescription "The git-rebase-subtree script" git-rebase-subtree
+AddDescription "The git-buildmsg(1) man page" git-buildmsg.txt
+AddDescription "The git-buildmsg script" git-buildmsg
+AddDescription "ndim's git cheatsheet" ndim-git-cheatsheet.txt
+AddDescription "source tarball distribution" ndim-git-utils-*.tar.bz2
+ReadmeName FOOTER.html
+HeaderName HEADER.html
+IndexIgnore FOOTER.html HEADER.html ..
diff --git a/m4/ndim-check-sh-command-substitution.m4 b/m4/ndim-check-sh-command-substitution.m4
new file mode 100644
index 0000000..de2e80c
--- /dev/null
+++ b/m4/ndim-check-sh-command-substitution.m4
@@ -0,0 +1,26 @@
+dnl NDIM_CHECK_SH_COMMAND_SUBSTITUTION([ACTION-IF-SUPPORTED],
+dnl                                    [ACTION-IF-NOT-SUPPORTED)dnl
+dnl
+m4_pattern_forbid([NDIM_CHECK_SH_COMMAND_SUBSTITUTION])dnl
+AC_DEFUN([NDIM_CHECK_SH_COMMAND_SUBSTITUTION],[dnl
+AS_IF([test "x$ndim_sh_command_substitution" = "x"], [dnl
+AC_MSG_CHECKING([\$(cmd) type sh command substition])
+ndim_sh_command_substitution=no
+test "x$(pwd)" = "x`pwd`" && test "y$(echo "foobar")" = "y`echo foobar`" \
+     && ndim_sh_command_substitution=yes
+AC_MSG_RESULT([$ndim_sh_command_substitution])])
+m4_ifval([$1], [
+if test "x$ndim_sh_command_substitution" = "xyes"; then
+$1
+fi
+])dnl
+m4_ifval([$2], [
+if test "x$ndim_sh_command_substitution" = "xno"; then
+$2
+fi
+])
+])dnl
+dnl
+dnl Local Variables:
+dnl mode: autoconf
+dnl End:
diff --git a/m4/ndim-check-sh-functions.m4 b/m4/ndim-check-sh-functions.m4
new file mode 100644
index 0000000..0b03dd7
--- /dev/null
+++ b/m4/ndim-check-sh-functions.m4
@@ -0,0 +1,29 @@
+# version 1.11
+dnl NDIM_CHECK_SH_FUNCTIONS([ACTION-IF-SUPPORTED],
+dnl                         [ACTION-IF-NOT-SUPPORTED)dnl
+dnl
+m4_pattern_forbid([NDIM_CHECK_SH_FUNCTIONS])dnl
+AC_DEFUN([NDIM_CHECK_SH_FUNCTIONS],[dnl
+NDIM_CHECK_SH_COMMAND_SUBSTITUTION([], [dnl
+AC_MSG_ERROR([Sorry, POSIX sh with \$() required.])dnl
+])dnl
+AS_IF([test "x$ndim_sh_functions" = "x"], [dnl
+AC_MSG_CHECKING([whether sh supports POSIX sh functions])
+ndim_sh_functions=no
+test "x$(moo() { echo "meh"; }; moo)" = "xmeh" && ndim_sh_functions=yes
+AC_MSG_RESULT([$ndim_sh_functions])])
+m4_ifval([$1], [
+if test "x$ndim_sh_functions" = "xyes"; then
+$1
+fi
+])dnl
+m4_ifval([$2], [
+if test "x$ndim_sh_functions" = "xno"; then
+$2
+fi
+])
+])dnl
+dnl
+dnl Local Variables:
+dnl mode: autoconf
+dnl End:
diff --git a/m4/ndim-check-sh-param-expansion.m4 b/m4/ndim-check-sh-param-expansion.m4
new file mode 100644
index 0000000..b253131
--- /dev/null
+++ b/m4/ndim-check-sh-param-expansion.m4
@@ -0,0 +1,31 @@
+# version 1.11
+dnl NDIM_CHECK_SH_COMMAND_SUBSTITUTION([ACTION-IF-SUPPORTED],
+dnl                                    [ACTION-IF-NOT-SUPPORTED)dnl
+dnl
+m4_pattern_forbid([NDIM_CHECK_SH_PARAM_SUBSTITUTION])dnl
+AC_DEFUN([NDIM_CHECK_SH_PARAM_SUBSTITUTION],[dnl
+AS_IF([test "x$ndim_sh_param_substitution" = "x"], [dnl
+AC_MSG_CHECKING([\${foo%%bar} type sh param substitution])
+ndim_sh_param_substitution=no
+ndim_testvalue="12.34.56-1.23.4-615asdg"
+test "x${ndim_testvalue%%-*}" = "x12.34.56" \
+     && test "x${ndim_testvalue%-*}" = "x12.34.56-1.23.4" \
+     && test "x${ndim_testvalue##*-}" = "x615asdg" \
+     && test "x${ndim_testvalue#*-}" = "x1.23.4-615asdg" \
+     && ndim_sh_param_substitution=yes
+AC_MSG_RESULT([$ndim_sh_param_substitution])])
+m4_ifval([$1], [
+if test "x$ndim_sh_param_substitution" = "xyes"; then
+$1
+fi
+])dnl
+m4_ifval([$2], [
+if test "x$ndim_sh_param_substitution" = "xno"; then
+$2
+fi
+])
+])dnl
+dnl
+dnl Local Variables:
+dnl mode: autoconf
+dnl End:
diff --git a/m4/ndim-detect-man2txt.m4 b/m4/ndim-detect-man2txt.m4
new file mode 100644
index 0000000..023b5ba
--- /dev/null
+++ b/m4/ndim-detect-man2txt.m4
@@ -0,0 +1,45 @@
+# serial 1.6.3
+dnl
+dnl NDIM_DETECT_MAN2TXT
+dnl
+dnl Syntax:
+dnl
+dnl   configure.ac:
+dnl     NDIM_DETECT_MAN2TXT()dnl
+dnl
+dnl   Makefile.am:
+dnl     if HAVE_NDIM_MAN2TXT
+dnl     .txt.man:
+dnl          $(NDIM_MAN2TXT) $< > $@
+dnl     endif
+dnl
+dnl Define AM_CONDITIONAL HAVE_NDIM_MAN2TXT.
+dnl If that is true, define NDIM_MAN2TXT.
+dnl
+m4_pattern_forbid([NDIM_DETECT_MAN2TXT])dnl
+AC_DEFUN([NDIM_DETECT_MAN2TXT], [dnl
+NDIM_CHECK_SH_FUNCTIONS([], [dnl
+AC_MSG_ERROR([Sorry, POSIX sh with functions required.])dnl
+])dnl
+AC_ARG_VAR([MAN])
+AC_PATH_PROG([MAN], [man], [false])
+AC_ARG_VAR([COL])
+AC_PATH_PROG([COL], [col], [false])
+AM_CONDITIONAL([HAVE_NDIM_MAN2TXT],
+               [test "x$MAN" != "xfalse" &&
+                test "x$COL" != "xfalse" &&
+                test "x$(echo "ABXY" | $COL -b)" = "xBY"])
+AC_MSG_CHECKING([man and col -b work correctly])
+if test "x$HAVE_NDIM_MAN2TXT_FALSE" = "x#"; then
+	AC_MSG_RESULT([yes])
+	NDIM_MAN2TXT='m2t(){ $(MAN) "$$(dirname "[$$]1")/$$(basename "[$$]1")"|$(COL) -b; }; m2t'
+else
+	AC_MSG_RESULT([no $(echo "ABXY" | $COL -b)])
+	NDIM_MAN2TXT='false'
+fi
+AC_SUBST([NDIM_MAN2TXT])
+])dnl
+dnl
+dnl Local Variables:
+dnl mode: autoconf
+dnl End:
diff --git a/m4/ndim-require-posix-sh.m4 b/m4/ndim-require-posix-sh.m4
new file mode 100644
index 0000000..e5e4814
--- /dev/null
+++ b/m4/ndim-require-posix-sh.m4
@@ -0,0 +1,15 @@
+dnl NDIM_REQUIRE_POSIX_SH()dnl
+dnl dnl
+m4_pattern_forbid([NDIM_REQUIRE_POSIX_SH])dnl
+AC_DEFUN([NDIM_REQUIRE_POSIX_SH],[dnl
+NDIM_CHECK_SH_COMMAND_SUBSTITUTION([], [dnl
+AC_MSG_ERROR([Sorry, POSIX sh with \$() required.])dnl
+])dnl
+NDIM_CHECK_SH_PARAM_SUBSTITUTION([], [dnl
+AC_MSG_ERROR([Sorry, POSIX sh with \${foo%%bar} & Co. required.])dnl
+])dnl
+])dnl
+dnl
+dnl Local Variables:
+dnl mode: autoconf
+dnl End:
diff --git a/nbb/Makefile-files b/nbb/Makefile-files
new file mode 100644
index 0000000..1103489
--- /dev/null
+++ b/nbb/Makefile-files
@@ -0,0 +1,15 @@
+# -*- makefile -*-
+
+if HAVE_PYTHON
+
+bin_SCRIPTS += nbb/nbb
+EXTRA_DIST  += nbb/nbb.in
+CLEANFILES  += nbb/nbb
+
+nodist_python_PYTHON += nbb/nbb_lib.py
+
+endif
+
+CLEANFILES += nbb/nbb_lib.pyc
+
+# End of Makefile-files.
diff --git a/nbb/nbb.in b/nbb/nbb.in
new file mode 100644
index 0000000..92d1b3c
--- /dev/null
+++ b/nbb/nbb.in
@@ -0,0 +1,35 @@
+#!@PYTHON@
+"""\
+nbb - ndim's branch builder frontend
+"""
+
+import sys
+import os
+
+if __name__ == '__main__':
+   pythondir = "@pythondir@"
+   lib_found = False
+   for cond, path in [
+      (1, sys.path),
+      (os.path.exists(pythondir), [pythondir] + sys.path),
+      ]:
+      if cond:
+         sys.path = path
+         try:
+            import nbb_lib
+            lib_found = True
+            break
+         except ImportError, e:
+            pass
+   if not lib_found:
+      sys.stderr.write("nbb: Fatal: Could not load nbb_lib.\n")
+      sys.exit(3)
+   #sys.stdout.write("sys.path=%s\n" % repr(sys.path))
+   #sys.stdout.flush()
+   assert(nbb_lib.version == "@PACKAGE_VERSION@")
+   nbb_lib.main(sys.argv)
+
+# vim: syntax=python
+# Local Variables:
+# mode: python
+# End:
diff --git a/nbb/nbb_lib.in b/nbb/nbb_lib.in
new file mode 100644
index 0000000..17e2aa1
--- /dev/null
+++ b/nbb/nbb_lib.in
@@ -0,0 +1,584 @@
+"""\
+nbb (ndim's branch builder) from @PACKAGE_NAME@ @PACKAGE_VERSION@
+Build, install given branch of source code into a branch specific place
+Copyright (C) 2007,2008 Hans Ulrich Niedermann
+
+Usage: %(prog)s 
+
+Features:
+ * supports git branches (TBD: git config)
+ * supports bzr branches (requires useful branch nick, TBD: bzr config)
+ * does out-of-source-tree builds (in-source-tree-builds unsupported)
+ * direct support for automake/autoconf based build systems
+ * TBD: supports execution of user commands in source, build, install dirs
+
+TODO:
+ * VCS config support ('git config', etc.)
+ * Build system support: automake/autoconf, cmake
+ * Design nice user interface. Requirements:
+   * print top_srcdir, builddir, installdir
+   * start subshell in top_srcdir, builddir, installdir
+   * run 'autoreconf' type step
+   * run 'configure' type step
+   * run 'make' type step
+   * run 'make install' type step
+   * run custom (make) commands
+ * Bash syntax completion for that user interface.
+ * Man page or something similar.
+
+Command line interface (TBD):
+
+  Run default build commands:
+    $ %(prog)s [general options] init [command specific options]
+    $ %(prog)s [general options] configure [command specific options]
+    $ %(prog)s [general options] build [command specific options]
+    $ %(prog)s [general options] install [command specific options]
+
+  Run cleanup commands:
+    TBD
+
+  Get/set config:
+    $ %(prog)s [general options] config srcdir
+    $ %(prog)s [general options] config builddir []
+    $ %(prog)s [general options] config installdir []
+
+  Start an interactive shell in either of the three directories:
+    $ %(prog)s [general options] src-sh [command specific options]
+    $ %(prog)s [general options] build-sh [command specific options]
+    $ %(prog)s [general options] install-sh [command specific options]
+
+  Run command in builddir:
+    $ %(prog)s [general options] run  [...]
+    $ %(prog)s [general options] run [command specific options... <-->] ...
+
+  (Not sure about these)
+  Run a non-interactive shell command in either of the three directories:
+    $ %(prog)s [general options] src-sh [command specific options] ...
+    $ %(prog)s [general options] build-sh [command specific options] ...
+    $ %(prog)s [general options] install-sh [command specific options] 
+
+Global options:
+
+  -h --help          Print this help text
+  -V --version       Print program version number
+
+  -n --dry-run       Do not actually execute any commands
+
+  -b --build-system  Force buildsystem detection (%(buildsystems)s)
+  -v --vcs           Force VCS detection (%(vcssystems)s)
+"""
+
+import sys
+import os
+import getopt
+
+import subprocess
+import urlparse
+
+
+# Used to make sure nbb_lib and nbb fit together
+version = "@PACKAGE_VERSION@"
+
+
+########################################################################
+# Utility functions
+########################################################################
+
+
+def prog_stdout(call_list):
+    """Run program and return stdout (similar to shell backticks)"""
+    p = subprocess.Popen(call_list,
+                         stdout=subprocess.PIPE,
+                         stderr=subprocess.PIPE)
+    stdout, stderr = p.communicate(input=None)
+    return stdout.strip()
+
+
+class ProgramRunError(Exception):
+    """A program run returns a retcode != 0"""
+    def __init__(self, call_list, retcode, cwd=None):
+        self.call_list = call_list
+        self.retcode = retcode
+        if cwd:
+            self.cwd = cwd
+        else:
+            self.cwd = os.getcwd()
+    def __str__(self):
+        return ("Error running program (%s, retcode=%d, cwd=%s)"
+                % (repr(self.call_list),
+                   self.retcode,
+                   repr(self.cwd)))
+
+
+def prog_run(call_list):
+    """Run program showing its output. Raise exception if retcode != 0."""
+    print "RUN:", call_list
+    print "  in", os.getcwd()
+    # return None
+    p = subprocess.Popen(call_list)
+    stdout, stderr = p.communicate(input=None)
+    if p.returncode != 0:
+        raise ProgramRunError(call_list, p.returncode, os.getcwd())
+    return p.returncode
+
+
+class AbstractConfig(object):
+    """Return static config until we implement real config reading"""
+    def __init__(self, srcdir, nick):
+        self.srcdir = srcdir
+        self.nick = nick
+    def srcdir(self):
+        return os.path.join(self.srcdir)
+    def builddir(self):
+        return os.path.join(self.srcdir, "_build", self.nick)
+    def installdir(self):
+        return os.path.join(self.srcdir, "_install", self.nick)
+
+
+class CommandLineError(Exception):
+    def __init__(self, message, *args):
+        if args:
+            self.msg = message % args
+        else:
+            self.msg = message
+    def __str__(self):
+        return "Command line error: %s" % self.msg
+
+
+class DuplicatePluginName(Exception):
+    pass
+
+
+class PluginDict(object):
+    """Helper for GenericPluginMeta class
+
+    Behaves basically like a standard dict, but fails when asked
+    to update an existing value.
+    """
+    def __init__(self):
+        self.dict = {}
+    def __getitem__(self, *args):
+        return self.dict.__getitem__(*args)
+    def __setitem__(self, key, value):
+        if self.dict.has_key(key):
+            raise DuplicatePluginName()
+        else:
+            self.dict[key] = value
+    def items(self): return self.dict.items()
+    def keys(self): return self.dict.keys()
+    def values(self): return self.dict.values()
+    def __iter__(self): return self.dict.__iter__()
+    def __str__(self): return self.dict.__str__()
+    def __repr__(self): return self.dict.__repr__()
+    def __len__(self): return self.dict.__len__()
+    def has_key(self, key): return self.dict.has_key(key)
+
+
+########################################################################
+# Generic plugin system
+########################################################################
+# Plugin architecture (metaclass tricks) by Marty Alchin from
+# http://gulopine.gamemusic.org/2008/jan/10/simple-plugin-framework/
+# Slightly modified go store plugins as dict.
+########################################################################
+
+class GenericPluginMeta(type):
+    def __init__(cls, name, bases, attrs):
+        if not hasattr(cls, 'plugins'):
+            # This branch only executes when processing the mount point itself.
+            # So, since this is a new plugin type, not an implementation, this
+            # class shouldn't be registered as a plugin. Instead, it sets up a
+            # list where plugins can be registered later.
+            cls.plugins = PluginDict()
+        elif hasattr(cls, 'name'):
+            # This must be a plugin implementation, which should be registered.
+            # Simply appending it to the list is all that's needed to keep
+            # track of it later.
+            cls.plugins[cls.name] = cls
+        else:
+            # This must be an abstract subclass of plugins.
+            pass
+
+
+########################################################################
+# VCS Source Tree plugin system
+########################################################################
+
+class NotAVCSourceTree(Exception):
+    pass
+
+class AmbigousAVCSource(Exception):
+    def __init__(self, srcdir, matches):
+        super(AmbigousAVCSource, self).__init__()
+        self.srcdir = srcdir
+        self.matches = matches
+    def __str__(self):
+        return ("More than one source tree VCS type detected for '%s': %s"
+                % (self.srcdir, self.matches))
+
+
+class VCSourceTree(object):
+    """
+    Mount point for plugins which refer to actions that can be performed.
+
+    Plugins implementing this reference should provide the following
+    interface:
+
+    name  attribute
+        The text to be displayed, describing the version control system
+    __init__  function
+        Must raise NotAVCSourceTree() if it is not a VCS source tree
+    """
+    __metaclass__ = GenericPluginMeta
+
+    def detect(cls, srcdir):
+        """Detect VCS tree type and return object representing it"""
+        if len(VCSourceTree.plugins) < 1:
+            raise "No VC source tree classes registered"
+        matches = PluginDict()
+        print "VCSourceTree.detect", VCSourceTree.plugins
+        print "srcdir", srcdir
+        for key, klass in VCSourceTree.plugins.items():
+            print "key", key
+            print "klass", klass
+            try:
+                matches[key] = klass(srcdir)
+                print "MATCH:", srcdir
+            except NotAVCSourceTree, e:
+                pass
+        if len(matches) > 1:
+            raise AmbigousAVCSource(srcdir, str(matches.values()))
+        elif len(matches) < 1:
+            raise NotAVCSourceTree(srcdir)
+        print "Matches:", matches
+        return matches[matches.keys()[0]]
+    detect = classmethod(detect)
+
+    def get_config(self):
+        """Get configuration object which determines builddir etc"""
+        return AbstractConfig(self.tree_root(), self.branch_name())
+
+    def tree_root(self):
+        """Get absolute path to source tree root"""
+        raise NotImplementedError()
+
+    def branch_name(self):
+        """Return name identifying the branch"""
+        raise NotImplementedError()
+
+    def __str__(self):
+        return "VCS-Source-Tree(%s, %s, %s)" % (self.name,
+                                                repr(self.tree_root()),
+                                                repr(self.branch_name()))
+
+
+########################################################################
+# Command plugin system
+########################################################################
+
+class Command(object):
+    """
+    Mount point for plugins which refer to commands that can be performed.
+
+    Plugins implementing this reference should provide the following
+    interface:
+
+    name  attribute
+        The text to be displayed, describing the version control system
+    summary attribute
+        Short (less than 50 chars) command summary line
+
+    validate_args(*args, **kwargs)  function
+        Must raise CommandLineError() if it encounters invalid arguments in cmdargs
+    run() function
+        Actually run the function
+
+    FFF(*args, **kwargs)
+        *args are the arguments from the command line
+        **kwargs are additional parameters from within the program
+    """
+    __metaclass__ = GenericPluginMeta
+
+    def __init__(self, *args, **kwargs):
+        self.validate_args(*args, **kwargs)
+        self.args = args
+        self.kwargs = kwargs
+
+    def run(self):
+        """Run the command"""
+        raise NotImplementedError()
+
+    def validate_args(self, *args, **kwargs):
+        """Validate command line arguments"""
+        print "Command: ", self.name
+        print "*args:   ", args
+        print "**kwargs:", kwargs
+	if len(args) > 0:
+            raise CommandLineError("'%s' command takes no parameters", self.name)
+
+    def __str__(self):
+        return "Command(%s, %s)" % (self.cmd_name, self.cmdargs)
+
+
+class HelpCommand(Command):
+    name = 'help'
+    summary = 'print help text'
+    def run(self):
+        print "List of commands:"
+        keys = Command.plugins.keys()
+        keys.sort()
+        for k in keys:
+           print "\t%-15s\t%s" % (k, Command.plugins[k].summary)
+
+class InternalConfigCommand(Command):
+    name = 'internal-config'
+    summary = 'print internal program configuration'
+    def run(self):
+        print "Source tree types:",  ", ".join(VCSourceTree.plugins.keys())
+        print "Build system types:", ", ".join(BSSourceTree.plugins.keys())
+        print "Commands:",           ", ".join(Command.plugins.keys())
+
+class SourceClassCommand(Command):
+    """Base class for commands acting on source trees"""
+    def __init__(self, *args, **kwargs):
+        super(SourceClassCommand, self).__init__(*args, **kwargs)
+        srcdir = os.getcwd()
+        absdir = os.path.abspath(srcdir)
+        self.vcs_sourcetree = VCSourceTree.detect(absdir)
+        print "vcs_sourcetree", str(self.vcs_sourcetree)
+        assert(self.vcs_sourcetree)
+        self.bs_sourcetree = BSSourceTree.detect(self.vcs_sourcetree)
+        print "bs_sourcetree", str(self.bs_sourcetree)
+
+class BuildTestCommand(SourceClassCommand):
+    name = 'build-test'
+    summary = 'simple build test'
+    def run(self):
+        self.bs_sourcetree.init()
+        self.bs_sourcetree.configure()
+        self.bs_sourcetree.build()
+        self.bs_sourcetree.install()
+
+
+########################################################################
+# VCS Source Tree plugins
+########################################################################
+
+class GitSourceTree(VCSourceTree):
+
+    name = 'git'
+
+    def __init__(self, srcdir):
+        os.chdir(srcdir)
+        if "true" != prog_stdout(["git", "rev-parse",
+                                  "--is-inside-work-tree"]):
+            raise NotAVCSourceTree()
+        reldir = prog_stdout(["git", "rev-parse", "--show-cdup"])
+        if reldir:
+            os.chdir(reldir)
+        self.__tree_root = os.getcwd()
+
+    def tree_root(self):
+        return self.__tree_root
+
+    def branch_name(self):
+        bname = prog_stdout(["git", "symbolic-ref", "HEAD"])
+        refs,heads,branch = bname.split('/')
+        assert(refs=='refs' and heads=='heads')
+        return branch
+
+
+class BzrSourceTree(VCSourceTree):
+
+    name = 'bzr'
+
+    def __init__(self, srcdir):
+        try:
+            import bzrlib.workingtree
+            wt,b = bzrlib.workingtree.WorkingTree.open_containing(srcdir)
+        except bzrlib.errors.NotBranchError:
+            raise NotAVCSourceTree()
+        except ImportError:
+            raise NotAVCSourceTree()
+        self.wt = wt
+        #print "wt:", wt
+        #print "wt:", dir(wt)
+        #print "wt.branch:", wt.branch
+        #print "wt.branch:", dir(wt.branch)
+        #print "wt.branch.nick:", wt.branch.nick
+        #print "wt.branch.abspath:", wt.branch.abspath
+        #print "wt.branch.base:", wt.branch.base
+        #print "wt.branch.basis_tree:", wt.branch.basis_tree()
+
+    def tree_root(self):
+        proto,host,path,some,thing = urlparse.urlsplit(self.wt.branch.base)
+        assert(proto == "file" and host == "")
+        assert(some == "" and thing == "")
+        return path
+
+    def branch_name(self):
+        return self.wt.branch.nick
+
+
+########################################################################
+# Buildsystem Source Tree plugins
+########################################################################
+
+class NotABSSourceTree(Exception): pass
+
+
+class BSSourceTree(object):
+    __metaclass__ = GenericPluginMeta
+
+    def detect(cls, vcs_tree):
+        """Find BS tree type and return it"""
+        if len(BSSourceTree.plugins) < 1:
+            raise "No BS source tree classes registered"
+        matches = PluginDict()
+        for key, klass in BSSourceTree.plugins.items():
+            try:
+                t = klass(vcs_tree)
+                matches[key] = t
+            except NotABSSourceTree:
+                pass
+        if len(matches) > 1:
+            raise ("More than one source tree BS type detected for '%s': %s"
+                   % (vcs_tree, ", ".join(map(lambda x:str(x), matches))))
+        elif len(matches) < 1:
+            raise "Source tree type for '%s' not detected" % (vcs_tree,)
+        print "Matches:", matches
+        return matches[matches.keys()[0]]
+    detect = classmethod(detect)
+
+    def __str__(self):
+        return "BS-Source-Tree(%s, %s)" % (self.name,
+                                           repr(self.tree_root()))
+
+    # Abstract methods
+    def tree_root(self): raise NotImplementedError()
+    def init(self): raise NotImplementedError()
+    def configure(self): raise NotImplementedError()
+    def build(self): raise NotImplementedError()
+    def install(self): raise NotImplementedError()
+
+
+class AutomakeSourceTree(BSSourceTree):
+    name = 'automake'
+    def __init__(self, vcs_tree):
+        srcdir = vcs_tree.tree_root()
+        self.config = vcs_tree.get_config()
+        flag = False
+        for f in [ os.path.join(srcdir, 'configure.ac'),
+                   os.path.join(srcdir, 'configure.in'),
+                   ]:
+            if os.path.exists(f):
+                flag = True
+                break
+        if not flag:
+            raise NotABSSourceTree()
+        self.srcdir = srcdir
+
+    def tree_root(self):
+        return self.srcdir
+
+    def init(self):
+        """'autoreconf'"""
+        prog_run(["autoreconf", "-v", "-i", "-s", self.srcdir])
+
+    def configure(self):
+        """'configure --prefix'"""
+        builddir = self.config.builddir()
+        if not os.path.exists(builddir): os.makedirs(builddir)
+        os.chdir(builddir)
+        prog_run(["%s/configure" % self.srcdir,
+                  "--prefix=%s" % self.config.installdir()
+                  ])
+
+    def build(self):
+        """'make'"""
+        os.chdir(self.config.builddir())
+        prog_run(["make", ])
+
+    def install(self):
+        """'make install'"""
+        os.chdir(self.config.builddir())
+        prog_run(["make", "install", "INSTALL=/usr/bin/install -p"])
+
+
+########################################################################
+# Commands
+########################################################################
+
+class NBB_Command(object):
+    def __init__(self, cmd, cmdargs):
+        if Command.plugins.has_key(cmd):
+            try:
+                c = Command.plugins[cmd](*cmdargs)
+                c.run()
+            except CommandLineError, e:
+                print "%(prog)s: Fatal:" % (outdict), e
+                sys.exit(2)
+            except ProgramRunError, e:
+                print "%(prog)s: Fatal:" % (outdict), e
+                print "Program aborted."
+        else:
+            print "Fatal: Unknown command '%s'" % cmd
+	    raise NotImplementedError()
+        return
+
+
+########################################################################
+# Main program
+########################################################################
+
+
+outdict = {}
+outdict['vcssystems']   = ", ".join(VCSourceTree.plugins.keys())
+outdict['buildsystems'] = ", ".join(BSSourceTree.plugins.keys())
+
+
+def print_help():
+    print __doc__ % outdict,
+
+
+def main(argv):
+
+    prog = argv[0]
+    idx = prog.rfind('/')
+    if idx >= 0:
+        prog = prog[idx+1:]
+    outdict['prog'] = prog
+
+    if len(argv) < 2:
+        print "Fatal: %(prog)s requires some arguments" % outdict
+        return 2
+
+    verbosity = 0
+    i = 1
+    while i /dev/null && pwd`:`cd $(top_builddir)/nbb > /dev/null && pwd` \
+		$(TESTSUITEFLAGS)
+
+installcheck-local: atconfig atlocal $(srcdir)/$(TESTSUITE)
+	$(SHELL) "$(srcdir)/$(TESTSUITE)" AUTOTEST_PATH='$(bindir)' \
+		$(TESTSUITEFLAGS)
+
+clean-local:
+	test ! -f '$(srcdir)/$(TESTSUITE)' || \
+		$(SHELL) '$(srcdir)/$(TESTSUITE)' --clean
+
+# Note about the location of testsuite.at, $(TESTSUITE), and package.m4:
+# We locate these files in the $(srcdir), because
+#  a) They are shipped in the source tarball.
+#  b) If they are created in $(builddir), they will need to be removed on
+#     "make clean" or "make distclean". Re-generation requires tools a
+#     normal system does not need to have.
+#  c) They do not change depending on any configure run, they only change
+#     depending on configure.ac or tests/Makefile.am updates - and those
+#     require special build tools to handle anyway. Thus, a normal build
+#     will not touch these files at all and just leave the filese from
+#     upstream in place.
+
+# testsuite.at depends on Makefile.in to make sure that changes in the
+# list of TESTCASES are reflected in testsuite.at. We do not depend on
+# Makefile, as Makefile is re-created on every ./configure run, and that
+# does not imply an addition to TESTCASES.
+EXTRA_DIST += $(srcdir)/testsuite.at
+$(srcdir)/testsuite.at: $(TESTCASES) Makefile.in
+	{ \
+		echo "dnl testsuite.at autogenerated from tests/Makefile.am"; \
+		echo "AT_INIT()"; : "([$(TESTSUITE_NAME)])"; \
+		echo "AT_COPYRIGHT([$(TESTSUITE_COPYRIGHT)])"; \
+		for exe in $(TESTED_EXECUTABLES); do \
+			echo "AT_TESTED([$${exe}])"; \
+		done; \
+		for tc in $(TESTCASES); do \
+			echo "m4_include([$${tc}])"; \
+		done; \
+	} > $(srcdir)/testsuite.at
+
+# FIXME: Hack to handle unset AUTOM4TE variable
+EXTRA_DIST += $(srcdir)/$(TESTSUITE)
+$(srcdir)/$(TESTSUITE): $(srcdir)/testsuite.at $(srcdir)/local.at $(srcdir)/package.m4
+	AUTOM4TE="$(AUTOM4TE)"; \
+	if test "x$${AUTOM4TE}" = "x"; then AUTOM4TE="autom4te"; fi; \
+	$${AUTOM4TE} --language=autotest -I '$(srcdir)' -o $(TESTSUITE).tmp $(srcdir)/testsuite.at
+	if test -f $(srcdir)/$(TESTSUITE) && cmp $(TESTSUITE).tmp $(srcdir)/$(TESTSUITE); \
+	then rm -f $(TESTSUITE).tmp; \
+	else mv -f $(TESTSUITE).tmp $(srcdir)/$(TESTSUITE); fi
+
+EXTRA_DIST += $(srcdir)/package.m4
+$(srcdir)/package.m4: $(top_srcdir)/configure.ac $(top_builddir)/config.status Makefile.in
+	:; { \
+		echo '# Signature of the current package (generated by tests/Makefile.am).'; \
+		echo 'm4_define([AT_PACKAGE_NAME],      [@PACKAGE_NAME@])'; \
+		echo 'm4_define([AT_PACKAGE_TARNAME],   [@PACKAGE_TARNAME@])'; \
+		echo 'm4_define([AT_PACKAGE_VERSION],   [@PACKAGE_VERSION@])'; \
+		echo 'm4_define([AT_PACKAGE_STRING],    [@PACKAGE_STRING@])'; \
+		echo 'm4_define([AT_PACKAGE_BUGREPORT], [@PACKAGE_BUGREPORT@])'; \
+	} > package.m4.tmp
+	if test -f $(srcdir)/package.m4 && cmp package.m4.tmp $(srcdir)/package.m4; \
+	then rm -f package.m4.tmp; \
+	else mv -f package.m4.tmp $(srcdir)/package.m4; fi
+
+dist-hook:
+	$(MAKE) $(srcdir)/package.m4 $(srcdir)/$(TESTSUITE)
+
+# End of tests/Makefile.am.
+
diff --git a/test/atlocal.in b/test/atlocal.in
new file mode 100644
index 0000000..e69de29
diff --git a/test/autotest.at b/test/autotest.at
new file mode 100644
index 0000000..3017987
--- /dev/null
+++ b/test/autotest.at
@@ -0,0 +1,9 @@
+AT_SETUP([autotest tests])
+AT_KEYWORDS([autotest])
+AT_CHECK([:], [0], [], [])
+AT_KEYWORDS([shell])
+AT_TESTED([sh grep cmp])
+AT_CHECK([${SHELL} --version], [ignore], [stdout], [stderr])
+AT_CAPTURE_FILE([stdout])
+AT_CAPTURE_FILE([stderr])
+AT_CLEANUP()
diff --git a/test/local.at b/test/local.at
new file mode 100644
index 0000000..1f52645
--- /dev/null
+++ b/test/local.at
@@ -0,0 +1,3 @@
+AT_COPYRIGHT([Copyright (C) 2007,2008 Hans Ulrich Niedermann])
+AT_TESTED([autom4te autoconf autoheader autoupdate autoreconf])
+# Local initialization of the test environment would happen here
diff --git a/test/nbb-basic.at b/test/nbb-basic.at
new file mode 100644
index 0000000..68ddf71
--- /dev/null
+++ b/test/nbb-basic.at
@@ -0,0 +1,41 @@
+dnl ===================================================================
+
+AT_COPYRIGHT([Copyright (C) 2008 Hans Ulrich Niedermann])
+AT_TESTED([nbb])
+
+dnl ===================================================================
+
+dnl ===================================================================
+
+AT_SETUP([nbb: --version option])
+AT_KEYWORDS([nbb version])
+AT_CHECK([nbb --version],
+[0],
+[nbb (ndims git utilities) AT_PACKAGE_VERSION
+])
+AT_CLEANUP()
+
+dnl ===================================================================
+
+AT_SETUP([nbb: --help option])
+AT_KEYWORDS([nbb help])
+AT_CHECK([nbb --help], [0], [ignore], [ignore])
+AT_CLEANUP()
+
+dnl ===================================================================
+
+AT_SETUP([nbb: help command])
+AT_KEYWORDS([nbb help])
+AT_CHECK([nbb help], [0], [ignore], [])
+AT_CLEANUP()
+
+dnl ===================================================================
+
+AT_SETUP([nbb: internal-config command])
+AT_KEYWORDS([nbb internal-config])
+AT_CHECK([nbb internal-config], [0], [ignore], [])
+AT_CLEANUP()
+
+dnl ===================================================================
+
+dnl ===================================================================
diff --git a/test/nbb-commands.at b/test/nbb-commands.at
new file mode 100644
index 0000000..4f045ab
--- /dev/null
+++ b/test/nbb-commands.at
@@ -0,0 +1,44 @@
+dnl ===================================================================
+
+AT_COPYRIGHT([Copyright (C) 2008 Hans Ulrich Niedermann])
+AT_TESTED([nbb])
+
+dnl ===================================================================
+
+AT_SETUP([nbb: git config default defaults])
+AT_KEYWORDS([nbb git config])
+AT_CHECK([mkdir test.git && cd test.git])
+AT_CHECK([cd test.git && git init], [0],
+[Initialized empty Git repository in .git/
+])
+echo "$PWD/test.git" > expout
+AT_CHECK([cd test.git && nbb config srcdir], [0], [expout])
+echo "$PWD/test.git/_build/_master" > expout
+AT_CHECK([cd test.git && nbb config builddir], [0], [expout])
+echo "$PWD/test.git/_install/master" > expout
+AT_CHECK([cd test.git && nbb config installdir], [0], [expout])
+AT_CHECK([rm -rf test.git])
+AT_CLEANUP()
+
+dnl ===================================================================
+
+AT_SETUP([nbb: bzr config defaults])
+AT_KEYWORDS([nbb bzr config])
+AT_CHECK([mkdir test.bzr && cd test.bzr])
+AT_CHECK([cd test.bzr && bzr init])
+echo "$PWD/test.bzr" > expout
+AT_CHECK([cd test.bzr && nbb config srcdir], [0], [expout])
+echo "$PWD/test.bzr/_build" > expout
+AT_CHECK([cd test.bzr && nbb config builddir], [0], [expout])
+echo "$PWD/test.bzr/_install" > expout
+AT_CHECK([cd test.bzr && nbb config installdir], [0], [expout])
+AT_CHECK([rm -rf test.git])
+AT_CLEANUP()
+
+dnl ===================================================================
+
+dnl ===================================================================
+
+dnl ===================================================================
+
+
-- 
cgit