您的答案是執行此操作的首選方式。 autoconf手冊介紹瞭如何在「make install」時間覆蓋各種變量(例如,這對打包非常有用)。在這樣做時,它說(參見「安裝目錄變量):
A corollary is that you should not use these variables except in
makefiles. For instance, instead of trying to evaluate `datadir' in
`configure' and hard-coding it in makefiles using e.g.,
`AC_DEFINE_UNQUOTED([DATADIR], ["$datadir"], [Data directory.])', you
should add `-DDATADIR='$(datadir)'' to your makefile's definition of
`CPPFLAGS' (`AM_CPPFLAGS' if you are also using Automake).
自動工具,和一般的構建系統,是一個令人費解的業務和還沒有人想出做的事情是漂亮和整潔的方式一般情況下,這意味着我們必須閱讀這樣的部分並完全解決這個問題,無論如何,你的直覺是正確的!
謝謝!按照「通常」的方式是否有任何好處?我都是爲了保持標準,但它似乎更加混亂。 – Malvineous 2011-05-04 00:44:33
的好處是你可以在配置時通過'./configure CPPFLAGS = -DDATA_PATH =/path/to/alternate/data'覆蓋CPPFLAGS;使用config.h來執行它需要'./configure --prefix =/alternate/prefix',這樣可以減少對各個目錄位置的控制。 – ptomato 2011-05-04 08:51:10