在makefile中使用sed用变量

问题描述 投票:0回答:1

我进行了广泛的搜索并找到了许多类似的问题,但据我所知,没有找到真正做我想要的东西的问题。

在这里是最接近的问题:

在makefile中使用sed;如何逃避变量?

我想在makefile内部做的非常简化的版本是

sed s~foo~${BAR}~
where

$BAR

是我的makefile中的一个变量。显然,我想用当前发生的文本
foo
replace replace replace replace replace replace
$BAR 由于被要求,这是完整版本:
请注意,目标是让makefile成为posix。

Makefile(仅相关部分):
${BAR}

Scripts/build/diff-all.sh

... diff: scripts/build/diff-all.sh ...

diff-branches

#!/bin/bash -e

for DIFFBRANCH in $(cat diff-branches); do
    scripts/build/diff.sh $DIFFBRANCH
done

Scripts/build/diff.sh

2016_reorg_diff
# more branches here

命令:

#/bin/bash -e DIFFBRANCH=$1 BRANCH=$(git rev-parse --abbrev-ref HEAD) CHAPTERDIR=src/chapters SHORTCHAPTERDIR=${CHAPTERDIR##src/} # remove src/ from the start of CHAPTERDIR CHAPTERS=$(ls $CHAPTERDIR | grep "^\\d\\d_.*\\.tex$") LATEXARGS="-file-line-error -halt-on-error" if [[ ! $DIFFBRANCH ]]; then echo "usage: $0 DIFFBRANCH" exit 1 fi mkdir -p tmp mkdir -p pdf for CHAPTER in $CHAPTERS; do # make tex diff files for each chapter SLUG=$(echo $CHAPTER | cut -f 1 -d '.') latexdiff-vc --git --so --flatten --force -r $DIFFBRANCH -r $BRANCH $CHAPTERDIR/$CHAPTER mkdir -p tmp/$CHAPTERDIR mv -v $CHAPTERDIR/$SLUG-diff$DIFFBRANCH-$BRANCH.tex tmp/src_diff_$DIFFBRANCH/$SHORTCHAPTERDIR/$SLUG-$BRANCH-diff-$DIFFBRANCH.tex done rsync -avz --exclude $SHORTCHAPTERDIR src/ tmp/src_diff_$DIFFBRANCH/ # copy all source files to tmp except chapters (because they're already there) sed -i.bak -E 's~^([[:blank:]]*\subimport{chapters/}{[[:alnum:]_]+)}~\1-$BRANCH-diff-$DIFFBRANCH}~' tmp/src_diff_$DIFFBRANCH/iuf-rulebook.tex # this replaces \subimport{chapters/}{01_general} with \subimport{chapters/}{01_general-$BRANCH-diff-$DIFFBRANCH} with the variables expanded # so that the iuf-rulebook.tex uses the diffed chapters # the -i.bak is required so SED works on OSX and Linux rm -f tmp/src_diff_$DIFFBRANCH/*.bak # because of this, we have to delete the .bak files after mkdir -p tmp/out_diff_$DIFFBRANCH TEXINPUTS=tmp/src_diff_$DIFFBRANCH: latexmk -pdf $LATEXARGS -quiet -output-directory=./tmp/out_diff_$DIFFBRANCH tmp/src_diff_$DIFFBRANCH/iuf-rulebook.tex mv tmp/out_diff_$DIFFBRANCH/iuf-rulebook.pdf pdf/iuf-rulebook-$BRANCH-diff-$DIFFBRANCH.pdf rm -rf tmp/*_$DIFFBRANCH

验证:
bash variables sed makefile
1个回答
0
投票

最新问题
© www.soinside.com 2019 - 2025. All rights reserved.