2 # gast_rpmbuild : wrapper script for rpmbuild command to set environment using gast
4 # Copyright (C) 2009 Tadashi Koike
6 # This program is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 2 of the License, or
9 # (at your option) any later version.
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program; if not, write to the Free Software
18 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21 #----------------------------------------------------------------------
22 # (I am weak in English. Please modify English comment more suitable. :T.K)
25 ORIGINAL_NAME="gast_rpmbuild"
30 # When this script is executed as 'gast_rpmbuild', this script creates symbolic link
31 # file name as 'rpmbuild' and exit.
32 if [ "${SCRIPT_NAME}" = "${ORIGINAL_NAME}" ]; then
37 echo "${ORIGINAL_NAME} ${VERSION}"
42 usage : ${ORIGINAL_NAME} [-v|--version] [-h|--help]
44 -h, --help display this help and exit
45 -v, --version display version information and exit
47 When this script is executed as '${ORIGINAL_NAME}' with no option, this script
48 creates symbolic link toward itself which name is 'rpmbuild'.
50 When this script is executed as 'rpmbuild', this script behaves just as
51 rpmbuild command with accepting additional '--save-temps-dir' option and
52 with setting GAST_* environment variables.
57 echo "usage : ${ORIGINAL_NAME} [--version|-v] [--help|-h]"
66 if [ -e "${cmd}" ]; then
67 file "${cmd}" 2>/dev/null | egrep 'symbolic link' >/dev/null 2>&1
68 if [ "$?" -ne 0 ]; then
69 echo "${ORIGINAL_NAME} : '${cmd}' exists as normal file or directory. Could not create symbolic link." >&2
73 ln -sf "${ORIGINAL_NAME}" "${cmd}"
74 if [ "$?" -eq 0 ]; then
75 echo "${ORIGINAL_NAME} : Create symbolic link ${cmd}" >&2
77 echo "${ORIGINAL_NAME} : Couldn't create symbolic link ${cmd}" >&2
83 # get a full-path name of original rpmbuild/rpm2cpio command.
84 RPMBUILD_BIN=`which rpmbuild 2>/dev/null`
85 if [ -z "${RPMBUILD_BIN}" ]; then
86 echo "${ORIGINAL_NAME} : Couldn't find a path to rpmbuild command. exit" >&2
90 # get a directory path (full-path) of directory this script
91 case "${SCRIPT_PATH}" in
92 '.') SCRIPT_PATH="${CWD}" ;;
93 \./*) SCRIPT_PATH="${CWD}/${SCRIPT_PATH#*/}" ;;
94 '~') SCRIPT_PATH="${HOME}" ;;
95 \~/*) SCRIPT_PATH="${HOME}/${SCRIPT_PATH#*/}" ;;
97 *) SCRIPT_PATH="${CWD}/${SCRIPT_PATH}" ;;
100 # Set this script's directory to PATH environment variable.
101 # (to be found a gcc wrapper script (=gast) in advance of original compiler binary).
102 PATH="${SCRIPT_PATH}:${PATH}"
105 # Set environment variable to get compiler's temporalry file
108 # Analyse command options. Get directory name to move temporary file.
111 # new_args_a : argument list for rpmbuild {-bb|-bc}
112 # new_args_b : argument list for rpmbuild {--recompile|--rebuild}
113 # srpm_list : list of srpm file(s)
116 if [ "${arg}" = "--save-temps-dir" ]; then
117 next_is_savedir="yes"
118 elif [ -n "${next_is_savedir}" ]; then
121 \-*) GAST_SAVE_DIR=""
122 echo "${ORIGINAL_NAME} : Error in --save-temps-dir option. ignore this option." >&2
123 new_args[$idx]="${arg}"
126 '') GAST_SAVE_DIR="" ;;
127 '.') GAST_SAVE_DIR="${CWD}" ;;
128 \./*) GAST_SAVE_DIR="${CWD}/${arg#*/}" ;;
129 '~') GAST_SAVE_DIR="${HOME}" ;;
130 \~/*) GAST_SAVE_DIR="${HOME}/${arg#*/}" ;;
131 \/*) GAST_SAVE_DIR="${arg}" ;;
132 *) GAST_SAVE_DIR="${CWD}/${arg}" ;;
135 if [ -n "${GAST_SAVE_DIR}" ]; then
136 GAST_SAVE_DIR="${GAST_SAVE_DIR%/}"
142 new_args[$idx]="${arg}"
146 exec "${RPMBUILD_BIN}" "${new_args[@]}"