-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathconfigure.ac
203 lines (168 loc) · 5.27 KB
/
configure.ac
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
# -*- Autoconf -*-
# Process this file with autoconf to produce a configure script.
AC_PREREQ([2.69])
AC_INIT([libcrypt4gh],[1.0],
[https://github.com/silverdaz/libcrypt4gh/issues],
[libcrypt4gh],
[https://github.com/silverdaz/libcrypt4gh])
AC_CONFIG_SRCDIR([src/crypt4gh.c])
AC_CONFIG_HEADER([src/config.h])
LIBCRYPT4GH_VERSION=1.0
AC_SUBST(LIBCRYPT4GH_VERSION)
AC_LANG([C])
AC_PROG_CC([cc gcc])
AC_PROG_CC #([cc clang gcc])
# AC_C_BIGENDIAN
# Checks for programs.
AC_PROG_CPP
AC_PROG_RANLIB
AC_CHECK_TOOLS([AR], [ar])
# System features
if test -z "$AR" ; then
AC_MSG_ERROR([*** 'ar' missing, please install or fix your \$PATH ***])
fi
AC_C_INLINE
# First of all, we need libsodium
AC_SEARCH_LIBS([sodium_malloc], [sodium], [], [AC_ERROR("libsodium is required. Install it from https://libsodium.org/.")])
#CFLAGS="${CFLAGS} $(pkg-config --cflags libsodium)"
#LDFLAGS="$LDFLAGS $(pkg-config --libs libsodium)"
if test "$GCC" = "yes"; then
AC_MSG_CHECKING([if $CC accepts -fno-builtin-memset])
saved_CFLAGS="$CFLAGS"
CFLAGS="$CFLAGS -fno-builtin-memset"
AC_LINK_IFELSE([AC_LANG_PROGRAM([[ #include <string.h> ]],
[[ char b[10]; memset(b, 0, sizeof(b)); ]])],
[ AC_MSG_RESULT([yes]) ],
[ AC_MSG_RESULT([no])
CFLAGS="$saved_CFLAGS" ]
)
fi
#######################################################
AC_MSG_CHECKING([if compiler allows __attribute__ on return types])
AC_COMPILE_IFELSE(
[AC_LANG_PROGRAM([[
#include <stdlib.h>
__attribute__((__unused__)) static void foo(void){return;}]],
[[ exit(0); ]])],
[ AC_MSG_RESULT([yes]) ],
[ AC_MSG_RESULT([no])
AC_DEFINE(NO_ATTRIBUTE_ON_RETURN_TYPE, 1,
[compiler does not accept __attribute__ on return types]) ]
)
AC_MSG_CHECKING([if compiler allows __attribute__ prototype args])
AC_COMPILE_IFELSE(
[AC_LANG_PROGRAM([[
#include <stdlib.h>
typedef void foo(const char *, ...) __attribute__((format(printf, 1, 2)));]],
[[ exit(0); ]])],
[ AC_MSG_RESULT([yes]) ],
[ AC_MSG_RESULT([no])
AC_DEFINE(NO_ATTRIBUTE_ON_PROTOTYPE_ARGS, 1,
[compiler does not accept __attribute__ on prototype args]) ]
)
# Miscellaneous checks
AC_CACHE_CHECK([whether $CC implements __FUNCTION__], ac_cv_cc_implements___FUNCTION__, [
AC_LINK_IFELSE([AC_LANG_PROGRAM([[ #include <stdio.h> ]],
[[ printf("%s", __FUNCTION__); ]])],
[ ac_cv_cc_implements___FUNCTION__="yes" ],
[ ac_cv_cc_implements___FUNCTION__="no"
])
])
if test "x$ac_cv_cc_implements___FUNCTION__" = "xyes" ; then
AC_DEFINE([HAVE___FUNCTION__], [1],
[Define if compiler implements __FUNCTION__])
fi
#######################################################
# Checks for header files.
AC_CHECK_HEADERS([ \
endian.h \
stdint.h \
string.h \
unistd.h \
])
# Check for Endianness
AC_C_BIGENDIAN(
AC_DEFINE(NATIVE_BIG_ENDIAN, 1, [machine is big-endian]),
AC_DEFINE(NATIVE_LITTLE_ENDIAN, 1, [machine is little-endian]),
AC_MSG_ERROR([unknown endianness]),
AC_MSG_ERROR([universal endianness is not supported - compile separately and use lipo(1)])
)
# "Particular Function Checks"
# see https://www.gnu.org/software/autoconf/manual/autoconf-2.69/html_node/Particular-Functions.html
AC_FUNC_MEMCMP
AC_FUNC_MALLOC
#######################################################
# Check for long long datatypes
AC_TYPE_OFF_T
AC_CHECK_TYPES([unsigned long long])
AC_CHECK_SIZEOF([int])
# More checks for data types
AC_CACHE_CHECK([for uintXX_t types], ac_cv_have_uintxx_t, [
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
#include <sys/types.h>
]], [[
uint8_t a;
uint32_t c;
a = b = c = 1;
]])],
[ ac_cv_have_uintxx_t="yes" ], [ ac_cv_have_uintxx_t="no"
])
])
if test "x$ac_cv_have_uintxx_t" = "xyes" ; then
AC_DEFINE([HAVE_UINTXX_T], [1],
[define if you have uintxx_t data type])
fi
if (test -z "$have_uintxx_t" && \
test "x$ac_cv_header_stdint_h" = "xyes")
then
AC_MSG_CHECKING([for uintXX_t types in stdint.h])
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[ #include <stdint.h> ]],
[[ uint8_t a; uint32_t b; a = b = 1;]])],
[
AC_DEFINE([HAVE_UINTXX_T])
AC_MSG_RESULT([yes])
], [ AC_MSG_RESULT([no])
])
fi
AC_CACHE_CHECK([for size_t], ac_cv_have_size_t, [
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[ #include <sys/types.h> ]],
[[ size_t foo; foo = 1235; ]])],
[ ac_cv_have_size_t="yes" ], [ ac_cv_have_size_t="no"
])
])
if test "x$ac_cv_have_size_t" = "xyes" ; then
AC_DEFINE([HAVE_SIZE_T], [1], [define if you have size_t data type])
fi
#######################################################
debug_flag=no
AC_ARG_WITH([debug],
[ --with-debug Build main code with -g -DDEBUG=xxx],
[
if test -n "$withval" && test "x$withval" != "xno"; then
CFLAGS="-g $CFLAGS"
DEFS="$DEFS -DDEBUG=${withval}"
debug_flag=yes
fi
]
)
AC_ARG_WITH([debug-prefix],
[ --with-debug-prefix Use prefix in debug statements],
[
if "x${debug_flag}" = "xyes" && test -n "$withval" ; then
DEFS="$DEFS -DDEBUG_PREFIX=${withval}"
fi
]
)
#######################################################
AC_SUBST([DEPEND], [$(cat $srcdir/src/.depend)])
AC_CONFIG_FILES([Makefile
libcrypt4gh.pc])
AC_OUTPUT
# Print summary of options
echo ""
echo " Version: ${LIBCRYPT4GH_VERSION}"
echo " Compiler: ${CC}"
echo " Compiler flags: ${CFLAGS} ${DEFS}"
#echo " Preprocessor flags: ${CPPFLAGS}"
echo " LIBS: ${LIBS}"
echo ""