summaryrefslogtreecommitdiff
path: root/configure.ac
blob: b8e9bea301176f843f4cf81324c81caed08c7885 (plain)
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
dnl  Copyright 2015 Red Hat, Inc.
dnl 
dnl  Permission to use, copy, modify, distribute, and sell this software and its
dnl  documentation for any purpose is hereby granted without fee, provided that
dnl  the above copyright notice appear in all copies and that both that
dnl  copyright notice and this permission notice appear in supporting
dnl  documentation, and that the name of Red Hat not be used in
dnl  advertising or publicity pertaining to distribution of the software without
dnl  specific, written prior permission.  Red Hat makes no
dnl  representations about the suitability of this software for any purpose.  It
dnl  is provided "as is" without express or implied warranty.
dnl 
dnl  RED HAT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
dnl  INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
dnl  EVENT SHALL RED HAT BE LIABLE FOR ANY SPECIAL, INDIRECT OR
dnl  CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
dnl  DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
dnl  TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
dnl  PERFORMANCE OF THIS SOFTWARE.
dnl
dnl Process this file with autoconf to create configure.

AC_PREREQ([2.57])

#   hsakmt versioning scheme
#
#   - The version in git has an odd MICRO version number
#
#   - Released versions, have an even MICRO version number
#
#   - Versions that break ABI must have a new MAJOR number
#
#   - If you break the ABI, then at least this must be done:
#
#        - increment MAJOR
#
#        - In the first development release where you break ABI, find
#          all instances of "hsakmt-n" and change them to hsakmt-(n+1)
#
#          This needs to be done at least in 
#                    configure.ac
#                    all Makefile.am's
#                    hsakmt-n.pc.in
#
#      This ensures that binary incompatible versions can be installed
#      in parallel.  See http://www106.pair.com/rhp/parallel.html for
#      more information
#

m4_define([hsakmt_major], 1)
m4_define([hsakmt_minor], 0)
m4_define([hsakmt_micro], 1)

m4_define([hsakmt_version],[hsakmt_major.hsakmt_minor.hsakmt_micro])

AC_INIT(hsakmt, hsakmt_version, [oded.gabbay@gmail.com], hsakmt)
AM_INIT_AUTOMAKE([foreign dist-bzip2])

# Suppress verbose compile lines
m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])])

AC_CONFIG_HEADERS(config.h)

# Checks for programs.
AC_CANONICAL_HOST
AC_PROG_AWK
test_CFLAGS=${CFLAGS+set} # We may override autoconf default CFLAGS.
AC_PROG_CC
AC_PROG_INSTALL
AC_PROG_LIBTOOL
AC_PROG_MAKE_SET
dnl HSAKMT_LINK_WITH_ENV(env-setup, program, true-action, false-action)
dnl
dnl Compiles and links the given program in the environment setup by env-setup
dnl and executes true-action on success and false-action on failure.
AC_DEFUN([HSAKMT_LINK_WITH_ENV],[dnl
	save_CFLAGS="$CFLAGS"
	save_LDFLAGS="$LDFLAGS"
	save_LIBS="$LIBS"
	CFLAGS=""
	LDFLAGS=""
	LIBS=""
	$1
	CFLAGS="$save_CFLAGS $CFLAGS"
	LDFLAGS="$save_LDFLAGS $LDFLAGS"
	LIBS="$save_LIBS $LIBS"
	AC_LINK_IFELSE(
		[AC_LANG_SOURCE([$2])],
		[hsakmt_cc_stderr=`test -f conftest.err && cat conftest.err`
		 hsakmt_cc_flag=yes],
		[hsakmt_cc_stderr=`test -f conftest.err && cat conftest.err`
		 hsakmt_cc_flag=no])

	if test "x$hsakmt_cc_stderr" != "x"; then
		hsakmt_cc_flag=no
	fi

	if test "x$hsakmt_cc_flag" = "xyes"; then
		ifelse([$3], , :, [$3])
	else
		ifelse([$4], , :, [$4])
	fi
	CFLAGS="$save_CFLAGS"
	LDFLAGS="$save_LDFLAGS"
	LIBS="$save_LIBS"
])

