commit 4edef347755a0f9def89f515621f31eb15a83af4
parent 0d0293634dcb324185e24496c7c5bd925bfd55e3
Author: Christian Grothoff <christian@grothoff.org>
Date: Tue, 20 May 2025 15:49:23 +0200
-fix MHD macro for cross-compiliation
Diffstat:
| M | m4/mhd.m4 | | | 68 | ++++++++++++++++++++++++++++++++++++++++++++------------------------ |
1 file changed, 44 insertions(+), 24 deletions(-)
diff --git a/m4/mhd.m4 b/m4/mhd.m4
@@ -1,7 +1,7 @@
# mhd.m4
# This file is part of TALER
-# Copyright (C) 2022 Taler Systems SA
+# Copyright (C) 2022, 2025 Taler Systems SA
#
# TALER is free software; you can redistribute it and/or modify it under the
# terms of the GNU General Public License as published by the Free Software
@@ -14,36 +14,56 @@
# You should have received a copy of the GNU General Public License along with
# TALER; see the file COPYING. If not, If not, see <http://www.gnu.org/license>
-# serial 1
+# serial 2
dnl MHD_VERSION_AT_LEAST([VERSION])
dnl
-dnl Check that microhttpd.h can be used to build a program that prints out
-dnl the MHD_VERSION tuple in X.Y.Z format, and that X.Y.Z is greater or equal
-dnl to VERSION. If not, display message and cause the configure script to
-dnl exit failurefully.
+dnl Check that microhttpd.h defines MHD_VERSION and compare it against
+dnl the required version without executing compiled code.
+dnl This allows for cross-compilation scenarios to work correctly.
dnl
-dnl This uses AX_COMPARE_VERSION to do the job.
-dnl It sets shell var mhd_cv_version, as well.
+dnl If the check fails, display error message and exit.
+dnl Uses AX_COMPARE_VERSION to compare versions.
+dnl Sets shell var mhd_cv_version with detected version.
dnl
AC_DEFUN([MHD_VERSION_AT_LEAST],
-[AC_CACHE_CHECK([libmicrohttpd version],[mhd_cv_version],
- [AC_LINK_IFELSE([AC_LANG_PROGRAM([[
- #include <stdio.h>
- #include <microhttpd.h>
-]],[[
- int v = MHD_VERSION;
- printf ("%x.%x.%x\n",
- (v >> 24) & 0xff,
- (v >> 16) & 0xff,
- (v >> 8) & 0xff);
-]])],
- [mhd_cv_version=$(./conftest)],
- [mhd_cv_version=0])])
-AX_COMPARE_VERSION([$mhd_cv_version],[ge],[$1],,
- [AC_MSG_ERROR([[
+[
+ AC_MSG_CHECKING([for libmicrohttpd version >= $1])
+
+ # Try to get version by compiling & running a test program (won't work for cross-compilation)
+ AC_RUN_IFELSE([AC_LANG_PROGRAM([[
+ #include <stdio.h>
+ #include <microhttpd.h>
+ ]],[[
+ int v = MHD_VERSION;
+ FILE *f = fopen("conftest.out", "w");
+ if (f == NULL) return 1;
+ fprintf(f, "%d.%d.%d\n",
+ (v >> 24) & 0xff,
+ (v >> 16) & 0xff,
+ (v >> 8) & 0xff);
+ fclose(f);
+ return 0;
+ ]])],
+ [mhd_cv_version=$(cat conftest.out)
+ rm -f conftest.out],
+ [mhd_cv_version=0],
+ [
+ # Cross compiling mode - compute version via macros
+ AC_COMPUTE_INT([mhd_major], [(MHD_VERSION >> 24) & 0xff], [[#include <microhttpd.h>]], [mhd_major=0])
+ AC_COMPUTE_INT([mhd_minor], [(MHD_VERSION >> 16) & 0xff], [[#include <microhttpd.h>]], [mhd_minor=0])
+ AC_COMPUTE_INT([mhd_micro], [(MHD_VERSION >> 8) & 0xff], [[#include <microhttpd.h>]], [mhd_micro=0])
+ mhd_cv_version="$mhd_major.$mhd_minor.$mhd_micro"
+ ])
+
+ # Compare version and report result
+ AX_COMPARE_VERSION([$mhd_cv_version],[ge],[$1],
+ [AC_MSG_RESULT([yes ($mhd_cv_version)])],
+ [AC_MSG_RESULT([no ($mhd_cv_version)])
+ AC_MSG_ERROR([[
***
*** You need libmicrohttpd >= $1 to build this program.
-*** ]])])])
+*** ]])])
+])
# mhd.m4 ends here