From 5c80ce91aac89962edd5f752cee3ef3a03f826fe Mon Sep 17 00:00:00 2001 From: Tadashi Koike Date: Sun, 28 Mar 2010 23:18:06 +0900 Subject: [PATCH] preserving assembler file is possible. add GAST_SAVE_ASM variable. --- README | 21 +++++++++++++------ README.ja_JP.UTF-8 | 60 +++++++++++++++++++++++++++++++++++++++--------------- gast | 46 ++++++++++++++++++++++++++++++++++++++--- 3 files changed, 102 insertions(+), 25 deletions(-) diff --git a/README b/README index 5d75af5..0853832 100644 --- a/README +++ b/README @@ -1,6 +1,6 @@ GAST: Gcc Automatically Save Temps - Copyright (C) 2009 Tadashi Koike (T.K) - ** Please overlook my weak English. ** + Copyright (C) 2009-2010 Tadashi Koike (T.K) + ** Please overlook my weak English. ** Table of contents ============ 1. Purpose of this project @@ -155,7 +155,7 @@ Table of contents $ vi gast.aliases 3) Execute 'gast_symlink' script. this script creates - symbolic link file foe each wrapper script. + symbolic link file for each wrapper script. Symbolic link filename are selected from 'gast.aliases'. $ ./gast_symlink @@ -212,11 +212,12 @@ Table of contents additiona option '--save-temps-dir' are available to specifiy preserving temporary files. (in above example, /home/foo/tmp) - If you need, you define GAST_CONTENT_WITHOUT_H, GAST_CONTENT_UNIQUE - environment variables. + If you need, you define GAST_CONTENT_WITHOUT_H, GAST_CONTENT_UNIQUE, + and GAST_SAVE_ASM environment variables. +------------------------------------------------------------------ |$ export GAST_CONTENT_WITHOUT_H= |$ export GAST_CONTENT_UNIQUE= + |$ export GAST_SAVE_ASM= +------------------------------------------------------------------ see "6. Environment variables to control 'gast'". @@ -248,6 +249,7 @@ Table of contents | $ export GAST_SAVE_DIR=/home/foo/tmp | $ export GAST_CONTENT_WITHOUT_H= | $ export GAST_CONTENT_UNIQUE= + | $ export GAST_SAVE_ASM= | $ | $ # do build | $ PATH=/home/foo/gast-0.1.2:${PATH} make @@ -266,6 +268,7 @@ Table of contents +------------------------------------------------------------------ |$ unset GAST_ENABLE GAST_SOURCE_DIR GAST_SAVE_DIR |$ unset GAST_CONTENT_WITHOUT_H GAST_CONTENT_UNIQUE + |$ unset GAST_SAVE_ASM +------------------------------------------------------------------ ======================================================================= @@ -276,7 +279,8 @@ Table of contents Below is an another example: +------------------------------------------------------------------ |$ GAST_ENABLE= GAST_SOURCE_DIR=/tmp GAST_SAVE_DIR=/home/foo/tmp \ - |> GAST_CONTENT_WITHOUT_H= PATH=/home/foo/gast-0.1.2:$PATH \ + |> GAST_CONTENT_WITHOUT_H= GAST_SAVE_ASM= \ + |> PATH=/home/foo/gast-0.1.2:$PATH \ |> gcc test.c +------------------------------------------------------------------ ... confusing. @@ -351,6 +355,11 @@ Table of contents current temporary file is same as one of the preserved files, gast does not preserve current temporary file. + GAST_SAVE_ASM + When this environment variable is defined (however excludes its + value is "no"), generated assembler file (.s file) is also + preserved. + 7. Use case 1) Assistance for researching source code (to understand macro diff --git a/README.ja_JP.UTF-8 b/README.ja_JP.UTF-8 index 557312b..1f2367a 100644 --- a/README.ja_JP.UTF-8 +++ b/README.ja_JP.UTF-8 @@ -1,4 +1,4 @@ - Copyright (C) 2009 Tadashi Koike (T.K) + Copyright (C) 2009-2010 Tadashi Koike (T.K) 目次 ============ 1. このプロジェクトの目的 @@ -150,23 +150,45 @@ gast-0.1.2/README.ja_JP.UTF-8 【セットアップ】 - スクリプトが配置されているディレクトリに移動し、各スクリプトを - 単独で(オプション引数なしで)実行してください。 各スクリプトは - 自身の別名となるシンボリックリンクを同一ディレクトリ内に作成しま - す。 + 1) スクリプトが配置されているディレクトリに移動してください。 $ cd /home/foo/gast-0.1.2 - $ ./gast - gast : Create symbolic link 'gcc' - gast : Create symbolic link 'cc' - gast : Create symbolic link 'g++' - $ ./gast_make - gast_make : Create symbolic link 'make' - gast_make : Create symbolic link 'gmake' + 2) 必要に応じて gast.alias ファイルを編集し、、ご利用のコンパイラ + や make ユーティリティなどの名前を、ラッパースクリプトの別名呼 + び出し名として追加してください。(通常は、デフォルトの状態でも + 充分機能すると思います。) - $ ./gast_rpmbuild - gast_rpmbuild : Create symbolic link 'rpmbuild' + $ vi gast.aliases + + 3) gast_symlink スクリプトを実行してください。このスクリプトは、 + スクリプト配置ディレクトリ内に、gast.aliases ファイルに定義 + された別名でシンボリックリンクを作成します。 + + $ ./gast_symlink + + 後から新しいシンボリックリンクを追加したい場合、gast.alias + ファイルを編集して、再度 gast_symlink を実行してください。 + + $ ./gast_symlink + + もし、シンボリックリンクを作成する対象スクリプトを限定する + 場合は、コマンド引数として対象スクリプト名を指定してください。 + + 例) + $ ./gast_symlink gast + + 4) シンボリックリンクを一括削除するには、gast_symlink スクリプト + を '-u' オプション付きで実行してください。 + + $ ./gast_symlink -u + + もし、削除するシンボリックリンクを限定する場合、シンボリック + リンクが張られている対象スクリプト名を、コマンド引数として + 指定してください。 + + 例) + $ ./gast_symlink -u gast_make 【注意】 ・ここで提供されるスクリプト群は、互いが同一ディレクトリに配置 @@ -203,6 +225,7 @@ 環境変数を定義して下さい。 $ export GAST_CONTENT_WITHOUT_H= $ export GAST_CONTENT_UNIQUE= + $ export GAST_SAVE_ASM=  【注意!!】   Linux カーネルのような巨大なパッケージをビルドする場合は、環境変数 @@ -254,6 +277,7 @@ $ export GAST_SAVE_DIR=/home/foo/tmp $ export GAST_CONTENT_WITHOUT_H= $ export GAST_CONTENT_UNIQUE= + $ export GAST_SAVE_ASM= $ $ # ビルド $ PATH=/home/foo/gast-0.1.2:${PATH} make @@ -283,7 +307,8 @@ また、以下のような実施方法もあります(コマンド列が長くて面倒ですが)。 $ GAST_ENABLE= GAST_SOURCE_DIR=/tmp GAST_SAVE_DIR=/home/foo/tmp \ - > GAST_CONTENT_WITHOUT_H= PATH=/home/foo/gast-0.1.2:$PATH \ + > GAST_CONTENT_WITHOUT_H= GAST_SAVE_ASM= \ + > PATH=/home/foo/gast-0.1.2:$PATH \ > gcc test.c いろいろ使ってみてください。 @@ -349,7 +374,10 @@ 破棄され、同一の内容が重複して退避されないようになります。 ※その代わり、コンパイルオプションの記録は完全には辿れなくなります。 - + + GAST_SAVE_ASM + この環境変数が存在する場合(かつ値が "no" でない場合)、gast は + さらに生成されたアセンブラファイル(.s ファイル)も退避します。 7. 役立つ場面(想定) diff --git a/gast b/gast index f8cc1bf..ec2b0b5 100755 --- a/gast +++ b/gast @@ -71,6 +71,12 @@ # value is "no"), If compile options are different but content of # temporary file is same as one of some previous stored files, # this script does preserve current temporary file. +# +# - GAST_SAVE_ASM +# When this environment variable is defined (however excludes its +# value is "no"), generated assembler file (.s file) is also +# preserved. +# VERSION="0.1.2" ORIGINAL_NAME="gast" @@ -129,6 +135,7 @@ usage : ${ORIGINAL_NAME} [-v|--version] [-h|--help] GAST_SOURCE_DIR= : top directory of source tree. GAST_CONTENT_WITHOUT_H : slim temporary files when this variable is defined. + GAST_SAVE_ASM : assembler file is also stored. EOL exit 0 ;; @@ -167,6 +174,8 @@ fi # Check whether source file(s) is/are specified. # And create new commandline arguments. asm_notdelete_flg= +output_file= +next_is_output_file= pipe_flg= idx=0 idx_src=0 @@ -185,11 +194,18 @@ do ext_list[$idx_src]=".ii" let idx_src+=1 ;; + '-o') next_is_output_file="YES" + ;; '-S') asm_notdelete_flg="YES" ;; '-pipe') pipe_flg="YES" new_args[$idx]="-save-temps" ;; + *) if [ -n "${next_is_output_file}" ]; then + output_file="${arg}" + next_is_output_file= + fi + ;; esac let idx+=1 done @@ -355,7 +371,11 @@ do dirname="${fullname%/*}" # directory name of source file (full-path) name_body="${basename%.*}" target="${name_body}${temp_ext}" # Compiler's temporary filename - asmfile="${name_body}.s" # Compiler's temporary filename (.s file) + if [ -n "${asm_notdelete_flg}" -a -n "${output_file}" ]; then + asmfile="${output_file}" # user specify assembler filename + else + asmfile="${name_body}.s" # temporary assembler filename (.s file) + fi src_relative_dir= # directory name of source file (relative-path from GAST_SOURCE_DIR) case "${fullname}" in @@ -373,8 +393,13 @@ do ;; esac [ "${src_relative_dir:0:1}" = '/' ] && src_relative_dir="${src_relative_dir#/}" - # Delete assembler temporary file (except that compiler is executed with -S option) - [ -e "${asmfile}" -a -z "${asm_notdelete_flg}" ] && rm -f "${asmfile}" > /dev/null 2>&1 + # Delete assembler temporary file (except that GAST_SAVE_ASM is specified + # or compiler is executed with -S option) + if [ -e "${asmfile}" ]; then + if [ -z "${asm_notdelete_flg}" -a "${GAST_SAVE_ASM=no}" = "no" ]; then + rm -f "${asmfile}" > /dev/null 2>&1 + fi + fi if [ -e "${target}" ]; then if [ "${target}" = "conftest.i" ]; then @@ -549,6 +574,21 @@ do if [ -z "${skip_moving}" ]; then mv -f "${target}" "${dest_file}" 2>/dev/null [ $? -ne 0 ] && echo "${ORIGINAL_NAME}(${SCRIPT_NAME}): Couldn't move ${target} to ${dest_file} ." >&2 + # move/copy assembler file + # Cullently, If destination assembler file already exists, + # I give up to move/copy assembler file. + dest_asm_file="${dest_file%${temp_ext}}.s" + if [ "${GAST_SAVE_ASM=no}" != "no" -a -e "${asmfile}" -a ! -e "${dest_asm_file}" ]; then + preserve_action= + if [ -z "${asm_notdelete_flg}" ]; then + preserve_action="move" + mv -f "${asmfile}" "${dest_asm_file}" 2>/dev/null + else + preserve_action="copy" + cp -p "${asmfile}" "${dest_asm_file}" 2>/dev/null + fi + [ $? -ne 0 ] && echo "${ORIGINAL_NAME}(${SCRIPT_NAME}): Couldn't ${preserve_action} ${asmfile} to ${dest_asm_file} ." >&2 + fi fi # Delete original temporary file. -- 2.11.0