forked from meganz/MEGAcmd
-
Notifications
You must be signed in to change notification settings - Fork 0
/
configure.ac
474 lines (406 loc) · 13.5 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
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
##
# @file configure.ac
# @brief an input file for autoconf tool
# (c) 2013 by Mega Limited, Auckland, New Zealand
#
# This file is part of the MEGAcmd.
#
# MEGAcmd is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
#
# @copyright Simplified (2-clause) BSD License.
#
# You should have received a copy of the license along with this
# program.
##
# -*- Autoconf -*-
# Process this file with autoconf to produce a configure script.
m4_include([sdk/m4/ax_check_compile_flag.m4])
m4_include([sdk/m4/ax_check_link_flag.m4])
m4_define([megacmd_major_version], [$(cat src/megacmdversion.h | grep "define MEGACMD_MAJOR" | cut -d" " -f 3)])
m4_define([megacmd_minor_version], [$(cat src/megacmdversion.h | grep "define MEGACMD_MINOR" | cut -d" " -f 3)])
m4_define([megacmd_micro_version], [$(cat src/megacmdversion.h | grep "define MEGACMD_MICRO" | cut -d" " -f 3)])
m4_define([megacmd_version],
[megacmd_major_version.megacmd_minor_version.megacmd_micro_version])
# libtool interface versioning
m4_define([megacmd_lt_revision], [0])
m4_define([megacmd_lt_current], [$(grep define <src/megacmdversion.h | awk '{print @S|@3}' | awk 'BEGIN { RS = "" ; FS = "\n" } {printf @S|@1*10000+@S|@2*100+@S|@3}')])
m4_define([megacmd_lt_age], [0])
AC_INIT([MEGAcmd], m4_esyscmd([ grep define < src/megacmdversion.h | awk '{print $3}' | awk 'BEGIN { RS = "" ; FS = "\n" } {printf $1"."$2"."$3}']), [https://github.com/meganz/megacmd])
AM_INIT_AUTOMAKE
AC_PROG_CC
AC_CONFIG_FILES(Makefile)
AC_OUTPUT
AC_CONFIG_SUBDIRS(sdk)
# Define _GNU_SOURCE
# AC_GNU_SOURCE
AC_USE_SYSTEM_EXTENSIONS
AM_INIT_AUTOMAKE([1.11 foreign silent-rules])
AC_CONFIG_HEADERS([src/megacmdconfig.h]) #this avoids inline definitions of stuff already defined in sdk's config.h (e.g: -DPACKAGE_NAME)
LT_INIT([shared disable-static win32-dll])
#AC_CONFIG_MACRO_DIR([m4])
# enable silent build
m4_ifndef([AM_SILENT_RULES], [m4_define([AM_SILENT_RULES],[])])
AM_SILENT_RULES([yes])
LT_CURRENT=megacmd_lt_current
LT_REVISION=megacmd_lt_revision
LT_AGE=megacmd_lt_age
AC_SUBST(LT_CURRENT)
AC_SUBST(LT_REVISION)
AC_SUBST(LT_AGE)
# Checks for typedefs, structures, and compiler characteristics.
AC_TYPE_SIZE_T
AC_TYPE_UINT8_T
AC_TYPE_UINT16_T
AC_TYPE_UINT32_T
AC_TYPE_UINT64_T
AC_TYPE_PID_T
AC_TYPE_OFF_T
AH_VERBATIM([__STDC_FORMAT_MACROS],
[/* C99 says: define this to get the PRI... macros from stdint.h */
#ifndef __STDC_FORMAT_MACROS
# define __STDC_FORMAT_MACROS 1
#endif])
AC_CHECK_TYPES([ssize_t])
AC_CANONICAL_HOST
# Check programs
AC_PROG_OBJCXX
AC_PROG_CXX
if test "$CXX" = no || test "$CXX:$GXX" = "g++:"; then
AC_MSG_ERROR([C++ compiler not found !])
fi
AC_PROG_LIBTOOL
AM_SANITY_CHECK
# Check for cppcheck
AC_CHECK_PROG(HAVE_CPPCHECK, cppcheck, yes)
AM_CONDITIONAL(CPPCHECK, test -n "$HAVE_CPPCHECK")
# set C++
AC_LANG_CPLUSPLUS
# Check headers
AC_STDC_HEADERS
AC_HEADER_STDC
AC_HEADER_STDBOOL
AC_HEADER_DIRENT
# Add 64-bits file support on some hosts
AC_SYS_LARGEFILE
# use new interfaces
AC_FUNC_FSEEKO
AC_TYPE_OFF_T
# Checks for typedefs, structures, and compiler characteristics.
AC_CHECK_SIZEOF([uint64_t])
AC_STRUCT_TM
AC_TYPE_OFF_T
AC_TYPE_SIZE_T
AC_CHECK_HEADERS([arpa/inet.h netdb.h netinet/in.h stddef.h stdint.h stdlib.h sys/socket.h sys/timeb.h htonl glob.h malloc.h sys/malloc.h malloc/malloc.h])
# Debug
AC_ARG_ENABLE(debug,
AS_HELP_STRING([--enable-debug], [enable support for running in debug mode]),
[], [enable_debug=no])
# Enable debug flags / build
if test "x$enable_debug" = "xyes" ; then
AM_CXXFLAGS="-Wall -g -ggdb3 -O0"
CXXFLAGS="-Wall -g -ggdb3 -O0"
AC_SUBST([AM_CXXFLAGS])
AC_DEFINE(DEBUG, 1, [Define to enable debug logging])
else
CXXFLAGS="$CXXFLAGS -DNDEBUG=1"
fi
# Check if we can use -fPIC flag
AX_CHECK_COMPILE_FLAG([-fPIC], [
AX_CHECK_LINK_FLAG([-fPIC],
[CXXFLAGS="$CXXFLAGS -fPIC"]
)
])
# Enable backups
CXXFLAGS="$CXXFLAGS -DENABLE_BACKUPS=1"
AM_CONDITIONAL(ENABLE_STATIC, test x$enable_static = xyes)
AC_SUBST(ENABLE_STATIC)
# TARGET OS:
WIN32=no
DARWIN=no
ANDROID=no
LINUX=no
AC_MSG_CHECKING([if building for Win32 platform])
case $host in
*-*-cygwin*)
LIBS_EXTRA="-luser32 -lkernel32"
WIN32=yes
;;
*-*-mingw*)
LIBS_EXTRA="-lws2_32 -lcrypt32 -lole32 -lwinmm -lshlwapi -lshell32"
CXXFLAGS="$CXXFLAGS -DUNICODE -DWINVER=0x0501 -DHAVE_STRUCT_TIMESPEC"
WIN32=yes
;;
*-apple-darwin*)
AC_DEFINE([_XOPEN_SOURCE], [500], [Define _XOPEN_SOURCE])
AC_DEFINE([_DARWIN_C_SOURCE], [1], [Define _DARWIN_C_SOURCE])
DARWIN=yes
;;
*-android*)
ANDROID=yes
;;
*-linux*)
LINUX=yes
;;
*)
LIBS_EXTRA=""
;;
esac
AC_MSG_RESULT([${WIN32}])
AM_CONDITIONAL([WIN32], [test "${WIN32}" = "yes"])
AM_CONDITIONAL([DARWIN], [test "${DARWIN}" = "yes"])
AM_CONDITIONAL([ANDROID], [test "${ANDROID}" = "yes"])
AM_CONDITIONAL([LINUX], [test "${LINUX}" = "yes"])
SAVE_LDFLAGS=$LDFLAGS
SAVE_CXXFLAGS=$CXXFLAGS
SAVE_CPPFLAGS=$CPPFLAGS
#
# PCRE
#
#with megacmd 0.9.4 & sdk 3.2.0, libpcrecpp is no linked in megasdk even when compiled with --with-pcre. Hence we need to check here
#Plus, contrary to what the sdk will do, if non-specified and available we default it to true
#libpcre
AC_MSG_CHECKING(for libpcrecpp)
pcre=false
AC_ARG_WITH(pcre,
AS_HELP_STRING(--with-pcre=PATH, base of libpcrecpp installation),
[
case $with_pcre in
no)
pcre=false
;;
yes)
AC_CHECK_HEADERS([pcrecpp.h],, [
AC_MSG_ERROR([pcrecpp.h header not found or not usable])
])
AC_CHECK_LIB(pcrecpp, [main], [PCRE_LIBS="-lpcrecpp"],[
AC_MSG_ERROR([Could not find libpcrecpp])
])
AC_CHECK_LIB(pcre, [pcre_compile], [PCRE_LIBS="$PCRE_LIBS -lpcre"],[
AC_MSG_ERROR([Could not find libpcre])
])
pcre=true
;;
*)
# determine if library is installed
if test -d "$with_pcre/lib64"; then
LDFLAGS="-L$with_pcre/lib64 $LDFLAGS"
CXXFLAGS="-I$with_pcre/include $CXXFLAGS"
CPPFLAGS="-I$with_pcre/include $CPPFLAGS"
AC_CHECK_HEADERS(pcrecpp.h,
PCRE_CXXFLAGS="-I$with_pcre/include"
PCRE_CPPFLAGS="-I$with_pcre/include"
PCRE_LDFLAGS="-L$with_pcre/lib64",
AC_MSG_ERROR([pcrecpp.h header not found or not usable])
)
else
LDFLAGS="-L$with_pcre/lib32 $LDFLAGS"
CXXFLAGS="-I$with_pcre/include $CXXFLAGS"
CPPFLAGS="-I$with_pcre/include $CPPFLAGS"
AC_CHECK_HEADERS(pcrecpp.h,
PCRE_CXXFLAGS="-I$with_pcre/include"
PCRE_CPPFLAGS="-I$with_pcre/include"
PCRE_LDFLAGS="-L$with_pcre/lib32",
AC_MSG_ERROR([pcrecpp.h header not found or not usable])
)
fi
AC_CHECK_LIB(pcrecpp, [main], [PCRE_LIBS="-lpcrecpp"],[
AC_MSG_ERROR([Could not find libpcrecpp])
])
AC_CHECK_LIB(pcre, [pcre_compile], [PCRE_LIBS="$PCRE_LIBS -lpcre"],[
AC_MSG_ERROR([Could not find libpcre])
])
pcre=true
#restore
LDFLAGS=$SAVE_LDFLAGS
CXXFLAGS=$SAVE_CXXFLAGS
CPPFLAGS=$SAVE_CPPFLAGS
;;
esac
],
[AC_MSG_RESULT([--with-pcre not specified])
AC_CHECK_HEADERS([pcrecpp.h], [pcre=true], [])
AC_CHECK_LIB(pcrecpp, [main], [PCRE_LIBS="-lpcrecpp"],[])
AC_CHECK_LIB(pcre, [pcre_compile], [PCRE_LIBS="$PCRE_LIBS -lpcre"],[])
])
if test "x$pcre" = "xtrue" ; then
AC_DEFINE(USE_PCRE, [1], [Define to use libpcre])
fi
AM_CONDITIONAL([USE_PCRE], [test "x$pcre" = "xtrue"])
AC_SUBST(PCRE_CXXFLAGS)
AC_SUBST(PCRE_CPPFLAGS)
AC_SUBST(PCRE_LDFLAGS)
AC_SUBST(PCRE_LIBS)
#################################################
### CLIENTS SPECIFIC DEPENDENCIES ###
#################################################
#termcap
AC_MSG_CHECKING(for termcap)
AC_ARG_WITH(termcap,
AS_HELP_STRING(--with-termcap=PATH, base of termcap installation),
[AC_MSG_RESULT($with_termcap)
case $with_termcap in
no)
;;
yes)
AC_CHECK_LIB([termcap], [tputs], [TERMCAP_LIBS="-ltermcap"],
[AC_MSG_NOTICE([termcap library not found or not usable.])]
)
;;
*)
# determine if library is installed
if test -d "$with_termcap/lib"; then
LDFLAGS="-L$with_termcap/lib $LDFLAGS"
CXXFLAGS="-I$with_termcap/include $CXXFLAGS"
CPPFLAGS="-I$with_termcap/include $CPPFLAGS"
AC_CHECK_HEADERS([termcap.h],[
TERMCAP_LDFLAGS="-L$with_termcap/lib"
TERMCAP_CXXFLAGS="-I$with_termcap/include"
TERMCAP_CPPFLAGS="-I$with_termcap/include"],
AC_MSG_NOTICE([termcap.h header not found or not usable])
)
else
LDFLAGS="-L$with_termcap $LDFLAGS"
CXXFLAGS="-I$with_termcap $CXXFLAGS"
CPPFLAGS="-I$with_termcap $CPPFLAGS"
AC_CHECK_HEADERS([termcap.h],[
TERMCAP_LDFLAGS="-L$with_termcap"
TERMCAP_CXXFLAGS="-I$with_termcap"
TERMCAP_CPPFLAGS="-I$with_termcap"],
AC_MSG_NOTICE([termcap.h header not found or not usable])
)
fi
AC_CHECK_LIB([termcap], [tputs], [TERMCAP_LIBS="-ltermcap"], [
AC_MSG_NOTICE([termcap library not found or not usable.])])
#restore
LDFLAGS=$SAVE_LDFLAGS
CXXFLAGS=$SAVE_CXXFLAGS
CPPFLAGS=$SAVE_CPPFLAGS
;;
esac
],
[AC_MSG_RESULT([--with-termcap not specified])
AC_CHECK_LIB([termcap], [tputs], [TERMCAP_LIBS="-ltermcap"],
[AC_MSG_NOTICE([termcap library not found or not usable.])]
)
]
)
AC_SUBST(TERMCAP_LDFLAGS)
AC_SUBST(TERMCAP_LIBS)
AC_SUBST(TERMCAP_CXXFLAGS)
AC_SUBST(TERMCAP_CPPFLAGS)
# ReadLine
AC_MSG_CHECKING(for Readline)
AC_ARG_WITH(readline,
AS_HELP_STRING(--with-readline=PATH, base of Readline installation),
[AC_MSG_RESULT($with_readline)
case $with_readline in
no)
AC_MSG_ERROR([readline library is required for the sample client.])
;;
yes)
AC_CHECK_HEADERS([readline/readline.h],, [
AC_MSG_ERROR([readline/readline.h header not found or not usable])
])
# readline requires termcap (or ncurses)
SAVE_LIBS=$LIBS
LIBS="$TERMCAP_LIBS $LIBS"
AC_CHECK_LIB([readline], [rl_save_prompt], [RL_LIBS="-lreadline"], [
AC_MSG_ERROR([readline library is required for the sample client.])])
LIBS=$SAVE_LIBS
;;
*)
# determine if library is installed
if test -d "$with_readline/lib"; then
LDFLAGS="-L$with_readline/lib $LDFLAGS"
CXXFLAGS="-I$with_readline/include $CXXFLAGS"
CPPFLAGS="-I$with_readline/include $CPPFLAGS"
AC_CHECK_HEADERS([readline/readline.h], [
RL_LDFLAGS="-L$with_readline/lib "
RL_CXXFLAGS="-I$with_readline/include "],
AC_MSG_ERROR([readline/readline.h header not found or not usable])
)
else
LDFLAGS="-L$with_readline $LDFLAGS"
CXXFLAGS="-I$with_readline $CXXFLAGS"
CPPFLAGS="-I$with_readline $CPPFLAGS"
AC_CHECK_HEADERS([readline/readline.h], [
RL_LDFLAGS="-L$with_readline"
RL_CXXFLAGS="-I$with_readline"],
AC_MSG_ERROR([readline/readline.h header not found or not usable])
)
fi
# readline requires termcap (or ncurses)
SAVE_LIBS=$LIBS
LIBS="$TERMCAP_LIBS $LIBS"
AC_CHECK_LIB([readline], [rl_save_prompt], [RL_LIBS="-lreadline"], [
AC_MSG_ERROR([readline library is required for the sample client.])])
LIBS=$SAVE_LIBS
#restore
LDFLAGS=$SAVE_LDFLAGS
CXXFLAGS=$SAVE_CXXFLAGS
CPPFLAGS=$SAVE_CPPFLAGS
;;
esac
],
[AC_MSG_RESULT([--with-readline not specified])
AC_CHECK_HEADERS([readline/readline.h],, [
AC_MSG_ERROR([readline/readline.h header not found or not usable])
])
# readline requires termcap (or ncurses)
SAVE_LIBS=$LIBS
LIBS="$TERMCAP_LIBS $LIBS"
AC_CHECK_LIB([readline], [rl_save_prompt], [RL_LIBS="-lreadline"], [
AC_MSG_ERROR([readline library is required for the sample client.])])
LIBS=$SAVE_LIBS
]
)
AC_SUBST(RL_LDFLAGS)
AC_SUBST(RL_LIBS)
AC_SUBST(RL_CXXFLAGS)
#PTHREAD
# check for Pthreads
AC_ARG_ENABLE(posix-threads,
AS_HELP_STRING(--disable-posix-threads, disable POSIX threads support),
[enable_posix_threads=no],
[enable_posix_threads=yes])
if test x$enable_posix_threads != xno; then
AC_CHECK_LIB(pthread, pthread_create, [HAVE_PTHREAD=yes], [HAVE_PTHREAD=no])
else
HAVE_PTHREAD=no
fi
if test "$HAVE_PTHREAD" = "yes"; then
AC_DEFINE(USE_PTHREAD, 1, [Defined if pthreads are available])
if test "$HAVE_PTHREAD" = "yes"; then
SAVE_LDFLAGS="-pthread $SAVE_LDFLAGS"
LDFLAGS="-pthread $LDFLAGS"
fi
fi
AM_CONDITIONAL([HAVE_PTHREAD], [test "${HAVE_PTHREAD}" = "yes"])
#This will simulate compilation of sdk and extract the includes defined for it. Thus we can
# take care of the configuration done for the subproject withtout having to recheck here
AC_OUTPUT
LMEGAINC=$(cd sdk; for i in $(make -n 2>/dev/null | grep "\-I" | grep megaapi ); do echo $i; done | grep "\-I" | sort | uniq | awk '{printf $0" "}')
AC_SUBST(LMEGAINC)
# Output
#AC_CONFIG_FILES([
# Makefile
#])
AC_OUTPUT
#~ AC_OUTPUT([sdk/Makefile])
AC_MSG_NOTICE([MEGAcmd configuration:
MEGACMD version: megacmd_version
Install prefix: $prefix
Compiler: $CXX
CXXFLAGS: $CXXFLAGS
CPPFLAGS: $CPPFLAGS
LDFLAGS: $LDFLAGS
debug: $enable_debug
static: $enable_static
posix threads: $enable_posix_threads
Readline: $RL_CXXFLAGS $RL_LDFLAGS $RL_LIBS
Termcap: $TERMCAP_CXXFLAGS $TERMCAP_LDFLAGS $TERMCAP_LIBS
PCRE: $PCRE_CXXFLAGS $PCRE_LDFLAGS $PCRE_LIBS
SDK includes: $LMEGAINC
])