Skip to content

Commit

Permalink
make: include source filenames in installed files
Browse files Browse the repository at this point in the history
  • Loading branch information
akinomyoga committed Apr 2, 2023
1 parent 79a6bd4 commit 610fab3
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 5 deletions.
8 changes: 7 additions & 1 deletion GNUmakefile
Expand Up @@ -178,12 +178,18 @@ else
INSDIR_DOC = $(DATA_HOME)/doc/blesh
endif

ifneq ($(strip_comment),)
opt_strip_comment := --strip-comment=$(strip_comment)
else
opt_strip_comment :=
endif

install: \
$(outfiles:$(OUTDIR)/%=$(INSDIR)/%) \
$(outfiles-doc:$(OUTDIR)/doc/%=$(INSDIR_DOC)/%) \
$(INSDIR)/cache.d $(INSDIR)/run
$(INSDIR)/%: $(OUTDIR)/%
bash make_command.sh install "$<" "$@"
bash make_command.sh install $(opt_strip_comment) "$<" "$@"
$(INSDIR_DOC)/%: $(OUTDIR)/doc/%
bash make_command.sh install "$<" "$@"
$(INSDIR)/cache.d $(INSDIR)/run:
Expand Down
4 changes: 3 additions & 1 deletion README-ja_JP.md
Expand Up @@ -50,7 +50,7 @@ make -C ble.sh install PREFIX=~/.local
echo 'source ~/.local/share/blesh/ble.sh' >> ~/.bashrc
```

生成過程では、複数のBashスクリプトファイルを結合することで `ble.sh` を生成し、
生成過程では、複数のBashスクリプトファイルを前処理・結合することで `ble.sh` を生成し、
他の関連ファイルを正しく配置し、またソースコード中のコードコメントを削除してロードを最適化します。

※生成過程は、C/C++ のコンパイルも伴わずバイナリも生成しませんので、コンパイラを準備していただく必要はありません。
Expand Down Expand Up @@ -279,6 +279,8 @@ Make 変数 `DESTDIR` または `PREFIX` が指定されている時、`ble.sh`
更にそれ以外で環境変数 `$XDG_DATA_HOME` が指定されている時、`$XDG_DATA_HOME/blesh` にインストールされます。
以上の変数が何れも指定されていない時の既定のインストール先は `~/.local/share/blesh` です。

インストール時にコード中のコメントは自動で削除されますが、コメントを保持したい場合は `strip_comment=no``make` の引数に指定して下さい。

`.bashrc` の設定に関しては[節1.3](#set-up-bashrc)を御覧ください。

## 1.2 GitHub Releases から tar をダウンロードして使う<sup><a id="get-from-tarball" href="#get-from-tarball">†</a></sup>
Expand Down
7 changes: 5 additions & 2 deletions README.md
Expand Up @@ -52,13 +52,13 @@ make -C ble.sh install PREFIX=~/.local
echo 'source ~/.local/share/blesh/ble.sh' >> ~/.bashrc
```

The build process integrates multiple Bash script files into a single Bash script `ble.sh`,
The build process integrates multiple Bash script files into a single Bash script `ble.sh` with pre-processing,
place other module files in appropriate places, and strip code comments for shorter initialization time.

