2011-07-28 14 views
0

Makefile変数で使用するためにシェルコマンドからテストを抽出するのに助けが必要です。Makefile help(とシェルコマンド)

基本的に、私は異なるサーバー上のソフトウェアの2つの異なるバージョンを使用していますが、共通のメイクファイルを使用しています。 1つは6.4.2バージョンのgnatmake、もう1つは6.2.2バージョンです。問題は、6.2.2バージョンが"--unchecked-shared-lib-imports"フラグをサポートしていないことです。これは、6.4.2バージョンに対してコンパイルするときに含める必要があります。

バージョンを確認するには、'gnatmake --version'コマンドを使用できます。これは下のそれぞれが返すものです。どのようにしてバージョンを解析できますか? (6.2.2または6.4.2)?

gnatmake 6.2.2:

GNATMAKE Pro 6.2.2 (20090612-43) 
Copyright (C) 1995-2009, Free Software Foundation, Inc. 
This is free software; see the source for copying conditions. 
See your AdaCore support agreement for details of warranty and support. 
If you do not have a current support agreement, then there is absolutely 
no warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR 
PURPOSE. 

gnatmake 6.4.2:

GNATMAKE Pro 6.4.2 (20110614-45) 
Copyright (C) 1995-2010, Free Software Foundation, Inc. 
This is free software; see the source for copying conditions. 
See your AdaCore support agreement for details of warranty and support. 
If you do not have a current support agreement, then there is absolutely 
no warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR 
PURPOSE. 

ここでは、私はメイクアップセットされるだろう考えていた方法ですので、GNATMAKE_VERSION場合6.4.2です。--unchecked-shared-lib-importsは、将来のパラメータに含めることができる変数GNAT_FLAGになります()。

GNATMAKE_VERSION:=$(shell gnatmake --version) 

GNAT_FLAG:= 
# if not equal (GNATMAKE_VERSION=6.2.2) 
#  GNAT_FLAG:= "--unchecked-shared-lib-imports" 
# 

test: 
    echo "$(GNATMAKE_VERSION)" 

test2: 
    echo "$(GNAT_FLAG)" 

これを行う簡単な方法はありますか?

+0

これはかなり簡単な方法です。それは動作しますか? – Beta

+0

私はこのコマンドからバージョンを解析する方法を知らない:$(shell gnatmake --version)それで後で使うことができる – systemoutprintln

答えて

1

(申し訳ありませんが、私が最初に問題を理解していない。)

はあなたがsed持っている場合は、これを試してみてください:

:あなたは headcutを持っている場合は、これを

GNATMAKE_VERSION:=$(shell gnatmake --version | sed -e '/GNATMAKE/!d' -e 's/GNATMAKE Pro \([^ ]*\) .*/\1/') 

をか

GNATMAKE_VERSION:=$(shell gnatmake --version | head -n 1 | cut -f3 -d' ') 

またはこれをGnatmakeが許可する場合:

GNATMAKE_VERSION:=$(shell gnatmake --version) 
GNATMAKE_VERSION:=$(word 3,$(GNATMAKE_VERSION))