dnl Find a -Werror for catching warnings.
WERROR=
for w in -Werror -errwarn; do
    if test "z$WERROR" = "z"; then
        AC_MSG_CHECKING([whether the compiler supports $w])
        HSAKMT_LINK_WITH_ENV(
		[CFLAGS=$w],
		[int main(int c, char **v) { (void)c; (void)v; return 0; }],
		[WERROR=$w; yesno=yes], [yesno=no])
	AC_MSG_RESULT($yesno)
    fi
done

dnl HSAKMT_CHECK_CFLAG(flag, [program])
dnl  Adds flag to CFLAGS if the given program links without warnings or errors.
AC_DEFUN([HSAKMT_CHECK_CFLAG], [dnl
	AC_MSG_CHECKING([whether the compiler supports $1])
	HSAKMT_LINK_WITH_ENV(
		[CFLAGS="$WERROR $1"],
		[$2
		 int main(int c, char **v) { (void)c; (void)v; return 0; }
		],
		[_yesno=yes],
		[_yesno=no])
	if test "x$_yesno" = xyes; then
	   CFLAGS="$CFLAGS $1"
	fi
	AC_MSG_RESULT($_yesno)
])

AC_CHECK_SIZEOF(long)

# Checks for Sun Studio compilers
AC_CHECK_DECL([__SUNPRO_C], [SUNCC="yes"], [SUNCC="no"])
AC_CHECK_DECL([__amd64], [AMD64_ABI="yes"], [AMD64_ABI="no"])

# Default CFLAGS to -O -g rather than just the -g from AC_PROG_CC
# if we're using Sun Studio and neither the user nor a config.site
# has set CFLAGS.
if test $SUNCC = yes &&			\
   test "x$test_CFLAGS" = "x" &&	\
   test "$CFLAGS" = "-g"
then
  CFLAGS="-O -g"
fi

# 
# We ignore hsakmt_major in the version here because the major version should
# always be encoded in the actual library name. Ie., the soname is:
#
#      hsakmt-$(hsakmt_major).0.minor.micro
#
m4_define([lt_current], [hsakmt_minor])
m4_define([lt_revision], [hsakmt_micro])
m4_define([lt_age], [hsakmt_minor])

LT_VERSION_INFO="lt_current:lt_revision:lt_age"

HSAKMT_VERSION_MAJOR=hsakmt_major()
AC_SUBST(HSAKMT_VERSION_MAJOR)
HSAKMT_VERSION_MINOR=hsakmt_minor()
AC_SUBST(HSAKMT_VERSION_MINOR)
HSAKMT_VERSION_MICRO=hsakmt_micro()
AC_SUBST(HSAKMT_VERSION_MICRO)

AC_SUBST(LT_VERSION_INFO)

# Check for dependencies

HSAKMT_CHECK_CFLAG([-Wall])
HSAKMT_CHECK_CFLAG([-Wdeclaration-after-statement])
HSAKMT_CHECK_CFLAG([-Wno-unused-local-typedefs])
HSAKMT_CHECK_CFLAG([-fno-strict-aliasing])

# Checks for typedefs, structures, and compiler characteristics.
AC_CHECK_HEADER_STDBOOL
AC_TYPE_INT16_T
AC_TYPE_INT32_T
AC_TYPE_INT64_T
AC_TYPE_INT8_T
AC_TYPE_UINT16_T
AC_TYPE_UINT32_T
AC_TYPE_UINT64_T
AC_TYPE_UINT8_T

dnl =====================================
dnl posix_memalign, sigaction, alarm, gettimeofday

AC_CHECK_FUNC(posix_memalign, have_posix_memalign=yes, have_posix_memalign=no)
if test x$have_posix_memalign = xyes; then
   AC_DEFINE(HAVE_POSIX_MEMALIGN, 1, [Whether we have posix_memalign()])