Note: This does not involve any C/C++/Fortran compilations and generating binaries, so C/C++/Fortran compilers are not needed.
Some people seem to bilindly believe that one always need to use `make` with C/C++/Fortran compilers to generate binaries.
They complain about `ble.sh`'s make process, but it comes from the lack of knowledge on the general principle of `make`.
C/C++ programs in the repository is used to update the Unicode character table from the Unicode database when a new Unicode standard appears.
You may find C/C++ programs in the repository, but they are used to update the Unicode character table from the Unicode database when a new Unicode standard appears.
The generated table is included in the repository:
[`canvas.GraphemeClusterBreak.sh`](https://github.com/akinomyoga/ble.sh/blob/master/src/canvas.GraphemeClusterBreak.sh),
[`canvas.c2w.musl.sh`](https://github.com/akinomyoga/ble.sh/blob/master/src/canvas.c2w.musl.sh),
Expand Down Expand Up @@ -293,6 +293,9 @@ Otherwise, if the make variables `INSDIR` is specified, it will be installed dir
Otherwise, if the environment variable `$XDG_DATA_HOME` is defined, the install location will be `$XDG_DATA_HOME/blesh`.
If none of these variables are specified, the default install location is `~/.local/share/blesh`.

The comment lines and blank lines in the script files are stripped in the installation process.
If you would like to keep these lines in the script files, please specify the argument `strip_comment=no` to `make`.

To set up `.bashrc` see [Sec. 1.3](#set-up-bashrc).

## 1.2 Or, use a tar ball of `ble.sh` obtained from GitHub releases<sup><a id="get-from-tarball" href="#get-from-tarball">†</a></sup>
Expand Down
1 change: 1 addition & 0 deletions docs/ChangeLog.md
Expand Up @@ -583,6 +583,7 @@
- global: normalize bracket expressions to `_a-zA-Z` / `_a-zA-Z0-9` `#D2006` 41faa494
- global: fix leak variables `#D2018` 6f5604de
- edit: handle nested WINCH properly `#D2020` a6b2c078
- make: include the source filenames in the installed files (suggested by bkerin) `#D2027` xxxxxxxx

## Contrib

Expand Down
37 changes: 36 additions & 1 deletion make_command.sh
Expand Up @@ -46,10 +46,13 @@ function sub:help {
function sub:install {
# read options
local flag_error= flag_release=
local opt_strip_comment=
while [[ $1 == -* ]]; do
local arg=$1; shift
case $arg in
(--release) flag_release=1 ;;
(--strip-comment=*)
opt_strip_comment=${arg#*=} ;;
(*) echo "install: unknown option $arg" >&2
flag_error=1 ;;
esac
Expand All @@ -61,11 +64,43 @@ function sub:install {
mkd "${dst%/*}"
if [[ $src == *.sh ]]; then
local nl=$'\n' q=\'

# header comment
local script='1i\
# this script is a part of blesh (https://github.com/akinomyoga/ble.sh) under BSD-3-Clause license
# Copyright 2015 Koichi Murase <myoga.murase@gmail.com>. All rights reserved.\
# This script is a part of blesh (https://github.com/akinomyoga/ble.sh)\
# provided under the BSD-3-Clause license. Do not edit this file because this\
# is not the original source code: Various pre-processing has been applied.\
# Also, the code comments and blank lines are stripped off in the installation\
# process. Please find the corresponding source file(s) in the repository\
# "akinomyoga/ble.sh".'
if [[ $src == out/ble.sh ]]; then
script=$script'\
#\
# Source: /ble.pp'
local file
for file in $(git ls-files src); do
[[ $file == *.sh ]] || continue
script=$script"\\
# Source: /$file"
done
else
script=$script'\
#\
# Source: /'"${src#out/}"
fi

# strip comments
if [[ $opt_strip_comment != no ]]; then
script=$script'
/<<[[:space:]]*EOF/,/^[[:space:]]*EOF/{p;d;}
/^[[:space:]]*#/d
/^[[:space:]]*$/d'
else
script=$script'\
#------------------------------------------------------------------------------'
fi

[[ $flag_release ]] &&
script=$script$nl's/^\([[:space:]]*_ble_base_repository=\)'$q'.*'$q'\([[:space:]]*\)$/\1'${q}release:$dist_git_branch$q'/'
sed "$script" "$src" >| "$dst.part" && mv "$dst.part" "$dst"
Expand Down
12 changes: 12 additions & 0 deletions note.txt
Expand Up @@ -6726,6 +6726,18 @@ bash_tips

2023-04-02

* make: インストール時に元のコメントなどの情報への pointer をつける (suggested by bkerin) [#D2027]
https://github.com/akinomyoga/ble.sh/discussions/309#discussioncomment-5498921

make_command.sh install からでは元のソースがどれかは原理的には分からないが、
取り敢えず現状では ble.sh 以外は全て対応するファイルが同名で存在しているの
で、その仮定の下でファイル名を含める事にした。ble.sh についても ble.pp と
src/*.sh を全て含める事にした。

果たしてコメントを削除しないインストールが本当に必要なのかは謎だが一応機能
としてはつけておく事にした。何れにしても元々ある日本語のコメントは個人用の
物であって他の人に見せる為のものではない。

* bgproc: bash-3 で idle.cancel がないと表示される [#D2026]

実装を改めて確認してみたらそもそも bash-3 に対する考慮が全く入っていない。
Expand Down

0 comments on commit 610fab3

Please sign in to comment.