From a01ced11728bfea93f8bb130899dedae65678530 Mon Sep 17 00:00:00 2001 From: Chris Hanson Date: Mon, 22 Feb 2010 02:41:49 -0800 Subject: [PATCH] Simplify! Implement make-system-file. --- dist/make-doc-files | 5 +- dist/make-liarc-files | 5 +- dist/make-native-files | 10 ++-- dist/make-src-files | 14 +++-- dist/make-system-file | 82 +++++++++++++++++++++++++++ dist/shared.sh | 122 +++++++++++++++++++++++++---------------- 6 files changed, 176 insertions(+), 62 deletions(-) create mode 100755 dist/make-system-file diff --git a/dist/make-doc-files b/dist/make-doc-files index 389f6d4a0..6eb9a9195 100755 --- a/dist/make-doc-files +++ b/dist/make-doc-files @@ -25,6 +25,7 @@ . "$(dirname "${0}")"/shared.sh make_output_dir +standard_args BUILD_DIR=doc-build @@ -50,7 +51,7 @@ make_archive_dir () } notify "Building documentation" -unpack_dist_to "${BUILD_DIR}" +unpack_dist_file_to "${DIST_DIR}" "${BUILD_DIR}" run_command "${DOC_OUT}"-build "${BUILD_DIR}"/doc build_docs notify "Making doc image for distributions" @@ -67,4 +68,4 @@ for FORMAT in html info pdf; do my_rm_rf "${DIST_DIR}" done -notify "Success!" +notify_finished diff --git a/dist/make-liarc-files b/dist/make-liarc-files index 3ffd8e086..bb44ea1be 100755 --- a/dist/make-liarc-files +++ b/dist/make-liarc-files @@ -25,6 +25,7 @@ . "$(dirname "${0}")"/shared.sh make_output_dir +standard_args LIARC_DIR=${PROJECT_NAME}-c-${RELEASE} @@ -34,7 +35,7 @@ compile_liarc_dist () } notify "Creating the liarc distribution directory" -unpack_dist_to "${LIARC_DIR}" +unpack_dist_file_to "${DIST_DIR}" "${LIARC_DIR}" notify "Compiling the liarc bootstrap files" run_command "${LIARC_OUT}"-compile "${LIARC_DIR}"/src compile_liarc_dist @@ -42,4 +43,4 @@ run_command "${LIARC_OUT}"-compile "${LIARC_DIR}"/src compile_liarc_dist notify "Creating liarc archive file" make_tar_file "${LIARC_OUT}" "${LIARC_DIR}" -notify "Success!" +notify_finished diff --git a/dist/make-native-files b/dist/make-native-files index e002cdad0..2165854d8 100755 --- a/dist/make-native-files +++ b/dist/make-native-files @@ -25,6 +25,7 @@ . "$(dirname "${0}")"/shared.sh make_output_dir +standard_args build () { @@ -53,20 +54,21 @@ remove_unshipped_files () for ARCH in i386 x86-64; do IMAGE_DIR=${DIST_DIR}-${ARCH} - OUT_ROOT=${BUILD_OUT}-${ARCH} + OUT_ROOT=${NATIVE_OUT}-${ARCH} notify "Building binaries for arch ${ARCH}" - unpack_dist + unpack_dist_file_to "${DIST_DIR}" "${DIST_DIR}" run_command "${OUT_ROOT}"-compile "${DIST_DIR}"/src build "${ARCH}" notify "Making image for arch ${ARCH}" new_temp_dir "${IMAGE_DIR}" run_command "${OUT_ROOT}"-image "${DIST_DIR}"/src make_image "${IMAGE_DIR}" remove_unshipped_files "${IMAGE_DIR}" "${ARCH}" - unpack_doc_image_into "${IMAGE_DIR}"/lib/mit-scheme-"${ARCH}" + unpack_into_existing_dir "${DOC_IMAGE_DIR}" \ + "${IMAGE_DIR}"/lib/mit-scheme-"${ARCH}" fixup_perms "${IMAGE_DIR}" make_tar_file "${OUT_ROOT}" "${IMAGE_DIR}" cleanup_temp_files done -notify "Success!" +notify_finished diff --git a/dist/make-src-files b/dist/make-src-files index 00b2333c3..afc06adc0 100755 --- a/dist/make-src-files +++ b/dist/make-src-files @@ -25,6 +25,7 @@ . "$(dirname "${0}")"/shared.sh reset_output_dir +standard_args notify "Creating the changelog" my_rm_f "${CHANGELOG}" @@ -33,10 +34,11 @@ make_read_only "${CHANGELOG}" notify "Creating the distribution directory" new_temp_dir "${DIST_DIR}" -my_mkdir "${DIST_DIR}"/etc -for FILE in src doc "${CHANGELOG}" dist/Makefile; do +my_cp "${CHANGELOG}" "${DIST_DIR}"/. +for FILE in src doc dist/Makefile; do my_cp "${SOURCE_TREE}"/"${FILE}" "${DIST_DIR}"/. done +my_mkdir "${DIST_DIR}"/etc my_cp "${SOURCE_TREE}"/etc/xscheme.el "${DIST_DIR}"/etc/. # Clean up dot files from source tree @@ -57,12 +59,12 @@ run_command "${SRC_OUT}"-config "${DIST_DIR}"/src ./Setup.sh run_command "${DOC_OUT}"-config "${DIST_DIR}"/doc reconf # Clean up after autoconf -my_find "${DIST_DIR}" -type d -name autom4te.cache -exec rm -rf '{}' \; +find "${DIST_DIR}" -type d -name autom4te.cache | xargs rm -rf fixup_perms "${DIST_DIR}" notify "Creating archive files" make_tar_file "${SRC_OUT}" "${DIST_DIR}" -make_tar_file "${SRC_OUT}"-ucode "${DIST_UCODE}" \ - "${DIST_DIR}"/src/COPYING "${DIST_DIR}"/src/microcode +make_tar_file "${SRC_OUT}"-ucode "${UCODE_BASE}" \ + "${DIST_DIR}"/src/COPYING "${DIST_DIR}"/src/etc "${DIST_DIR}"/src/microcode -notify "Success!" +notify_finished diff --git a/dist/make-system-file b/dist/make-system-file new file mode 100755 index 000000000..1e735f44f --- /dev/null +++ b/dist/make-system-file @@ -0,0 +1,82 @@ +#!/bin/bash +# +# Copyright (C) 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994, +# 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, +# 2005, 2006, 2007, 2008, 2009, 2010 Massachusetts Institute of +# Technology +# +# 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. + +# inputs: ucode tar, scheme binary tars +# outputs: system-specific tar + +system_args () +{ + (( ${#} >= 3 )) || usage + DIST_TYPE=${1} + ARCH=${2} + SYSTEM=${3} +} +ARGS_FUNCTION=system_args + +system_usage () +{ + echo "usage: ${PROGRAM} TYPE ARCH SYSTEM [OPTIONS]" + usage_arg_type + echo " ARCH must be 'i386' or 'x86-64'" + echo " SYSTEM is the operating system identifier" + echo " OPTIONS are passed to the configure script" +} +USAGE_FUNCTION=system_usage + +. "$(dirname "${0}")"/shared.sh +make_output_dir + +shift 3 + +OUT=${SYSTEM_OUT}-${ARCH}-${SYSTEM} +ARCH_BASE=${DIST_DIR}-${ARCH} +SYSTEM_BASE=${ARCH_BASE}-${SYSTEM} +UCODE_DIR=${DIST_DIR}/src/microcode +IMAGE_DIR=temp_image_dir +LIB_DIR=lib/mit-scheme-"${ARCH}" + +compile () +{ + my_configure --enable-native-code="${ARCH}" "${@}" + my_make +} + +make_image () +{ + make install DESTDIR="${TL_DIR}"/"${IMAGE_DIR}" +} + +notify "Compiling executable" +unpack_dist_file_to "${UCODE_BASE}" "${DIST_DIR}" +run_command "${OUT}"-compile "${UCODE_DIR}" compile "${@}" + +notify "Making image directory" +new_temp_dir "${IMAGE_DIR}" +run_command "${OUT}"-image "${UCODE_DIR}" make_image +unpack_dist_file_to "${ARCH_BASE}" "${SYSTEM_BASE}" +my_mv "${IMAGE_DIR}"/usr/local/bin "${SYSTEM_BASE}"/. +my_mv "${IMAGE_DIR}"/usr/local/"${LIB_DIR}"/lib "${SYSTEM_BASE}"/"${LIB_DIR}"/. + +notify "Making archive file" +make_tar_file "${OUT}" "${SYSTEM_BASE}" + +notify_finished diff --git a/dist/shared.sh b/dist/shared.sh index 17938d7ed..158b76b1b 100644 --- a/dist/shared.sh +++ b/dist/shared.sh @@ -19,9 +19,13 @@ # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA # 02110-1301, USA. -set -e +set -ae umask 022 +# Capture standard out so we can send messages there even when it's +# redirected. +exec 3>&1 + TL_DIR=$(pwd) PROGRAM=${0} PROJECT_NAME=mit-scheme @@ -29,17 +33,32 @@ SOURCE_TREE=${PROJECT_NAME} usage () { - echo "usage: ${PROGRAM} TYPE" >&2 - echo " TYPE must be 'snapshot' to specify today's date" >&2 - echo " or 'standard' to specify standard release" >&2 + ${USAGE_FUNCTION:-standard_usage} >&2 exit 1 } -(( ${#} <= 1 )) || usage -DIST_TYPE=${1:-standard} +standard_usage () +{ + echo "usage: ${PROGRAM} TYPE" + usage_arg_type +} + +usage_arg_type () +{ + echo " TYPE must be 'snapshot' to specify today's date" + echo " or 'standard' to specify standard release" +} + +standard_args () +{ + (( ${#} <= 1 )) || usage + DIST_TYPE=${1:-standard} +} [[ -d ${SOURCE_TREE} ]] || usage +${ARGS_FUNCTION:-standard_args} "${@}" + get_release () { fgrep Release "${SOURCE_TREE}"/src/runtime/version.scm \ @@ -52,15 +71,13 @@ get_release () } case ${DIST_TYPE} in - (snapshot) - RELEASE=$(date +%Y%m%d) - + snapshot) + RELEASE=$(date +%Y%m%d) ;; - (standard) - RELEASE=$(get_release) - + standard) + RELEASE=$(get_release) ;; - (*) + *) usage ;; esac @@ -69,21 +86,36 @@ CHANGELOG=changelog.txt TAR_SUFFIX=.tar.gz DIST_DIR=${PROJECT_NAME}-${RELEASE} +UCODE_BASE=${DIST_DIR}-ucode DOC_IMAGE_DIR=${DIST_DIR}-doc-image -DIST_UCODE=${DIST_DIR}-ucode - OUTPUT_DIR=${TL_DIR}/.out SRC_OUT=${OUTPUT_DIR}/src DOC_OUT=${OUTPUT_DIR}/doc LIARC_OUT=${OUTPUT_DIR}/liarc -BUILD_OUT=${OUTPUT_DIR}/build +NATIVE_OUT=${OUTPUT_DIR}/native +SYSTEM_OUT=${OUTPUT_DIR}/system + +notify () +{ + echo "${@}" >&3 +} + +notify_finished () +{ + notify "Success!" +} -CMD_TRACE= cmd () { - [[ -n ${CMD_TRACE} ]] && echo ">>>>" "${@}" - "${@}" + if [[ -z ${CMD_TRACE} ]]; then + "${@}" + else + notify ">>>>" "${@}" + if [[ ${CMD_TRACE} != norun ]]; then + "${@}" + fi + fi } reset_output_dir () @@ -176,17 +208,20 @@ make_read_only () cmd chmod 444 "${@}" } -notify () +run_command () { - echo "${@}" + local OUT_FILE=${1} + shift + run_command_helper "${@}" &> "${OUT_FILE}" } -run_command () +run_command_helper () { - local OUT_FILE=${1} - local DIR=${2} - shift 2 - (cd "${DIR}"; cmd "${@}") > "${OUT_FILE}" 2>&1 + local DIR=${1} + shift + pushd "${DIR}" &> /dev/null + cmd "${@}" + popd &> /dev/null } make_tar_file () @@ -199,23 +234,22 @@ make_tar_file () set "${DIR}" fi my_rm_f "${TAR_FILE}" - my_tar "${DIR}" "${@}" > "${OUT_FILE}" 2>&1 + my_tar "${DIR}" "${@}" &> "${OUT_FILE}" make_read_only "${TAR_FILE}" } -unpack_dist_to () +unpack_dist_file_to () { - local DEST=${1} - guarantee_tar "${DIST_DIR}" + local SOURCE=${1} + local DEST=${2} + guarantee_tar "${SOURCE}" new_temp_dir "${DEST}" - unpack_into "${DIST_DIR}" "${DEST}" + unpack_into_existing_dir "${SOURCE}" "${DEST}" } -unpack_dist () +unpack_into_existing_dir () { - guarantee_tar "${DIST_DIR}" - new_temp_file "${DIST_DIR}" - my_untar "${DIST_DIR}" + my_untar "${1}" -C "${2}" --strip-components 1 } guarantee_tar () @@ -231,16 +265,6 @@ guarantee_file () fi } -unpack_doc_image_into () -{ - unpack_into "${DOC_IMAGE_DIR}" "${1}" -} - -unpack_into () -{ - my_untar "${1}" -C "${2}" --strip-components 1 -} - # Keep track of temp files and clean them up. new_temp_file () @@ -257,9 +281,11 @@ new_temp_dir () cleanup_temp_files () { - cd "${TL_DIR}" - my_rm_rf "${TEMP_FILES[@]}" - TEMP_FILES=() + if [[ -z ${PRESERVE_TEMP_FILES} ]]; then + cd "${TL_DIR}" + my_rm_rf "${TEMP_FILES[@]}" + TEMP_FILES=() + fi } TEMP_FILES=() -- 2.25.1