tools:Autotool參數傳遞

 

1.判斷某個文件是否存在,若不存在,想辦法告知對應的源碼[configure.ac;Makefile.am;source.c]

a.configure.ac傳遞給Makefile.am

diff --git a/configure.ac b/configure.ac
index aaaaa..bbbbb 100644
--- a/configure.ac
+++ b/configure.ac
@@ -40,6 +40,7 @@ AC_ARG_ENABLE([xxx],
         enable_xxx=no)
 
 AM_CONDITIONAL([ENABLE_www], [test "x${enable_www}" = "xyes"])
+AM_CONDITIONAL([HAVE_FILE_PRIV], [test -e $(WORKSPACE)/dir1/dir2/source.h])

b.Makefile.am 定義宏傳遞給源碼

diff --git a/Makefile.am b/Makefile.am
index cfbd2d4..75926c3 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -5,8 +5,10 @@  source_code
+if HAVE_FILE_PRIV
+lib_xxx_la_CFLAGS += -D HAVE_FILE_PRIV
+endif

c.source.c

diff --git a/source.c b/source.c
index 04667ff..c22b0d2 100644
--- a/source.c
+++ b/source.c
@@ -27,7 +27,10 @@
 #include <inc.h>
+
+#ifdef HAVE_FILE_PRIV
 #include <priv.h>
+#endif

2.判斷文件是否存在與編譯目錄

https://www.gnu.org/software/autoconf/manual/autoconf-2.61/html_node/Generic-Headers.html

diff --git a/configure.ac b/configure.ac
index aaaaa..bbbbb 100644
--- a/configure.ac
+++ b/configure.ac
@@ -40,6 +40,7 @@ AC_ARG_ENABLE([xxx],
         enable_xxx=no)
 
 AM_CONDITIONAL([ENABLE_www], [test "x${enable_www}" = "xyes"])
+AC_CHECK_HEADS(source.h)

如果在config過程中找到source.h,則會在對應config.h中增加一行定義

#define HAVE_SOURCE_H 1

切記須在本地源碼inclde config.h 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章