summaryrefslogtreecommitdiff
path: root/configure.ac
blob: 5dfaf22c754ed7ea2e97afbf1a957da1b86218e8 (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
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
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
#                                               -*- Autoconf -*-
# Process this file with autoconf to produce a configure script.

AC_PREREQ([2.65])
AC_INIT([tox], [0.2.12])
AC_CONFIG_AUX_DIR(configure_aux)
AC_CONFIG_SRCDIR([toxcore/net_crypto.c])
AC_CONFIG_HEADERS([config.h])
AM_INIT_AUTOMAKE([foreign 1.10 -Wall subdir-objects tar-ustar])
m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])])
AC_CONFIG_MACRO_DIR([m4])

EXTRA_LT_LDFLAGS=

if test "x${prefix}" = "xNONE"; then
    prefix="${ac_default_prefix}"
fi

BUILD_DHT_BOOTSTRAP_DAEMON="no"
BUILD_DHT_BOOTSTRAP="no"
BUILD_TESTS="yes"
BUILD_AV="yes"
BUILD_TESTING="yes"

LIBCONFIG_FOUND="no"
WANT_NACL="no"
ADD_NACL_OBJECTS_TO_PKGCONFIG="yes"
SET_SO_VERSION="yes"

AC_ARG_ENABLE([soname-versions],
    [AC_HELP_STRING([--enable-soname-versions], [enable soname versions (must be disabled for android) (default: enabled)]) ],
    [
        if test "x$enableval" = "xno"; then
            SET_SO_VERSION="no"
        elif test "x$enableval" = "xyes"; then
            SET_SO_VERSION="yes"
        fi
    ]
)
AM_CONDITIONAL(SET_SO_VERSION, test "x$SET_SO_VERSION" = "xyes")

AC_ARG_ENABLE([nacl],
    [AC_HELP_STRING([--enable-nacl], [use nacl instead of libsodium (default: disabled)]) ],
    [
        if test "x$enableval" = "xno"; then
            WANT_NACL="no"
        elif test "x$enableval" = "xyes"; then
            WANT_NACL="yes"
        fi
    ]
)

AC_ARG_ENABLE([randombytes-stir],
    [AC_HELP_STRING([--enable-randombytes-stir], [use randombytes_stir() instead of sodium_init() for faster startup on android (default: disabled)]) ],
    [
        if test "x$enableval" = "xyes"; then
            if test "x$WANT_NACL" = "xyes"; then
                AC_MSG_WARN([randombytes_stir() is not available with NaCl library])
            else
                AC_DEFINE([USE_RANDOMBYTES_STIR], [1], [randombytes_stir() instead of sodium_init()])
            fi
        fi
    ]
)

AC_ARG_WITH(log-level,
    AC_HELP_STRING([--with-log-level=LEVEL],
                   [Logger levels: TRACE; DEBUG; INFO; WARNING; ERROR ]),
    [
        if test "x$withval" = "xTRACE"; then
            AC_DEFINE([MIN_LOGGER_LEVEL], [LOGGER_LEVEL_TRACE], [Logger_Level value])

        elif test "x$withval" = "xDEBUG"; then
            AC_DEFINE([MIN_LOGGER_LEVEL], [LOGGER_LEVEL_DEBUG], [Logger_Level value])

        elif test "x$withval" = "xINFO"; then
            AC_DEFINE([MIN_LOGGER_LEVEL], [LOGGER_LEVEL_INFO], [Logger_Level value])

        elif test "x$withval" = "xWARNING"; then
            AC_DEFINE([MIN_LOGGER_LEVEL], [LOGGER_LEVEL_WARNING], [Logger_Level value])

        elif test "x$withval" = "xERROR"; then
            AC_DEFINE([MIN_LOGGER_LEVEL], [LOGGER_LEVEL_ERROR], [Logger_Level value])
        else
            AC_MSG_WARN([Invalid logger level: $withval. Using default.])
        fi
    ]
)

PKG_PROG_PKG_CONFIG

AC_ARG_ENABLE([av],
    [AC_HELP_STRING([--disable-av], [build AV support libraries (default: auto)]) ],
    [
        if test "x$enableval" = "xno"; then
            BUILD_AV="no"
        elif test "x$enableval" = "xyes"; then
            BUILD_AV="yes"
        fi
    ]
)

