aboutsummaryrefslogtreecommitdiffstats
path: root/plpa-1.3.2/plpa.m4
blob: 0546c6972d241853175a1df6f931c8555b8a261c (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
# -*- shell-script -*-
#
# Copyright (c) 2004-2005 The Trustees of Indiana University and Indiana
#                         University Research and Technology
#                         Corporation.  All rights reserved.
# Copyright (c) 2004-2005 The Regents of the University of California.
#                         All rights reserved.
# Copyright (c) 2004-2008 High Performance Computing Center Stuttgart, 
#                         University of Stuttgart.  All rights reserved.
# Copyright (c) 2006-2009 Cisco Systems, Inc.  All rights reserved.
# $COPYRIGHT$
# 
# Additional copyrights may follow
# 
# $HEADER$
#

# Main PLPA m4 macro, to be invoked by the user
#
# Expects two or three paramters:
# 1. Configuration prefix (optional; if not specified, "." is assumed)
# 2. What to do upon success
# 3. What to do upon failure
#
AC_DEFUN([PLPA_INIT],[
    # If we used the 2 param variant of PLPA_INIT, then assume the
    # config prefix is ".".  Otherwise, it's $1.
    m4_ifval([$3], 
             [_PLPA_INIT_COMPAT([$1], [$2], [$3])],
             [AC_MSG_WARN([The 2-argument form of the PLPA INIT m4 macro is deprecated])
              AC_MSG_WARN([It was removed starting with PLPA v1.2])
              AC_MSG_ERROR([Cannot continue])])
])dnl

#-----------------------------------------------------------------------

# Do the main work for PLPA_INIT
#
# Expects three paramters:
# 1. Configuration prefix
# 2. What to do upon success
# 3. What to do upon failure
#
AC_DEFUN([_PLPA_INIT_COMPAT],[
    AC_REQUIRE([_PLPA_INTERNAL_SETUP])
    AC_REQUIRE([AC_PROG_CC])
    AC_REQUIRE([AM_PROG_LEX])
    AC_REQUIRE([AC_PROG_YACC])

    m4_define([plpa_config_prefix],[$1])

    # Check for syscall()
    AC_CHECK_FUNC([syscall], [plpa_config_happy=1], [plpa_config_happy=0])

    # Look for syscall.h
    if test "$plpa_config_happy" = 1; then
        AC_CHECK_HEADER([sys/syscall.h], [plpa_config_happy=1], [plpa_config_happy=0])
    fi

    # Look for unistd.h
    if test "$plpa_config_happy" = 1; then
        AC_CHECK_HEADER([unistd.h], [plpa_config_happy=1], [plpa_config_happy=0])
    fi

    # Check for __NR_sched_setaffinity
    if test "$plpa_config_happy" = 1; then
        AC_MSG_CHECKING([for __NR_sched_setaffinity])
        if test "$plpa_emulate" = "yes"; then
            AC_MSG_RESULT([emulated])
            AC_DEFINE([__NR_sched_setaffinity], [0], [Emulated value])
        else
            AC_TRY_COMPILE([#include <syscall.h>
#include <unistd.h>], [#ifndef __NR_sched_setaffinity
#error __NR_sched_setaffinity_not found!
#endif
int i = 1;],
                           [AC_MSG_RESULT([yes])
                            plpa_config_happy=1], 
                           [AC_MSG_RESULT([no])
                            plpa_config_happy=0])
        fi
    fi

    # Check for __NR_sched_getaffinity (probably overkill, but what
    # the heck?)
    if test "$plpa_config_happy" = 1; then
        AC_MSG_CHECKING([for __NR_sched_getaffinity])
        if test "$plpa_emulate" = "yes"; then
            AC_MSG_RESULT([emulated])
            AC_DEFINE([__NR_sched_getaffinity], [0], [Emulated value])
        else
            AC_TRY_COMPILE([#include <syscall.h>
#include <unistd.h>], [#ifndef __NR_sched_getaffinity
#error __NR_sched_getaffinity_not found!
#endif
int i = 1;],
                           [AC_MSG_RESULT([yes])
                            plpa_config_happy=1], 
                           [AC_MSG_RESULT([no])
                            plpa_config_happy=0])
        fi
    fi

    # If all was good, do the real init
    AS_IF([test "$plpa_config_happy" = "1"],
          [_PLPA_INIT($2, $3)],
          [$3])
    PLPA_DO_AM_CONDITIONALS

    AC_CONFIG_FILES(
        plpa_config_prefix[/Makefile]
        plpa_config_prefix[/src/Makefile]
        plpa_config_prefix[/src/libplpa/Makefile]
    )

    # Cleanup
    unset plpa_config_happy
])dnl

#-----------------------------------------------------------------------

# Build PLPA as a standalone package
AC_DEFUN([PLPA_STANDALONE],[
    AC_REQUIRE([_PLPA_INTERNAL_SETUP])
    plpa_mode=standalone
])dnl

#-----------------------------------------------------------------------

# Build PLPA as an included package
AC_DEFUN([PLPA_INCLUDED],[
    m4_ifval([$1], 
             [AC_MSG_WARN([The 1-argument form of the PLPA INCLUDED m4 macro is deprecated])
              AC_MSG_WARN([It was removed starting with PLPA v1.2])
              AC_MSG_ERROR([Cannot continue])])

    AC_REQUIRE([_PLPA_INTERNAL_SETUP])
    plpa_mode=included
    PLPA_DISABLE_EXECUTABLES
])dnl

#-----------------------------------------------------------------------

dnl JMS: No fortran bindings yet
dnl # Set whether the fortran bindings will be built or not
dnl AC_DEFUN([PLPA_FORTRAN],[
dnl     AC_REQUIRE([_PLPA_INTERNAL_SETUP])
dnl 
dnl    # Need [] around entire following line to escape m4 properly
dnl     [plpa_tmp=`echo $1 | tr '[:upper:]' '[:lower:]'`]
dnl     if test "$1" = "0" -o "$1" = "n"; then
dnl         plpa_fortran=no
dnl     elif test "$1" = "1" -o "$1" = "y"; then
dnl         plpa_fortran=yes
dnl     else
dnl         AC_MSG_WARN([Did not understand PLPA_FORTRAN argument ($1) -- ignored])
dnl     fi
dnl ])dnl

#-----------------------------------------------------------------------

# Disable building the executables
AC_DEFUN([PLPA_DISABLE_EXECUTABLES],[
    AC_REQUIRE([_PLPA_INTERNAL_SETUP])
    plpa_executables=no
])dnl

#-----------------------------------------------------------------------

# Disable building the executables
AC_DEFUN([PLPA_ENABLE_EXECUTABLES],[
    AC_REQUIRE([_PLPA_INTERNAL_SETUP])
    plpa_executables=yes
])dnl

#-----------------------------------------------------------------------

# Specify the symbol prefix
AC_DEFUN([PLPA_SET_SYMBOL_PREFIX],[
    AC_REQUIRE([_PLPA_INTERNAL_SETUP])
    plpa_symbol_prefix_value=$1
])dnl

#-----------------------------------------------------------------------

# Internals
AC_DEFUN([_PLPA_INTERNAL_SETUP],[

    AC_ARG_ENABLE([emulate],
                    AC_HELP_STRING([--enable-emulate],
                                   [Emulate __NR_sched_setaffinity and __NR_sched_getaffinity, to allow building on non-Linux systems (for testing)]))
    if test "$enable_emulate" = "yes"; then
        plpa_emulate=yes
    else
        plpa_emulate=no
    fi

    # Build and install the executables or no?
    AC_ARG_ENABLE([executables],
                    AC_HELP_STRING([--disable-executables],
                                   [Using --disable-executables disables building and installing the PLPA executables]))
    if test "$enable_executables" = "yes" -o "$enable_executables" = ""; then
        plpa_executables=yes
    else
        plpa_executables=no
    fi

    # Included mode, or standalone?
    AC_ARG_ENABLE([included-mode],
                    AC_HELP_STRING([--enable-included-mode],
                                   [Using --enable-included-mode puts the PLPA into "included" mode.  The default is --disable-included-mode, meaning that the PLPA is in "standalone" mode.]))
    if test "$enable_included_mode" = "yes"; then
        plpa_mode=included
        if test "$enable_executables" = ""; then
            plpa_executables=no
        fi
    else
        plpa_mode=standalone
    fi

dnl JMS: No fortran bindings yet
dnl    # Fortran bindings, or no?
dnl    AC_ARG_ENABLE([fortran],
dnl                    AC_HELP_STRING([--disable-fortran],
dnl                                   [Using --disable-fortran disables building the Fortran PLPA API bindings]))
dnl    if test "$enable_fortran" = "yes" -o "$enable_fortran" = ""; then
dnl        plpa_fortran=yes
dnl    else
dnl        plpa_fortran=no
dnl    fi

    # Change the symbol prefix?
    AC_ARG_WITH([plpa-symbol-prefix],
                AC_HELP_STRING([--with-plpa-symbol-prefix=STRING],
                               [STRING can be any valid C symbol name.  It will be prefixed to all public PLPA symbols.  Default: "plpa_"]))
    if test "$with_plpa_symbol_prefix" = ""; then
        plpa_symbol_prefix_value=plpa_
    else
        plpa_symbol_prefix_value=$with_plpa_symbol_prefix
    fi

    # Debug mode?
    AC_ARG_ENABLE([debug],
                    AC_HELP_STRING([--enable-debug],
                                   [Using --enable-debug enables various maintainer-level debugging controls.  This option is not recomended for end users.]))
    if test "$enable_debug" = "yes"; then
        plpa_debug=1
        plpa_debug_msg="enabled"
    elif test "$enable_debug" = "" -a -d .svn; then
        plpa_debug=1
        plpa_debug_msg="enabled (SVN checkout default)"
    else
        plpa_debug=0
        plpa_debug_msg="disabled"
    fi
])dnl

#-----------------------------------------------------------------------

# Internals for PLPA_INIT
AC_DEFUN([_PLPA_INIT],[
    AC_REQUIRE([_PLPA_INTERNAL_SETUP])

    # Are we building as standalone or included?
    AC_MSG_CHECKING([for PLPA building mode])
    AC_MSG_RESULT([$plpa_mode])

    # Debug mode?
    AC_MSG_CHECKING([if want PLPA maintainer support])
    AC_DEFINE_UNQUOTED(PLPA_DEBUG, [$plpa_debug], [Whether we are in debugging more or not])
    AC_MSG_RESULT([$plpa_debug_msg])

    # We need to set a path for header, etc files depending on whether
    # we're standalone or included. this is taken care of by PLPA_INCLUDED.

    AC_MSG_CHECKING([for PLPA config prefix])
    AC_MSG_RESULT(plpa_config_prefix)

    # Note that plpa_config.h *MUST* be listed first so that it
    # becomes the "main" config header file.  Any AM_CONFIG_HEADERs
    # after that (plpa.h) will only have selective #defines replaced,
    # not the entire file.
    AM_CONFIG_HEADER(plpa_config_prefix[/src/libplpa/plpa_config.h])
    AM_CONFIG_HEADER(plpa_config_prefix[/src/libplpa/plpa.h])

    # What prefix are we using?
    AC_MSG_CHECKING([for PLPA symbol prefix])
    AC_DEFINE_UNQUOTED(PLPA_SYM_PREFIX, [$plpa_symbol_prefix_value],
                       [The PLPA symbol prefix])
    # Ensure to [] escape the whole next line so that we can get the
    # proper tr tokens
    [plpa_symbol_prefix_value_caps="`echo $plpa_symbol_prefix_value | tr '[:lower:]' '[:upper:]'`"]
    AC_DEFINE_UNQUOTED(PLPA_SYM_PREFIX_CAPS, [$plpa_symbol_prefix_value_caps],
                       [The PLPA symbol prefix in all caps])
    AC_MSG_RESULT([$plpa_symbol_prefix_value])

    # Build with valgrind support if we can find it, unless it was
    # explicitly disabled
    AC_ARG_WITH([valgrind],
                [AC_HELP_STRING([--with-valgrind(=DIR)],
                [Directory where the valgrind software is installed])])
    CPPFLAGS_save="$CPPFLAGS"
    valgrind_happy=no
    AS_IF([test "$with_valgrind" != "no"],
          [AS_IF([test ! -z "$with_valgrind" -a "$with_valgrind" != "yes"],
                 [CPPFLAGS="$CPPFLAGS -I$with_valgrind/include"])
           AC_CHECK_HEADERS([valgrind/valgrind.h], 
                 [AC_MSG_CHECKING([for VALGRIND_CHECK_MEM_IS_ADDRESSABLE])
                  AC_LINK_IFELSE(AC_LANG_PROGRAM([[
#include "valgrind/memcheck.h"
]],
                     [[char buffer = 0xff;
                       VALGRIND_CHECK_MEM_IS_ADDRESSABLE(&buffer, sizeof(buffer));]]),
                     [AC_MSG_RESULT([yes])
                      valgrind_happy=yes],
                     [AC_MSG_RESULT([no])
                      AC_MSG_WARN([Need Valgrind version 3.2.0 or later.])],
                     [AC_MSG_RESULT([cross-compiling; assume yes...?])
                      AC_MSG_WARN([PLPA will fail to compile if you do not have Valgrind version 3.2.0 or later])
                      valgrind_happy=yes]),
                 ],
                 [AC_MSG_WARN([valgrind.h not found])])
           AS_IF([test "$valgrind_happy" = "no" -a "x$with_valgrind" != "x"],
                 [AC_MSG_WARN([Valgrind support requested but not possible])
                  AC_MSG_ERROR([Cannot continue])])])
    AS_IF([test "$valgrind_happy" = "no"],
          [CPPFLAGS="$CPPFLAGS_save"
           valgrind_define=0],
          [valgrind_define=1])
    AC_DEFINE_UNQUOTED([PLPA_WANT_VALGRIND_SUPPORT], [$valgrind_define],
                       [Whether we want Valgrind support or not])

dnl JMS: No fortran bindings yet
dnl    # Check for fortran
dnl    AC_MSG_CHECKING([whether to build PLPA Fortran API])
dnl    AC_MSG_RESULT([$plpa_fortran])

    # Check whether to build the exectuables or not
    AC_MSG_CHECKING([whether to build PLPA executables])
    AC_MSG_RESULT([$plpa_executables])

    # If we're building executables, we need some things for plpa-taskset
    if test "$plpa_executables" = "yes"; then
        AC_C_INLINE
    fi

    # Success
    $1
])dnl


#-----------------------------------------------------------------------

# This must be a standalone routine so that it can be called both by
# PLPA_INIT and an external caller (if PLPA_INIT is not invoked).
AC_DEFUN([PLPA_DO_AM_CONDITIONALS],[
    if test "$plpa_did_am_conditionals" != "yes"; then
        AM_CONDITIONAL([PLPA_BUILD_STANDALONE], [test "$plpa_mode" = "standalone"])
dnl JMS: No fortran bindings yet
dnl        AM_CONDITIONAL(PLPA_BUILD_FORTRAN, [test "$plpa_fortran" = "yes"])
        AM_CONDITIONAL(PLPA_BUILD_EXECUTABLES, [test "$plpa_executables" = "yes"])
    fi
    plpa_did_am_conditionals=yes
])dnl

© 2014-2024 Faster IT GmbH | imprint | privacy policy