configure.ac 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335
  1. AC_INIT([tpm2-tools],
  2. [m4_esyscmd_s([git describe --tags --always --dirty])])
  3. AC_CONFIG_MACRO_DIR([m4])
  4. AX_IS_RELEASE([dash-version])
  5. AX_CHECK_ENABLE_DEBUG([info])
  6. AC_PROG_CC
  7. AC_PROG_LN_S
  8. LT_INIT
  9. AM_INIT_AUTOMAKE([foreign
  10. subdir-objects])
  11. # enable "silent-rules" option by default
  12. m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])])
  13. AX_CODE_COVERAGE
  14. m4_ifdef([_AX_CODE_COVERAGE_RULES],
  15. [AM_CONDITIONAL(AUTOCONF_CODE_COVERAGE_2019_01_06, [true])],
  16. [AM_CONDITIONAL(AUTOCONF_CODE_COVERAGE_2019_01_06, [false])])
  17. AX_ADD_AM_MACRO_STATIC([])
  18. AC_CONFIG_FILES([Makefile])
  19. # enable autoheader config.h file
  20. AC_CONFIG_HEADERS([lib/config.h])
  21. AC_CHECK_PROG([PANDOC],[pandoc],[yes])
  22. AS_IF(
  23. [test "x${PANDOC}" = x"yes"],
  24. [],
  25. [AC_MSG_WARN([Required executable pandoc not found, man pages will not be built])])
  26. AM_CONDITIONAL([HAVE_PANDOC],[test "x${PANDOC}" = "xyes"])
  27. AM_CONDITIONAL(
  28. [HAVE_MAN_PAGES],
  29. [test -d "${srcdir}/man/man1" -o "x${PANDOC}" = "xyes"])
  30. AC_ARG_ENABLE([fapi],
  31. [AS_HELP_STRING([--disable-fapi], [disable FAPI tools (default: auto)])],,
  32. [enable_fapi=check])
  33. AS_IF([test "$enable_fapi" = yes -o "$enable_fapi" = check],
  34. [PKG_CHECK_MODULES([TSS2_FAPI], [tss2-fapi], [enable_fapi=yes], [
  35. AS_IF([test "$enable_fapi" = yes], [AC_MSG_ERROR([Required module tss2-fapi not found])])
  36. enable_fapi=no
  37. ])
  38. PKG_CHECK_MODULES([TSS2_FAPI_3_0], [tss2-fapi >= 3.0],
  39. [AC_DEFINE([FAPI_3_0], [1], [fapi3.0.0])],
  40. [true])
  41. ])
  42. AM_CONDITIONAL([HAVE_FAPI], [test "$enable_fapi" = yes])
  43. PKG_CHECK_MODULES([TSS2_ESYS_3_0], [tss2-esys >= 3.0.0],
  44. [AC_DEFINE([ESYS_3_0], [1], [Esys3.0])]
  45. [AC_SUBST([TSS2_ESYS_CFLAGS], [$TSS2_ESYS_3_0_CFLAGS])
  46. AC_SUBST([TSS2_ESYS_LIBS], [$TSS2_ESYS_3_0_LIBS])],
  47. [PKG_CHECK_MODULES([TSS2_ESYS_2_3], [tss2-esys >= 2.4.0],
  48. [AC_DEFINE([ESYS_2_3], [1], [Esys2.3])]
  49. [AC_SUBST([TSS2_ESYS_CFLAGS], [$TSS2_ESYS_2_3_CFLAGS])
  50. AC_SUBST([TSS2_ESYS_LIBS], [$TSS2_ESYS_2_3_LIBS])])])
  51. PKG_CHECK_MODULES([TSS2_TCTILDR], [tss2-tctildr])
  52. PKG_CHECK_MODULES([TSS2_MU], [tss2-mu])
  53. PKG_CHECK_MODULES([TSS2_RC], [tss2-rc])
  54. PKG_CHECK_MODULES([TSS2_SYS], [tss2-sys])
  55. PKG_CHECK_MODULES([CRYPTO], [libcrypto >= 1.0.2g])
  56. PKG_CHECK_MODULES([CURL], [libcurl])
  57. PKG_CHECK_MODULES([UUID], [uuid])
  58. # pretty print of devicepath if efivar library is present
  59. PKG_CHECK_MODULES([EFIVAR], [efivar],,[true])
  60. AC_CHECK_HEADERS([efivar/efivar.h])
  61. # backwards compat with older pkg-config
  62. # - pull in AC_DEFUN from pkg.m4
  63. m4_ifndef([PKG_CHECK_VAR], [
  64. # PKG_CHECK_VAR(VARIABLE, MODULE, CONFIG-VARIABLE,
  65. # [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND])
  66. # -------------------------------------------
  67. # Retrieves the value of the pkg-config variable for the given module.
  68. AC_DEFUN([PKG_CHECK_VAR],
  69. [AC_REQUIRE([PKG_PROG_PKG_CONFIG])dnl
  70. AC_ARG_VAR([$1], [value of $3 for $2, overriding pkg-config])dnl
  71. _PKG_CONFIG([$1], [variable="][$3]["], [$2])
  72. AS_VAR_COPY([$1], [pkg_cv_][$1])
  73. AS_VAR_IF([$1], [""], [$5], [$4])dnl
  74. ])# PKG_CHECK_VAR
  75. ])
  76. AC_ARG_WITH([bashcompdir],
  77. AS_HELP_STRING([--with-bashcompdir=DIR], [directory for bash completions]), ,
  78. [PKG_CHECK_VAR([with_bashcompdir], [bash-completion], [completionsdir], ,
  79. [with_bashcompdir="${datarootdir}/bash-completion/completions"])])
  80. AC_SUBST(bashcompdir, [$with_bashcompdir])
  81. AC_ARG_WITH([tpmsim],
  82. AS_HELP_STRING([--with-tpmsim=BIN], [simulator used for testing]),
  83. [],
  84. [])
  85. AC_SUBST(tpmsim, [$with_tpmsim])
  86. AC_CANONICAL_HOST
  87. # Check OS and set library and compile flags accordingly
  88. case "${host_os}" in
  89. *nto-qnx*)
  90. EXTRA_CFLAGS="$EXTRA_CFLAGS -D_QNX_SOURCE"
  91. LIBDL_LDFLAGS=""
  92. ;;
  93. *)
  94. LIBDL_LDFLAGS="-ldl"
  95. ;;
  96. esac
  97. AC_SUBST([LIBDL_LDFLAGS])
  98. AC_ARG_ENABLE([unit],
  99. [AS_HELP_STRING([--enable-unit],
  100. [build cmocka unit tests])],,
  101. [enable_unit=no])
  102. AM_CONDITIONAL([UNIT], [test "x$enable_unit" != xno])
  103. AC_ARG_ENABLE([persistent],
  104. [AS_HELP_STRING([--disable-persistent],
  105. [disable tests that require resetting the TPM])],,)
  106. AM_CONDITIONAL([PERSISTENT], [test "x$enable_persistent" != xno])
  107. dnl macro that checks for specific modules in python
  108. AC_DEFUN([AC_PYTHON_MODULE],
  109. [AC_MSG_CHECKING([for module $1 in $PYTHON])
  110. echo "import $1" | $PYTHON - 2>/dev/null
  111. if test $? -ne 0 ; then
  112. AC_MSG_ERROR([not found])
  113. else
  114. AC_MSG_RESULT(found)
  115. fi
  116. ])
  117. # Check OS and set library and compile flags accordingly
  118. case "${host_os}" in
  119. *bsd* | *BSD*)
  120. HOSTOS='BSD'
  121. ;;
  122. *)
  123. #Assume linux
  124. HOSTOS='Linux'
  125. ;;
  126. esac
  127. AS_IF([test "x$enable_unit" != xno], [
  128. PKG_CHECK_MODULES([CMOCKA],[cmocka])
  129. AC_CHECK_PROG([tpm2_abrmd], [tpm2-abrmd], yes, no)
  130. AS_IF([test $tpm2_abrmd = yes],
  131. [TPM2_ABRMD=tpm2-abrmd],
  132. [AC_MSG_ERROR([Required executable tpm2_abrmd not found, try setting PATH])]
  133. )
  134. AC_SUBST([TPM2_ABRMD])
  135. AS_IF([test -z "$tpmsim"], [
  136. AC_CHECK_PROG([swtpm], [swtpm], yes, no)
  137. AC_CHECK_PROG([tpm_server], [tpm_server], yes, no)
  138. AS_IF([test $swtpm = yes], [TPM2_SIM=swtpm],
  139. [AS_IF([test $tpm_server = yes], [TPM2_SIM=tpm_server],
  140. [AC_MSG_ERROR([Required executables swtpm or tpm_server not found, try setting PATH])])])
  141. ],
  142. [
  143. AC_CHECK_PROG([HAS_TPM2_SIM], [$tpmsim], yes, no)
  144. AS_IF([test "$HAS_TPM2_SIM" = yes],
  145. [TPM2_SIM=$tpmsim],
  146. [AC_MSG_ERROR([Required executable $tpmsim not found, system tests require a tpm simulator shell!])]
  147. )
  148. ]
  149. )
  150. AC_SUBST([TPM2_SIM])
  151. AC_CHECK_PROG([BASH_SHELL], [bash], yes, no)
  152. AS_IF([test $BASH_SHELL = no],
  153. [AC_MSG_ERROR([Required executable bash not found, system tests require a bash shell!])])
  154. AM_PATH_PYTHON([2.7],
  155. [],
  156. [AC_MSG_ERROR([Required executable python not found, some system tests will fail!])]
  157. )
  158. AC_PYTHON_MODULE([yaml])
  159. AC_CHECK_PROG([XXD], [xxd], yes, no)
  160. AS_IF([test $XXD = no],
  161. [AC_MSG_ERROR([Required executable xxd not found, some system tests will fail!])])
  162. AS_IF([test "$HOSTOS" = "Linux"],
  163. [AC_CHECK_PROG([SS], [ss], [yes], [no])],
  164. [AC_CHECK_PROG([SS], [sockstat], [yes], [no])])
  165. AS_IF([test $SS = no],
  166. [AC_MSG_ERROR([Required executable ss/sockstat not found, some system tests will fail!])])
  167. AC_CHECK_PROG([SHASUM], [shasum], yes, no)
  168. AS_IF([test $SHASUM = no],
  169. [AC_MSG_ERROR([Required executable shasum not found, some system tests will fail!])])
  170. AC_CHECK_PROG([MKTEMP], [mktemp], yes, no)
  171. AS_IF([test $MKTEMP = no],
  172. [AC_MSG_ERROR([Required executable mktemp not found, some system tests will fail!])])
  173. AC_CHECK_PROG([EXPECT], [expect], yes, no)
  174. AS_IF([test $EXPECT = no],
  175. [AC_MSG_ERROR([Required executable expect not found, some system tests will fail!])])
  176. AC_CHECK_PROG([OPENSSL], [openssl], yes, no)
  177. AS_IF([test $OPENSSL = no],
  178. [AC_MSG_ERROR([Required executable openssl not found, some system tests will fail!])])
  179. unit_test_tool_report="- tpm2_abrmd: $tpm2_abrmd
  180. - TPM simulator: $TPM2_SIM
  181. - bash: $BASH_SHELL
  182. - python: $PYTHON
  183. - xxd: $XXD
  184. - ss: $SS
  185. - shasum: $SHASUM
  186. - mktemp: $MKTEMP
  187. - expect: $EXPECT
  188. - openssl: $OPENSSL"
  189. ])
  190. AC_ARG_ENABLE([dlclose],
  191. [AS_HELP_STRING([--disable-dlclose],
  192. [Some versions of libc cause a sigsegv on exit, this disables the dlclose and works around that bug])],
  193. [AC_DEFINE([DISABLE_DLCLOSE], [1],
  194. [Some versions of libc cause a sigsegv on exit with dlclose(), this disables the dlclose()
  195. and works around that bug])]
  196. )
  197. AC_ARG_ENABLE([hardening],
  198. [AS_HELP_STRING([--disable-hardening],
  199. [Disable compiler and linker options to frustrate memory corruption exploits])],,
  200. [enable_hardening="yes"])
  201. # Good information on adding flags, and dealing with compilers can be found here:
  202. # https://github.com/zcash/zcash/issues/1832
  203. # https://github.com/kmcallister/autoharden/
  204. AS_IF([test x"$enable_hardening" != x"no"], [
  205. AC_DEFUN([add_hardened_c_flag], [
  206. AX_CHECK_COMPILE_FLAG([$1],
  207. [EXTRA_CFLAGS="$EXTRA_CFLAGS $1"],
  208. [AC_MSG_ERROR([Cannot enable $1, consider configuring with --disable-hardening])]
  209. )
  210. ])
  211. AC_DEFUN([add_hardened_ld_flag], [
  212. AX_CHECK_LINK_FLAG([$1],
  213. [EXTRA_LDFLAGS="$EXTRA_LDFLAGS $1"],
  214. [AC_MSG_ERROR([Cannot enable $1, consider configuring with --disable-hardening])]
  215. )
  216. ])
  217. AC_DEFUN([add_hardened_define_flag], [
  218. AX_CHECK_PREPROC_FLAG([$1],
  219. [EXTRA_CFLAGS="$EXTRA_CFLAGS $1"],
  220. [AC_MSG_ERROR([Cannot enable $1, consider configuring with --disable-hardening])]
  221. )
  222. ])
  223. add_hardened_c_flag([-Wall])
  224. add_hardened_c_flag([-Wextra])
  225. AS_IF([test "x$ax_is_release" = "xno"], [add_hardened_c_flag([-Werror])])
  226. add_hardened_c_flag([-Wformat])
  227. add_hardened_c_flag([-Wformat-security])
  228. add_hardened_c_flag([-Wstack-protector])
  229. add_hardened_c_flag([-fstack-protector-all])
  230. add_hardened_c_flag([-Wstrict-overflow=5])
  231. add_hardened_c_flag([-O2])
  232. AX_ADD_FORTIFY_SOURCE
  233. add_hardened_c_flag([-fPIC])
  234. add_hardened_ld_flag([[-shared]])
  235. add_hardened_c_flag([-fPIE])
  236. add_hardened_ld_flag([[-pie]])
  237. add_hardened_ld_flag([[-Wl,-z,relro]])
  238. add_hardened_ld_flag([[-Wl,-z,now]])
  239. ], [
  240. AC_MSG_WARN([Compiling with --disable-hardening is dangerous!
  241. you should consider fixing the configure script compiler flags
  242. and submitting patches upstream!])
  243. ])
  244. AC_DEFUN([add_c_flag], [
  245. AX_CHECK_COMPILE_FLAG([$1],
  246. [EXTRA_CFLAGS="$EXTRA_CFLAGS $1"],
  247. $2
  248. )
  249. ])
  250. # -D_GNU_SOURCE is required for execvpe() in options.c
  251. add_c_flag([-D_GNU_SOURCE], [AC_MSG_ERROR([Cannot enable -D_GNU_SOURCE])])
  252. # Enable gnu99 mode, since we use some of these features.
  253. add_c_flag([-std=gnu99], [AC_MSG_ERROR([Cannot enable -std=gnu99])])
  254. # Best attempt compiler options that are on newer versions of GCC that
  255. # we can't widely enforce without killing other peoples builds.
  256. # Works with gcc only. Needs to be disabled on BSD and clang
  257. AS_IF([test "$HOSTOS" = "Linux"],
  258. [add_c_flag([-Wstringop-overflow=4])
  259. add_c_flag([-Wstringop-truncation])
  260. add_c_flag([-Wduplicated-branches])
  261. add_c_flag([-Wduplicated-cond])
  262. add_c_flag([-Wbool-compare])],[])
  263. # Best attempt, strip unused stuff from the binary to reduce size.
  264. # Rather than nesting these and making them ugly just use a counter.
  265. AX_CHECK_COMPILE_FLAG([-fdata-sections], [strip="${strip}y"])
  266. AX_CHECK_COMPILE_FLAG([-ffunction-sections], [strip="${strip}y"])
  267. AX_CHECK_LINK_FLAG([[-Wl,--gc-sections]], [strip="${strip}y"])
  268. AS_IF([test x"$strip" = x"yyy"], [
  269. EXTRA_CFLAGS="$EXTRA_CFLAGS -fdata-sections -ffunction-sections"
  270. EXTRA_LDFLAGS="$EXTRA_LDFLAGS -Wl,--gc-sections"
  271. ],
  272. AC_MSG_NOTICE([Not using compiler options to reduce binary size!])
  273. )
  274. AC_SUBST([EXTRA_CFLAGS])
  275. AC_SUBST([EXTRA_LDFLAGS])
  276. AC_SUBST([PATH])
  277. AC_OUTPUT
  278. AC_MSG_RESULT([
  279. - $PACKAGE_NAME: $VERSION
  280. - Man pages: ${PANDOC:-no}
  281. - Unit tests: $enable_unit
  282. $unit_test_tool_report
  283. ])