AC_ARG_ENABLE([tests],
    [AC_HELP_STRING([--disable-tests], [build unit tests (default: auto)]) ],
    [
        if test "x$enableval" = "xno"; then
            BUILD_TESTS="no"
        elif test "x$enableval" = "xyes"; then
            BUILD_TESTS="yes"
        fi
    ]
)

AC_ARG_ENABLE([daemon],
    [AC_HELP_STRING([--enable-daemon], [build DHT bootstrap daemon (default: auto)]) ],
    [
        if test "x$enableval" = "xno"; then
            BUILD_DHT_BOOTSTRAP_DAEMON="no"
        elif test "x$enableval" = "xyes"; then
            BUILD_DHT_BOOTSTRAP_DAEMON="yes"
        fi
    ]
)

AC_ARG_ENABLE([dht-bootstrap],
    [AC_HELP_STRING([--enable-dht-bootstrap], [build DHT bootstrap utility (default: disabled)]) ],
    [
        if test "x$enableval" = "xno"; then
            BUILD_DHT_BOOTSTRAP="no"
        elif test "x$enableval" = "xyes"; then
            BUILD_DHT_BOOTSTRAP="yes"
        fi
    ]
)


AC_ARG_ENABLE([rt],
    [AC_HELP_STRING([--disable-rt], [Disables the librt check (default: auto)]) ],
    [
        if test "x$enableval" = "xno"; then
            DISABLE_RT="yes"
        elif test "x$enableval" = "xyes"; then
            DISABLE_RT="no"
        fi
    ]
)

AC_ARG_ENABLE([testing],
    [AC_HELP_STRING([--disable-testing], [build various testing tools (default: auto)]) ],
    [
        if test "x$enableval" = "xno"; then
            BUILD_TESTING="no"
        elif test "x$enableval" = "xyes"; then
            BUILD_TESTING="yes"
        fi
    ]
)

AC_ARG_ENABLE([[epoll]],
  [AS_HELP_STRING([[--enable-epoll[=ARG]]], [enable epoll support (yes, no, auto) [auto]])],
    [enable_epoll=${enableval}],
    [enable_epoll='auto']
  )

AC_ARG_ENABLE([[ipv6]],
  [AS_HELP_STRING([[--disable-ipv6[=ARG]]], [use ipv4 in tests (yes, no, auto) [auto]])],
    [use_ipv6=${enableval}],
    [use_ipv6='auto']
  )

if test "$use_ipv6" != "yes"; then
  AC_DEFINE([USE_IPV6],[0],[define to 0 to force ipv4])
fi

AX_HAVE_EPOLL
if test "$enable_epoll" != "no"; then
  if test "${ax_cv_have_epoll}" = "yes"; then
    AC_DEFINE([TCP_SERVER_USE_EPOLL],[1],[define to 1 to enable epoll support])
    enable_epoll='yes'
  else
    if test "$enable_epoll" = "yes"; then
      AC_MSG_ERROR([[Support for epoll was explicitly requested but cannot be enabled on this platform.]])
    fi
    enable_epoll='no'
  fi
fi

DEPSEARCH=
LIBSODIUM_SEARCH_HEADERS=
LIBSODIUM_SEARCH_LIBS=
NACL_SEARCH_HEADERS=
NACL_SEARCH_LIBS=

AC_ARG_WITH(dependency-search,
    AC_HELP_STRING([--with-dependency-search=DIR],
                   [search for dependencies in DIR, i.e., look for libraries in
                    DIR/lib and for headers in DIR/include]),
    [
        DEPSEARCH="$withval"
    ]
)

if test -n "$DEPSEARCH"; then
    CFLAGS="$CFLAGS -I$DEPSEARCH/include"
    CPPFLAGS="$CPPFLAGS -I$DEPSEARCH/include"
    LDFLAGS="$LDFLAGS -L$DEPSEARCH/lib"
    export PKG_CONFIG_PATH=$PKG_CONFIG_PATH:$DEPSEARCH/lib/pkgconfig
fi

AC_ARG_WITH(nacl-headers,
        AC_HELP_STRING([--with-nacl-headers=DIR],
                       [search for nacl<F2> header files in DIR]),
        [
            NACL_SEARCH_HEADERS="$withval"
            AC_MSG_NOTICE([will search for nacl header files in $withval])
        ]
)

AC_ARG_WITH(nacl-libs,
        AC_HELP_STRING([--with-nacl-libs=DIR],
                       [search for nacl libraries in DIR]),
        [
            NACL_SEARCH_LIBS="$withval"
            AC_MSG_NOTICE([will search for nacl libraries in $withval])
        ]
)

