Code

Merging in the OpenMP work from the mailing list with some improved build files.
[inkscape.git] / acinclude.m4
1 dnl  Usage: RELAYTOOL(LIBRARY_NAME, LIBS, CFLAGS, ACTION-IF-WEAK-LINK-IS-POSSIBLE)
3 dnl  Example:
4 dnl  RELAYTOOL("gtkspell", GTKSPELL_LIBS, GTKSPELL_CFLAGS, gtkspell_weak=yes)
5 dnl  Will modify GTKSPELL_LIBS to include a call to relaytool if available
6 dnl  or if not, will modify GTKSPELL_CFLAGS to include -D switches to define
7 dnl  libgtkspell_is_present=1 and libgtkspell_symbol_is_present=1
9 AC_DEFUN([RELAYTOOL], [
10     if test -z "$RELAYTOOL_PROG"; then
11         AC_PATH_PROG(RELAYTOOL_PROG, relaytool, no)
12     fi
14     AC_MSG_CHECKING(whether we can weak link $1)
16     _RELAYTOOL_PROCESSED_NAME=`echo "$1" | sed 's/-/_/g;s/\./_/g;'`
17     _RELAYTOOL_UPPER_NAME=`echo $_RELAYTOOL_PROCESSED_NAME | tr '[[:lower:]]' '[[:upper:]]'`
19     if test "$RELAYTOOL_PROG" = "no"; then
20         AC_MSG_RESULT(no)
21         $3="-DRELAYTOOL_${_RELAYTOOL_UPPER_NAME}='static const int lib${_RELAYTOOL_PROCESSED_NAME}_is_present = 1; static int __attribute__((unused)) lib${_RELAYTOOL_PROCESSED_NAME}_symbol_is_present(char *m) { return 1; }' $$3"
22     else
23         AC_MSG_RESULT(yes)
24         $2=`echo $$2|sed 's/\`/\\\\\`/g;'`
25         $2="-Wl,--gc-sections \`relaytool --relay $1 $$2\`"
26         $3="-DRELAYTOOL_${_RELAYTOOL_UPPER_NAME}='extern int lib${_RELAYTOOL_PROCESSED_NAME}_is_present; extern int lib${_RELAYTOOL_PROCESSED_NAME}_symbol_is_present(char *s);' $$3"
27         $4
28     fi
29 ])
31 # ===========================================================================
32 #               http://autoconf-archive.cryp.to/ax_openmp.html
33 # ===========================================================================
34 #
35 # SYNOPSIS
36 #
37 #   AX_OPENMP([ACTION-IF-FOUND[, ACTION-IF-NOT-FOUND]])
38 #
39 # DESCRIPTION
40 #
41 #   This macro tries to find out how to compile programs that use OpenMP a
42 #   standard API and set of compiler directives for parallel programming
43 #   (see http://www-unix.mcs/)
44 #
45 #   On success, it sets the OPENMP_CFLAGS/OPENMP_CXXFLAGS/OPENMP_F77FLAGS
46 #   output variable to the flag (e.g. -omp) used both to compile *and* link
47 #   OpenMP programs in the current language.
48 #
49 #   NOTE: You are assumed to not only compile your program with these flags,
50 #   but also link it with them as well.
51 #
52 #   If you want to compile everything with OpenMP, you should set:
53 #
54 #       CFLAGS="$CFLAGS $OPENMP_CFLAGS"
55 #       #OR#  CXXFLAGS="$CXXFLAGS $OPENMP_CXXFLAGS"
56 #       #OR#  FFLAGS="$FFLAGS $OPENMP_FFLAGS"
57 #
58 #   (depending on the selected language).
59 #
60 #   The user can override the default choice by setting the corresponding
61 #   environment variable (e.g. OPENMP_CFLAGS).
62 #
63 #   ACTION-IF-FOUND is a list of shell commands to run if an OpenMP flag is
64 #   found, and ACTION-IF-NOT-FOUND is a list of commands to run it if it is
65 #   not found. If ACTION-IF-FOUND is not specified, the default action will
66 #   define HAVE_OPENMP.
67 #
68 # LAST MODIFICATION
69 #
70 #   2008-04-12
71 #
72 # COPYLEFT
73 #
74 #   Copyright (c) 2008 Steven G. Johnson <stevenj@alum.mit.edu>
75 #
76 #   This program is free software: you can redistribute it and/or modify it
77 #   under the terms of the GNU General Public License as published by the
78 #   Free Software Foundation, either version 3 of the License, or (at your
79 #   option) any later version.
80 #
81 #   This program is distributed in the hope that it will be useful, but
82 #   WITHOUT ANY WARRANTY; without even the implied warranty of
83 #   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
84 #   Public License for more details.
85 #
86 #   You should have received a copy of the GNU General Public License along
87 #   with this program. If not, see <http://www.gnu.org/licenses/>.
88 #
89 #   As a special exception, the respective Autoconf Macro's copyright owner
90 #   gives unlimited permission to copy, distribute and modify the configure
91 #   scripts that are the output of Autoconf when processing the Macro. You
92 #   need not follow the terms of the GNU General Public License when using
93 #   or distributing such scripts, even though portions of the text of the
94 #   Macro appear in them. The GNU General Public License (GPL) does govern
95 #   all other use of the material that constitutes the Autoconf Macro.
96 #
97 #   This special exception to the GPL applies to versions of the Autoconf
98 #   Macro released by the Autoconf Macro Archive. When you make and
99 #   distribute a modified version of the Autoconf Macro, you may extend this
100 #   special exception to the GPL to apply to your modified version as well.
102 AC_DEFUN([AX_OPENMP], [
103 AC_PREREQ(2.59) dnl for _AC_LANG_PREFIX
105 AC_CACHE_CHECK([for OpenMP flag of _AC_LANG compiler], ax_cv_[]_AC_LANG_ABBREV[]_openmp, [save[]_AC_LANG_PREFIX[]FLAGS=$[]_AC_LANG_PREFIX[]FLAGS
106 ax_cv_[]_AC_LANG_ABBREV[]_openmp=unknown
107 # Flags to try:  -fopenmp (gcc), -openmp (icc), -mp (SGI & PGI),
108 #                -xopenmp (Sun), -omp (Tru64), -qsmp=omp (AIX), none
109 ax_openmp_flags="-fopenmp -openmp -mp -xopenmp -omp -qsmp=omp none"
110 if test "x$OPENMP_[]_AC_LANG_PREFIX[]FLAGS" != x; then
111   ax_openmp_flags="$OPENMP_[]_AC_LANG_PREFIX[]FLAGS $ax_openmp_flags"
112 fi
113 for ax_openmp_flag in $ax_openmp_flags; do
114   case $ax_openmp_flag in
115     none) []_AC_LANG_PREFIX[]FLAGS=$save[]_AC_LANG_PREFIX[] ;;
116     *) []_AC_LANG_PREFIX[]FLAGS="$save[]_AC_LANG_PREFIX[]FLAGS $ax_openmp_flag" ;;
117   esac
118   AC_TRY_LINK_FUNC(omp_set_num_threads,
119         [ax_cv_[]_AC_LANG_ABBREV[]_openmp=$ax_openmp_flag; break])
120 done
121 []_AC_LANG_PREFIX[]FLAGS=$save[]_AC_LANG_PREFIX[]FLAGS
122 ])
123 if test "x$ax_cv_[]_AC_LANG_ABBREV[]_openmp" = "xunknown"; then
124   m4_default([$2],:)
125 else
126   if test "x$ax_cv_[]_AC_LANG_ABBREV[]_openmp" != "xnone"; then
127     OPENMP_[]_AC_LANG_PREFIX[]FLAGS=$ax_cv_[]_AC_LANG_ABBREV[]_openmp
128   fi
129   m4_default([$1], [AC_DEFINE(HAVE_OPENMP,1,[Define if OpenMP is enabled])])
130 fi
131 ])dnl AX_OPENMP