rules
他のセクションで使用するためにdebian makeファイルに関数とグローバル変数を定義できますかoverride_****
?
これは成功しませんでした。
たとえば、以下は私のスクリプトファイルの1つから抜粋したものです。また、Debianルールファイルのカバレッジセクション全体でこの関数とグローバル変数を使用したいと思います。
# console output colors
NC='\033[0m' # No Color
RED='\033[1;31m'
BLUE='\033[1;34m'
GREEN='\033[1;32m'
YELLOW='\033[1;33m'
#return code
rc=999
######################### Functions #############################
function logCommandExecution()
{
commandName=$1
exitCode=$2
#echo 'command name: '${commandName}' exitCode: '${exitCode}
if [ ${exitCode} -eq 0 ]
then
printf "${GREEN}${commandName}' completed successfully${NC}\n"
else
printf "${RED}${commandName} failed with error code [${exitCode}]${NC}\n"
exit ${exitCode}
fi
}
ベストアンサー1
これdebian/rules
はshファイルではなくmakeファイルです。
私はそれを試してみるためにmakefileにあなたの関数を入れました:
#!/usr/bin/make -f
# console output colors
NC='\033[0m' # No Color
RED='\033[1;31m'
GREEN='\033[1;32m'
######################### Functions #############################
function logCommandExecution()
{
commandName=$1
exitCode=$2
#echo 'command name: '${commandName}' exitCode: '${exitCode}
if [ ${exitCode} -eq 0 ]
then
printf "${GREEN}${commandName}' completed successfully${NC}\n"
else
printf "${RED}${commandName} failed with error code [${exitCode}]${NC}\n"
exit ${exitCode}
fi
}
all:
logCommandExecution Passcmd 0
logCommandExecution Failcmd 1
その後、これを実行しようとすると、次のような結果が得られます。
$ make all
makefile:14: *** missing separator. Stop.
だから答えは簡単ではありません。しかし、makefileでシェル構文を実行する方法があります。
この回答役に立つかもしれません。
最も簡単な方法は、関数を別のファイルに入れて次から呼び出すことですdebian/rules
。
ファイル生成:
#!/usr/bin/make -f
all:
./logCommandExecution Passcmd 0
./logCommandExecution Failcmd 1
ログコマンドの実行:
#!/bin/sh
# console output colors
NC='\033[0m' # No Color
RED='\033[1;31m'
GREEN='\033[1;32m'
commandName=$1
exitCode=$2
#echo 'command name: '${commandName}' exitCode: '${exitCode}
if [ ${exitCode} -eq 0 ]
then
printf "${GREEN}${commandName}' completed successfully${NC}\n"
else
printf "${RED}${commandName} failed with error code [${exitCode}]${NC}\n"
exit ${exitCode}
fi
これで成功すると、次のようになります。
$ make
./logCommandExecution Passcmd 0
Passcmd' completed successfully
./logCommandExecution Failcmd 1
Failcmd failed with error code [1]
make: *** [makefile:5: all] Error 1