now can build source and binary
[pspp] / make-bin-dist.as
diff --git a/make-bin-dist.as b/make-bin-dist.as
new file mode 100644 (file)
index 0000000..742f2bf
--- /dev/null
@@ -0,0 +1,166 @@
+# -* autoconf -*-
+
+BP_INIT([make-binary.log])
+
+usage=["\
+Usage: $0 [OPTION]... PSPP_DIST.TAR.GZ
+where PSPP_DIST.TAR.GZ is a PSPP tarball prepared by \"make dist\".
+
+Options:
+  -b, --binid=BINID         Use BINID to identify binary.
+  -h, --help                Print this usage message and exit
+  -f, --force               Delete existing directory instead of aborting
+
+Report bugs to <bug-gnu-pspp@gnu.org>.
+GNU PSPP: <http://www.gnu.org/software/pspp/>.
+General help using GNU software: <http://www.gnu.org/gethelp/>."]
+
+version=["\
+make-binary (@PACKAGE_NAME@) @VERSION@
+Copyright (C) 2010 Free Software Foundation, Inc.
+License GPLv3+/Autoconf: GNU GPL version 3 or later
+<http://gnu.org/licenses/gpl.html>, <http://gnu.org/licenses/exceptions.html>
+This is free software: you are free to change and redistribute it.
+There is NO WARRANTY, to the extent permitted by law.
+
+Written by Ben Pfaff."]
+
+help="\
+Try \`$as_me --help' for more information."
+
+exit_missing_arg='
+  m4_bpatsubst([AS_ERROR([option `$[1]' requires an argument$as_nl$help])],
+    ['], ['\\''])'
+# restore font-lock: '
+
+# Variables.
+overwrite=false
+BINID=
+
+# Parse command line.
+while test $# -gt 0 ; do
+  option=[`expr "x$1" : 'x\(--[^=]*\)' \| \
+              "x$1" : 'x\(-.\)'`]
+  optarg=[`expr "x$1" : 'x--[^=]*=\(.*\)' \| \
+              "x$1" : 'x-.\(.*\)'`]
+  case $1 in
+    --version | -V )
+       echo "$version" ; exit ;;
+    --help | -h )
+       AS_ECHO(["$usage"]); exit ;;
+
+    --force | -f )
+       overwrite=true ;;
+
+    --binid=* | -b?* )
+       BINID=$optarg
+       shift ;;
+    --binid | -b )
+       test $# = 1 && eval "$exit_missing_arg"
+       BINID=$2
+       shift; shift ;;
+
+    -- )     # Stop option processing
+       shift; break ;;
+    - )        # Use stdin as input.
+       break ;;
+    -* )
+       exec >&2
+       AS_ERROR([invalid option `$[1]'$as_nl$help]) ;; #`
+    * )
+       break ;;
+  esac
+done
+
+# Find the input file.
+case $# in
+  1)
+    tarball=$1
+    ;;
+  *) exec >&2
+     AS_ERROR([invalid number of arguments$as_nl$help]) ;;
+esac
+
+if test ! -e "$tarball"; then
+   exec >&2
+   AS_ERROR([$tarball does not exist])
+fi
+
+BP_START_STEP([Determining $tarball target directory])
+DIST_DIR=`zcat $tarball | tar tf - 2>/dev/null | sed 1q | sed s,/.*,,`
+BP_SET_VAR([DIST_DIR])
+if test X$DIST_DIR = X; then
+  BP_ERROR([failed to determine $tarball target directory])
+elif test -e "$DIST_DIR"; then
+  if test $overwrite = true; then
+    chmod -R u+w "$DIST_DIR"
+    rm -rf "$DIST_DIR"
+  else
+    BP_ERROR([$DIST_DIR exists and --force not specified])
+  fi
+fi
+
+BP_START_STEP([Extracting source tarball])
+BP_RUN([zcat $tarball | tar xf - >&AS_MESSAGE_LOG_FD 2>&1])
+
+BP_START_STEP([Extracting tar version])
+DIST_VERSION=`$DIST_DIR/configure --version 2>/dev/null | sed 1q | sed 's/.* //'`
+BP_SET_VAR([DIST_VERSION])
+
+BP_START_STEP([Configuring])
+BP_RUN([mkdir $DIST_DIR/_build >&AS_MESSAGE_LOG_FD 2>&1])
+BP_RUN([chmod -R a-w $DIST_DIR >&AS_MESSAGE_LOG_FD 2>&1])
+BP_RUN([chmod u+w $DIST_DIR/_build >&AS_MESSAGE_LOG_FD 2>&1])
+BP_TRY_RUN([(cd $DIST_DIR/_build && ../configure --enable-relocatable --prefix='') >&AS_MESSAGE_LOG_FD 2>&1])
+_bp_status=$?
+for base in config.h config.log; do
+  fn=$DIST_DIR/_build/$base
+  if test -e "$fn"; then
+    BP_COPY_OUTPUT([build configuration], [$fn])
+  fi
+done
+if test $_bp_status != 0; then
+  AS_ECHO(["$as_me:$LINENO: command exited with status $_bp_status"]) >&AS_MESSAGE_LOG_FD
+fi
+
+BP_START_STEP([Determine target name])
+if test "X$BINID" = X; then
+  BINID=`sed -n 's/^Target: \(.*\)$/\1/p' < $DIST_DIR/_build/config.log 2>/dev/null | sed 1q`
+  if test "X$BINID" = X; then
+    BINID=`./config.guess`
+  fi
+fi  
+BP_SET_VAR([BINID])
+
+BP_START_STEP([Build])
+BP_RUN([(cd $DIST_DIR/_build && make) >&AS_MESSAGE_LOG_FD 2>&1])
+
+BP_START_STEP([Install])
+BP_RUN([(cd $DIST_DIR/_build && make install DESTDIR=$PWD/pspp-$DIST_VERSION-$BINID) >&AS_MESSAGE_LOG_FD 2>&1])
+
+BP_START_STEP([Make binary distribution])
+BP_RUN([(cd $DIST_DIR/_build && tar cfz pspp-$DIST_VERSION-$BINID.tar.gz pspp-$DIST_VERSION-$BINID) >&AS_MESSAGE_LOG_FD 2>&1])
+BP_MOVE_OUTPUT([binary distribution], [$DIST_DIR/_build/pspp-$DIST_VERSION-$BINID.tar.gz])
+
+BP_START_STEP([Check])
+BP_TRY_RUN([(cd $DIST_DIR/_build && make check) >&AS_MESSAGE_LOG_FD 2>&1])
+_bp_status=$?
+for base in tests/testsuite.log tests/testsuite.dir; do
+  fn=$DIST_DIR/_build/$base
+  if test -e "$fn"; then
+    BP_MOVE_OUTPUT([test logs], [$fn])
+  fi
+done
+if test $_bp_status != 0; then
+  AS_ECHO(["$as_me:$LINENO: command exited with status $_bp_status"]) >&AS_MESSAGE_LOG_FD
+fi
+
+BP_START_STEP([Uninstall])
+BP_RUN([(cd $DIST_DIR/_build && make uninstall DESTDIR=$PWD/pspp-$DIST_VERSION-$BINID) >&AS_MESSAGE_LOG_FD 2>&1])
+
+BP_START_STEP([Check uninstall])
+BP_RUN([(cd $DIST_DIR/_build && make distuninstallcheck distuninstallcheck_dir=$PWD/pspp-$DIST_VERSION-$BINID) >&AS_MESSAGE_LOG_FD 2>&1])
+
+# distcleancheck
+
+BP_FINISH