AC_ARG_WITH(libsodium-headers,
        AC_HELP_STRING([--with-libsodium-headers=DIR],
                       [search for libsodium header files in DIR]),
        [
            LIBSODIUM_SEARCH_HEADERS="$withval"
            AC_MSG_NOTICE([will search for libsodium header files in $withval])
        ]
)

AC_ARG_WITH(libsodium-libs,
        AC_HELP_STRING([--with-libsodium-libs=DIR],
                       [search for libsodium libraries in DIR]),
        [
            LIBSODIUM_SEARCH_LIBS="$withval"
            AC_MSG_NOTICE([will search for libsodium libraries in $withval])
        ]
)

if test "x$WANT_NACL" = "xyes"; then
    enable_shared=no
    enable_static=yes
fi

# Checks for programs.
AC_PROG_CC_C99

if test "x$ac_cv_prog_cc_c99" = "xno" ; then
    AC_MSG_ERROR([c-toxcore requires a C99 compatible compiler])
fi

AM_PROG_CC_C_O
m4_ifdef([AM_PROG_AR], [AM_PROG_AR])
AC_LIBTOOL_WIN32_DLL
AC_PROG_LIBTOOL

WIN32=no
MACH=no
AC_CANONICAL_HOST
case $host_os in
    *mingw*)
        WIN32="yes"
        EXTRA_LT_LDFLAGS="$EXTRA_LT_LDFLAGS -no-undefined"
    ;;
    *solaris*)
        LIBS="$LIBS -lssp -lsocket -lnsl"
    ;;
    *qnx*)
        LIBS="$LIBS -lsocket"
    ;;
    *freebsd*|*openbsd*)
        LDFLAGS="$LDFLAGS -L/usr/local/lib"
        CFLAGS="$CFLAGS -I/usr/local/include"
        CPPFLAGS="$CPPFLAGS -I/usr/local/include"
        ADD_NACL_OBJECTS_TO_PKGCONFIG="no"
    ;;
    darwin*)
        MACH=yes
    ;;
esac
AM_CONDITIONAL(WIN32, test "x$WIN32" = "xyes")

AC_SUBST(EXTRA_LT_LDFLAGS)

# Needed math flags for some compilers

MATH_LDFLAGS="-lm"
AC_SUBST(MATH_LDFLAGS)

# Checks for libraries.
AC_CHECK_FUNCS([explicit_bzero memset_s])
PKG_CHECK_MODULES([LIBSODIUM], [libsodium],
    [
        LIBSODIUM_FOUND="yes"
    ],
    [
        LIBSODIUM_FOUND="no"
    ])

if test "x$WANT_NACL" = "xyes"; then
    NACL_LIBS=
    NACL_LDFLAGS=
    NACL_OBJECTS=
    NACL_OBJECTS_PKGCONFIG=
    LDFLAGS_SAVE="$LDFLAGS"
    if test -n "$NACL_SEARCH_LIBS"; then
        LDFLAGS="-L$NACL_SEARCH_LIBS $LDFLAGS"
        AC_CHECK_LIB(nacl, random,
            [
                NACL_LDFLAGS="-L$NACL_SEARCH_LIBS"
                NACL_LIBS="-lnacl"
            ],
            [
                AC_MSG_ERROR([library nacl was not found in requested location $NACL_SEARCH_LIBS])
            ]
        )
    else
        AC_CHECK_LIB(nacl, random,
            [],
            [
                AC_MSG_ERROR([you enabled nacl support, but library nacl was not found on your system])
            ]
        )
    fi

    if (test -f "$NACL_SEARCH_LIBS/cpucycles.o") &&
       (test -f "$NACL_SEARCH_LIBS/randombytes.o"); then
        NACL_OBJECTS="$NACL_SEARCH_LIBS/cpucycles.o $NACL_SEARCH_LIBS/randombytes.o"
        AC_MSG_NOTICE([found extra NaCl objects: $NACL_OBJECTS])
        if test "x$ADD_NACL_OBJECTS_TO_PKGCONFIG" = "xyes"; then
            AC_MSG_NOTICE([adding extra NaCl objects to pkg-config file])
            NACL_OBJECTS_PKGCONFIG="$NACL_OBJECTS"
        fi
    else
        AC_MSG_ERROR([required NaCl object files cpucycles.o randombytes.o not found, please specify their location using the --with-nacl-libs parameter])
    fi

    LDFLAGS="$LDFLAGS_SAVE"
    AC_SUBST(NACL_LIBS)
    AC_SUBST(NACL_LDFLAGS)
    AC_SUBST(NACL_OBJECTS)
    AC_SUBST(NACL_OBJECTS_PKGCONFIG)
