source: trunk/m4/yat_plplot.m4

Last change on this file was 3867, checked in by Peter, 16 months ago

allow user to override values from pkg-config

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id Date
File size: 5.6 KB
Line 
1## $Id: yat_plplot.m4 3867 2020-02-20 03:43:31Z peter $
2#
3# serial 2
4#
5# see http://www.gnu.org/software/automake/manual/automake.html#Serials
6#
7# SYNOPSIS
8#
9#   YAT_CHECK_PLPLOT([ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND])
10#
11# DESCRIPTION
12#
13#   If pkg-config is available infer variables PLPLOT_CPPFLAGS,
14#   PLPLOT_CXXFLAGS_PLPLOT, PLPLOT_LDFLAGS and PLPLOT_LIBS from
15#   pkg-config. Otherwise try linking against plplot-c++ and
16#   plplotd-c++ to set PLPLOT_LIBS to what the library is called on
17#   this system. If PLPLOT_* variable above are already set, the
18#   values from pkg-config is ignored.
19#
20# COPYLEFT
21#
22#   Copyright (C) 2020 Peter Johansson
23#
24#   This file is part of the yat library, http://dev.thep.lu.se/yat
25#
26#   The yat library is free software; you can redistribute it and/or
27#   modify it under the terms of the GNU General Public License as
28#   published by the Free Software Foundation; either version 3 of the
29#   License, or (at your option) any later version.
30#
31#   The yat library is distributed in the hope that it will be useful,
32#   but WITHOUT ANY WARRANTY; without even the implied warranty of
33#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
34#   General Public License for more details.
35#
36#   You should have received a copy of the GNU General Public License
37#   along with yat. If not, see <http://www.gnu.org/licenses/>.
38#
39
40## This macro is a modified version of the the code found in the
41## 'configure.ac' of svndigest, http://dev.thep.lu.se/svndigest, which
42## was written by Jari Häkkinen and Peter Johansson
43##
44## Copyright (C) 2009, 2015 Jari Häkkinen
45## Copyright (C) 2010, 2011, 2012 Peter Johansson
46
47AC_DEFUN([YAT_CHECK_PLPLOT],
48[
49  YAT_CHECK_PKG_CONFIG_PLPLOT
50
51  YAT_CHECK_PLPLOT_HEADER(
52    [YAT_CHECK_PLPLOT_LIB([$1],[$2])],
53    [$2]
54  )
55
56  AC_SUBST([PLPLOT_CPPFLAGS])
57  AC_SUBST([PLPLOT_CXXFLAGS])
58  AC_SUBST([PLPLOT_LDFLAGS])
59  AC_SUBST([PLPLOT_LIBS])
60])
61
62
63# set variable yat_plplot_pkg to no, plplot-c++ or plplotd-c++
64AC_DEFUN([YAT_CHECK_PKG_CONFIG_PLPLOT],
65[
66  PKG_PROG_PKG_CONFIG([0.23])
67
68  yat_plplot_pkg=no
69  AS_VAR_SET_IF([PKG_CONFIG], [
70    m4_foreach_w([yat_PKG], [plplot-c++ plplotd-c++], [
71      AS_VAR_IF([yat_plplot_pkg], [no], [
72        AC_MSG_CHECKING([for yat_PKG.pc])
73        PKG_CHECK_EXISTS([yat_PKG], [
74          AC_MSG_RESULT([yes])
75          AS_VAR_SET([yat_plplot_pkg], [yat_PKG])
76        ],[
77          AC_MSG_RESULT([no])
78        ])
79      ])
80    ])
81  ], [
82    AC_MSG_WARN([
83      pkg-config could not be found or is too old. You may want to
84      install it and make sure it is in your PATH or set the
85      PKG_CONFIG environment variable to the full path to pkg-config])
86  ])
87
88
89  AC_ARG_VAR([PLPLOT_CPPFLAGS],
90             [preprocessor flags for plplot, overriding pkg-config])
91  AC_ARG_VAR([PLPLOT_CXXFLAGS],
92             [compiler flags for plplot, overriding pkg-config])
93  AC_ARG_VAR([PLPLOT_LDFLAGS],
94             [linker flags for plplot, overriding pkg-config])
95  AC_ARG_VAR([PLPLOT_LIBS], [libraries for plplot, overriding pkg-config])
96
97  AS_VAR_IF([yat_plplot_pkg], [no], [], [
98    # pkg-config typically returns <prefix>/include/plplot because plplot
99    # people assumes users include header files as <foo.h>. We prefer
100    # including files as <plplot/foo.h> and therefore need to trim off
101    # trailing '/plplot'. Space is included in sed expression to avoid
102    # substituting potential '/plplot' in PREFIX.
103
104    # only set flags if not already set, to allow user to override
105    AS_VAR_SET_IF([PLPLOT_CPPFLAGS], [], [
106      PLPLOT_CPPFLAGS=`$PKG_CONFIG --cflags-only-I $yat_plplot_pkg | sed 's|/plplot | |g'`])
107
108    AS_VAR_SET_IF([PLPLOT_CXXFLAGS], [], [
109      PLPLOT_CXXFLAGS=`$PKG_CONFIG --cflags-only-other $yat_plplot_pkg`])
110
111    AS_VAR_SET_IF([PLPLOT_LDFLAGS], [], [
112      PLPLOT_LDFLAGS=`$PKG_CONFIG --libs-only-other --libs-only-L $yat_plplot_pkg`])
113
114    AS_VAR_SET_IF([PLPLOT_LIBS], [], [
115      PLPLOT_LIBS=`$PKG_CONFIG --libs-only-l $yat_plplot_pkg`])
116  ])
117])
118
119
120AC_DEFUN([YAT_CHECK_PLPLOT_HEADER],
121[
122  AC_REQUIRE([YAT_CHECK_PKG_CONFIG_PLPLOT])
123  save_CPPFLAGS=$CPPFLAGS
124  save_CXXFLAGS=$CXXFLAGS
125  CPPFLAGS="$CPPFLAGS $PLPLOT_CPPFLAGS"
126  CXXFLAGS="$CXXFLAGS $PLPLOT_CXXFLAGS"
127  AC_CHECK_HEADERS([plplot/plstream.h], [
128    CPPFLAGS=$save_CPPFLAGS
129    CXXFLAGS=$save_CXXFLAGS
130    $1
131  ], [
132    CPPFLAGS=$save_CPPFLAGS
133    CXXFLAGS=$save_CXXFLAGS
134    $2
135  ])
136])
137
138
139AC_DEFUN([YAT_CHECK_PLPLOT_LIB],
140[
141AC_REQUIRE([YAT_CHECK_PKG_CONFIG_PLPLOT])
142
143save_CPPFLAGS=$CPPFLAGS
144save_CXXFLAGS=$CXXFLAGS
145save_LDFLAGS=$LDFLAGS
146save_LIBS=$LIBS
147AS_VAR_SET_IF([PLPLOT_LIBS], [
148  LDFLAGS="$LDFLAGS $PLPLOT_LDFLAGS"
149  LIBS="$LIBS $PLPLOT_LIBS"
150  AC_MSG_CHECKING([linking against $PLPLOT_LIBS])
151  AC_LINK_IFELSE([AC_LANG_PROGRAM()], [
152    AC_MSG_RESULT([ok])
153    dnl restore variables already here so user can set these variables (in $1)
154    LDFLAGS=$save_LDFLAGS
155    LIBS=$save_LIBS
156    $1
157  ], [
158    AC_MSG_RESULT([failed])
159    dnl restore variables already here so user can set these variables (in $2)
160    LDFLAGS=$save_LDFLAGS
161    LIBS=$save_LIBS
162    $2
163  ])
164], [ dnl else
165  CPPFLAGS="$CPPFLAGS $PLPLOT_CPPFLAGS"
166  CXXFLAGS="$CXXFLAGS $PLPLOT_CXXFLAGS"
167  LDFLAGS="$LDFLAGS $PLPLOT_LDFLAGS"
168  YAT_CHECK_LIBS([for library that contains plstream], [yat_cv_plplot_lib],
169                 [plplotcxx plplotcxxd],
170                 [AC_LANG_PROGRAM([@%:@ include <plplot/plstream.h>],
171                                  [plstream pls])],
172                 [PLPLOT_LIBS="$yat_cv_plplot_lib"
173                  dnl restore variables here so user can set it in $1
174                  CPPFLAGS=$save_CPPFLAGS
175                  CXXFLAGS=$save_CXXFLAGS
176                  LDFLAGS=$save_LDFLAGS
177                  LIBS=$save_LIBS
178                  $1],
179                 [$2])
180]) # end VAR_SET_IF
181]) # YAT_CHECK_PLPLOT_LIB
Note: See TracBrowser for help on using the repository browser.