fi

AC_CHECK_FUNC(sigaction, have_sigaction=yes, have_sigaction=no)
if test x$have_sigaction = xyes; then
   AC_DEFINE(HAVE_SIGACTION, 1, [Whether we have sigaction()])
fi

AC_CHECK_FUNC(alarm, have_alarm=yes, have_alarm=no)
if test x$have_alarm = xyes; then
   AC_DEFINE(HAVE_ALARM, 1, [Whether we have alarm()])
fi

AC_CHECK_HEADER([sys/mman.h],
   [AC_DEFINE(HAVE_SYS_MMAN_H, [1], [Define to 1 if we have <sys/mman.h>])])

AC_CHECK_FUNC(mmap, have_mmap=yes, have_mmap=no)
if test x$have_mmap = xyes; then
   AC_DEFINE(HAVE_MMAP, 1, [Whether we have mmap()])
fi

AC_CHECK_FUNC(mprotect, have_mprotect=yes, have_mprotect=no)
if test x$have_mprotect = xyes; then
   AC_DEFINE(HAVE_MPROTECT, 1, [Whether we have mprotect()])
fi

AC_CHECK_FUNC(getpagesize, have_getpagesize=yes, have_getpagesize=no)
if test x$have_getpagesize = xyes; then
   AC_DEFINE(HAVE_GETPAGESIZE, 1, [Whether we have getpagesize()])
fi

AC_CHECK_FUNC(gettimeofday, have_gettimeofday=yes, have_gettimeofday=no)
AC_CHECK_HEADER(sys/time.h, have_sys_time_h=yes, have_sys_time_h=no)
if test x$have_gettimeofday = xyes && test x$have_sys_time_h = xyes; then
   AC_DEFINE(HAVE_GETTIMEOFDAY, 1, [Whether we have gettimeofday()])
fi

AC_DEFUN([HSAKMT_CHECK_PTHREAD],[dnl
    if test "z$support_for_pthreads" != "zyes"; then
	HSAKMT_LINK_WITH_ENV(
		[$1], [pthread_test_program],
		[PTHREAD_CFLAGS="$CFLAGS"
		 PTHREAD_LIBS="$LIBS"
		 PTHREAD_LDFLAGS="$LDFLAGS"
		 support_for_pthreads=yes])
    fi
])

support_for_pthreads=no

AC_MSG_CHECKING(for pthreads)

HSAKMT_CHECK_PTHREAD([CFLAGS="-pthread"; LDFLAGS="-pthread"])
HSAKMT_CHECK_PTHREAD([CFLAGS="-D_REENTRANT"; LIBS="-lpthread"])
HSAKMT_CHECK_PTHREAD([CFLAGS="-D_REENTRANT"; LDFLAGS="-lroot"])
    
if test $support_for_pthreads = yes; then
    AC_DEFINE([HAVE_PTHREADS], [], [Whether pthreads is supported])
    if test $ac_cv_tls = none ; then
        CFLAGS="$CFLAGS $PTHREAD_CFLAGS"
    fi
fi

AC_MSG_RESULT($support_for_pthreads)

# distribute additional compiler and linker flags among Makefiles
# --> set and change these variables instead of CXXFLAGS or LDFLAGS (for user only)
AC_SUBST(TOOLCHAIN_SUPPORTS__THREAD)
AC_SUBST(HAVE_PTHREADS)
AC_SUBST(PTHREAD_LDFLAGS)
AC_SUBST(PTHREAD_LIBS)
AC_SUBST(PTHREAD_CFLAGS)
AC_SUBST(AM_CFLAGS)

# Checks for library functions.

AC_FUNC_MALLOC
AC_FUNC_MMAP
AC_CHECK_FUNCS([memchr memset strstr])

AC_OUTPUT([hsakmt-1.pc
           hsakmt-1-uninstalled.pc
           Makefile
	   hsakmt/Makefile
	   hsakmt/hsakmt-version.h])