elif test "x$LIBSODIUM_FOUND" = "xno"; then
    LIBSODIUM_LIBS=
    LIBSODIUM_LDFLAGS=
    LDFLAGS_SAVE="$LDFLAGS"
    if test -n "$LIBSODIUM_SEARCH_LIBS"; then
        LDFLAGS="-L$LIBSODIUM_SEARCH_LIBS $LDFLAGS"
        AC_CHECK_LIB(sodium, crypto_pwhash_scryptsalsa208sha256,
            [
                LIBSODIUM_LDFLAGS="-L$LIBSODIUM_SEARCH_LIBS"
                LIBSODIUM_LIBS="-lsodium"
            ],
            [
                AC_MSG_ERROR([required library libsodium was not found in requested location $LIBSODIUM_SEARCH_LIBS or library version is too old])
            ]
        )
    else
        AC_CHECK_LIB(sodium, crypto_pwhash_scryptsalsa208sha256,
            [],
            [
                AC_MSG_ERROR([required library libsodium was not found on your system, please check http://download.libsodium.org/libsodium/releases/ or library version is too old])
            ]
        )
    fi

    LDFLAGS="$LDFLAGS_SAVE"
    AC_SUBST(LIBSODIUM_LIBS)
    AC_SUBST(LIBSODIUM_LDFLAGS)
fi

# Checks for header files.
AC_CHECK_HEADERS([arpa/inet.h fcntl.h netdb.h netinet/in.h stdint.h stdlib.h string.h sys/socket.h sys/time.h unistd.h])


if test "x$WANT_NACL" = "xyes"; then
    NACL_CFLAGS=
    CFLAGS_SAVE="$CFLAGS"
    CPPFLAGS_SAVE="$CPPFLAGS"
    if test -n "$NACL_SEARCH_HEADERS"; then
        CFLAGS="-I$NACL_SEARCH_HEADERS $CFLAGS"
        CPPFLAGS="-I$NACL_SEARCH_HEADERS $CPPFLAGS"
        AC_CHECK_HEADER(crypto_box.h,
            [
                NACL_CFLAGS="-I$NACL_SEARCH_HEADERS"
            ],
            [
                AC_MSG_ERROR([header files for library nacl were not found in requested location $NACL_SEARCH_HEADERS])
            ]
        )
    else
        AC_CHECK_HEADER(crypto_box.h,
            [],
            [
                AC_MSG_ERROR([you enabled nacl support, but nacl header files were not found on your system])
            ]
        )
    fi
    CFLAGS="$CFLAGS_SAVE"
    CPPFLAGS="$CPPFLAGS_SAVE"
    AC_SUBST(NACL_CFLAGS)
    AC_DEFINE([VANILLA_NACL], [1], [use nacl instead of libsodium])
elif test "x$LIBSODIUM_FOUND" = "xno"; then
    LIBSODIUM_CFLAGS=
    CFLAGS_SAVE="$CFLAGS"
    CPPFLAGS_SAVE="$CPPFLAGS"
    if test -n "$LIBSODIUM_SEARCH_HEADERS"; then
        CFLAGS="-I$LIBSODIUM_SEARCH_HEADERS $CFLAGS"
        CPPFLAGS="-I$LIBSODIUM_SEARCH_HEADERS $CPPFLAGS"
        AC_CHECK_HEADER(sodium.h,
            [
                LIBSODIUM_CFLAGS="-I$LIBSODIUM_SEARCH_HEADERS"
            ],
            [
                AC_MSG_ERROR([header files for required library libsodium were not found in requested location $LIBSODIUM_SEARCH_HEADERS])
            ]
        )
    else
        AC_CHECK_HEADER(sodium.h,
            [],
            [
                AC_MSG_ERROR([header files for required library libsodium was not found on your system, please check http://download.libsodium.org/libsodium/releases/])
            ]
        )
    fi
    CFLAGS="$CFLAGS_SAVE"
    CPPFLAGS="$CPPFLAGS_SAVE"
    AC_SUBST(LIBSODIUM_CFLAGS)
fi

# Checks for library functions.
if (test "x$WIN32" != "xyes") && (test "x$MACH" != "xyes") && (test "x${host_os#*openbsd}" = "x$host_os") && (test "x$DISABLE_RT" != "xyes"); then
    AC_CHECK_LIB(rt, clock_gettime,
        [
            RT_LIBS="-lrt"
            AC_SUBST(RT_LIBS)
        ],
        [
            AC_MSG_ERROR([required library rt was not found on your system])
        ]
    )
fi


AX_PTHREAD(
    [],
    [
        AC_MSG_ERROR([required library pthread was not found on your system])
    ]
)

AC_CHECK_LIB([pthread], [pthread_self],
    [
        PTHREAD_LDFLAGS="-lpthread"
        AC_SUBST(PTHREAD_LDFLAGS)
    ]
)

if test "x$BUILD_AV" = "xyes"; then
    PKG_CHECK_MODULES([OPUS], [opus],
        [],
        [
            AC_MSG_WARN([disabling AV support $OPUS_PKG_ERRORS])
            BUILD_AV="no"
        ]
    )
fi

if test "x$BUILD_AV" = "xyes"; then
    PKG_CHECK_MODULES([VPX], [vpx],
        [],
        [
            AC_MSG_WARN([disabling AV support $VPX_PKG_ERRORS])
            BUILD_AV="no"
        ]
    )
fi

if test "x$BUILD_AV" = "xyes"; then
    # toxcore lib needs an global?
    # So far this works okay
    AV_LIBS="$OPUS_LIBS $VPX_LIBS"
    AC_SUBST(AV_LIBS)

    AV_CFLAGS="$OPUS_CFLAGS $VPX_CFLAGS"
    AC_SUBST(AV_CFLAGS)
fi

if test -n "$PKG_CONFIG"; then
    if test "x$BUILD_DHT_BOOTSTRAP_DAEMON" = "xyes"; then
        PKG_CHECK_MODULES([LIBCONFIG], [libconfig >= 1.4.6],
            [
                LIBCONFIG_FOUND="yes"
            ],
            [
                AC_MSG_WARN([$LIBCONFIG_PKG_ERRORS])
                AC_MSG_WARN([libconfig not available, will not build DHT bootstrap daemon])
                BUILD_DHT_BOOTSTRAP_DAEMON="no"
            ])
    fi
else
    AC_MSG_WARN([pkg-config was not found on your system, will search for libraries manually])
fi

if (test "x$BUILD_DHT_BOOTSTRAP_DAEMON" = "xyes") && \
   (test "x$LIBCONFIG_FOUND" = "xno"); then
    AC_CHECK_HEADER(libconfig.h,
        [],
        [
            AC_MSG_WARN([header files for library libconfig was not found on your system, not building DHT bootstrap daemon])
            BUILD_DHT_BOOTSTRAP_DAEMON="no"
        ]
    )

    if test "x$BUILD_DHT_BOOTSTRAP_DAEMON" = "xyes"; then
        AC_CHECK_LIB(config, config_read,
            [],
            [
                AC_MSG_WARN([library libconfig was not found on the system])
                BUILD_DHT_BOOTSTRAP_DAEMON="no"
            ]
        )
    fi
fi

if test "x$WIN32" = "xyes"; then
    AC_CHECK_LIB(ws2_32, main,
        [
            WINSOCK2_LIBS="-liphlpapi -lws2_32"
            AC_SUBST(WINSOCK2_LIBS)
        ],
        [
            AC_MSG_ERROR([required library was not found on the system, please check your MinGW installation])
        ]
    )
fi

AM_CONDITIONAL(BUILD_DHT_BOOTSTRAP_DAEMON, test "x$BUILD_DHT_BOOTSTRAP_DAEMON" = "xyes")
AM_CONDITIONAL(BUILD_DHT_BOOTSTRAP, test "x$BUILD_DHT_BOOTSTRAP" = "xyes")
AM_CONDITIONAL(BUILD_TESTS, test "x$BUILD_TESTS" = "xyes")
AM_CONDITIONAL(BUILD_AV, test "x$BUILD_AV" = "xyes")
AM_CONDITIONAL(BUILD_TESTING, test "x$BUILD_TESTING" = "xyes")
AM_CONDITIONAL(WITH_NACL, test "x$WANT_NACL" = "xyes")
AM_CONDITIONAL(WIN32, test "x$WIN32" = "xyes")

AC_CONFIG_FILES([Makefile
                 build/Makefile
                 libtoxcore.pc
                 tox.spec
                ])

AM_COND_IF(BUILD_AV,
  [
    AC_CONFIG_FILES([libtoxav.pc])
  ],)

AC_OUTPUT