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
$ 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
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'".
| $ 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
+------------------------------------------------------------------
|$ unset GAST_ENABLE GAST_SOURCE_DIR GAST_SAVE_DIR
|$ unset GAST_CONTENT_WITHOUT_H GAST_CONTENT_UNIQUE
+ |$ unset GAST_SAVE_ASM
+------------------------------------------------------------------
=======================================================================
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.
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
- Copyright (C) 2009 Tadashi Koike (T.K)
+ Copyright (C) 2009-2010 Tadashi Koike (T.K)
目次
============
1. このプロジェクトの目的
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
【注意】
・ここで提供されるスクリプト群は、互いが同一ディレクトリに配置
環境変数を定義して下さい。
$ export GAST_CONTENT_WITHOUT_H=
$ export GAST_CONTENT_UNIQUE=
+ $ export GAST_SAVE_ASM=
【注意!!】
Linux カーネルのような巨大なパッケージをビルドする場合は、環境変数
$ 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
また、以下のような実施方法もあります(コマンド列が長くて面倒ですが)。
$ 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
いろいろ使ってみてください。
破棄され、同一の内容が重複して退避されないようになります。
※その代わり、コンパイルオプションの記録は完全には辿れなくなります。
-
+
+ GAST_SAVE_ASM
+ この環境変数が存在する場合(かつ値が "no" でない場合)、gast は
+ さらに生成されたアセンブラファイル(.s ファイル)も退避します。
7. 役立つ場面(想定)
# 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"
GAST_SOURCE_DIR=<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
;;
# 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
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
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
;;
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
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.