1# 2# Copyright 2021 Northern.tech AS 3# 4# This file is part of CFEngine 3 - written and maintained by Northern.tech AS. 5# 6# This program is free software; you can redistribute it and/or modify it 7# under the terms of the GNU General Public License as published by the 8# Free Software Foundation; version 3. 9# 10# This program is distributed in the hope that it will be useful, 11# but WITHOUT ANY WARRANTY; without even the implied warranty of 12# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13# GNU General Public License for more details. 14# 15# You should have received a copy of the GNU General Public License 16# along with this program; if not, write to the Free Software 17# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA 18# 19# To the extent this program is licensed as part of the Enterprise 20# versions of CFEngine, the applicable Commercial Open Source License 21# (COSL) may apply to this file if you as a licensee so wish it. See 22# included file COSL.txt. 23# 24# CF3_WITH_LIBRARY(library-name, checks) 25# -------------------------------------- 26# 27# This function popluates CFLAGS, CPPFLAGS and LDFLAGS from the 28# --with-$library=PATH and runs a second argument with those options. 29# 30# After execution flags are returned to previous state, but available in 31# ${LIBRARY}_{CFLAGS,LDFLAGS}. Path is available in ${LIBRARY}_PATH. 32# 33# Libraries added to LIBS are available as ${LIBRARY}_LIBS afterwards. 34# 35AC_DEFUN([CF3_WITH_LIBRARY], 36[ 37 m4_define([ULN],m4_toupper($1)) 38 39 # 40 # Populate ${LIBRARY}_{PATH,CFLAGS,LDFLAGS} according to arguments 41 # 42 if test "x$with_[$1]" != xyes && 43 test "x$with_[$1]" != xcheck && 44 test "x$with_[$1]" != x 45 then 46 test -z "$ULN[]_PATH" && ULN[]_PATH="$with_[$1]" 47 if test "x$with_[$1]" != x/usr && 48 test "x$with_[$1]" != x/ 49 then 50 test -z "$ULN[]_CFLAGS" && ULN[]_CFLAGS="" 51 test -z "$ULN[]_CPPFLAGS" && ULN[]_CPPFLAGS="-I$with_[$1]/include" 52 test -z "$ULN[]_LDFLAGS" && ULN[]_LDFLAGS="-L$with_[$1]/lib" 53 fi 54 else 55 ULN[]_PATH="default path" 56 fi 57 58 # 59 # Save old environment 60 # 61 save_CFLAGS="$CFLAGS" 62 save_CPPFLAGS="$CPPFLAGS" 63 save_LDFLAGS="$LDFLAGS" 64 save_LIBS="$LIBS" 65 66 CFLAGS="$CFLAGS $ULN[]_CFLAGS" 67 CPPFLAGS="$CPPFLAGS $ULN[]_CPPFLAGS" 68 LDFLAGS="$LDFLAGS $ULN[]_LDFLAGS" 69 70 # 71 # Run checks passed as argument 72 # 73 $2 74 75 # 76 # Pick up any libraries added by tests 77 # 78 test -z "$ULN[]_LIBS" && ULN[]_LIBS="$LIBS" 79 80 # 81 # libtool understands -R$path, but we are not using libtool in configure 82 # snippets, so -R$path goes to $pkg_LDFLAGS only after autoconf tests 83 # 84 if test "x$with_[$1]" != xyes && 85 test "x$with_[$1]" != xcheck && 86 test "x$with_[$1]" != x/usr && 87 test "x$with_[$1]" != x/ 88 then 89 ULN[]_LDFLAGS="$ULN[]_LDFLAGS -R$with_[$1]/lib" 90 fi 91 92 # 93 # Restore pristine environment 94 # 95 CFLAGS="$save_CFLAGS" 96 CPPFLAGS="$save_CPPFLAGS" 97 LDFLAGS="$save_LDFLAGS" 98 LIBS="$save_LIBS" 99 100 AC_SUBST(ULN[]_PATH) 101 AC_SUBST(ULN[]_CPPFLAGS) 102 AC_SUBST(ULN[]_CFLAGS) 103 AC_SUBST(ULN[]_LDFLAGS) 104 AC_SUBST(ULN[]_LIBS) 105]) 106