-
Notifications
You must be signed in to change notification settings - Fork 0
/
configure.ac
1426 lines (1165 loc) · 60.7 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
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
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# Process this file with autoconf to produce a configure script.
#
# Hand written file: used as input into GNU Autotools (autoconf).
# This is part of GNU Astronomy Utilities (gnuastro) package.
#
# We use some macros that are distributed as part of the GNU Autoconf
# Archive here. Those macros are all placed in the bootstrapped/m4/
# directory along with those that were imported from Gnulib. The
# ./bootstrap script includes that directory while its running Autoconf so
# we don't need to explicitly call that directory here.
#
# Original author:
# Mohammad Akhlaghi <[email protected]>
# Contributing author(s):
# Pedram Ashofteh-Ardakani <[email protected]>
# Jash Shah <[email protected]>
# Copyright (C) 2015-2024 Free Software Foundation, Inc.
#
# Gnuastro is free software: you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Gnuastro 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. See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Gnuastro. If not, see <http://www.gnu.org/licenses/>.
# Definitions:
AC_PREREQ([2.69])
AC_INIT([GNU Astronomy Utilities],
m4_esyscmd([bootstrapped/build-aux/git-version-gen \
.tarball-version --prefix "gnuastro_v"]),
[[email protected]], [gnuastro],
[http://www.gnu.org/software/gnuastro/])
AC_CONFIG_AUX_DIR([bootstrapped/build-aux])
AM_INIT_AUTOMAKE([-Wall subdir-objects gnu])
AC_CONFIG_SRCDIR([lib/fits.c])
AC_CONFIG_HEADERS([config.h])
AC_CONFIG_MACRO_DIRS([bootstrapped/m4])
# Library version, see the GNU Libtool manual ("Library interface versions"
# section for the exact definition of each) for
GAL_CURRENT=22
GAL_REVISION=0
GAL_AGE=0
GAL_LT_VERSION="${GAL_CURRENT}:${GAL_REVISION}:${GAL_AGE}"
AC_SUBST(GAL_LT_VERSION)
# Checks for programs.
: ${CFLAGS=""}
: ${CXXFLAGS=""}
AC_PROG_CC
AC_PROG_CXX
AC_PROG_AWK
AC_PROG_SED
gl_EARLY
AM_PROG_AR
LT_INIT
# Check the number of jobs. Depending on the operative system (GNU/Linux or
# macOS), the way of getting the number of cores is different. If the
# number of cores can not be obtained, set it to 8.
AC_CHECK_PROG(has_nproc, nproc, [yes], [no])
AS_IF([test $has_nproc = yes],
[jobs=$(nproc --all)],
[
AC_CHECK_PROG(has_sysctl, sysctl, [yes], [no])
AS_IF([test $has_sysctl = yes],
[jobs=$(sysctl -a | awk '/^hw\.ncpu/{print $2}')],
[jobs=8])
])
AC_SUBST(SUGGESTEDJOBS, [$jobs])
# This macro will let the libraries know that we are now in the Gnuastro
# build system, not on the user's system. While we are building Gnuastro,
# we have the important installation information in 'config.h'. But in the
# user's own programs, this information is defined in
# 'gnuastro/config.h'. With this macro, the installed headers can decide
# if the latter should be included or not. Note that 'gnuastro/config.h'
# is only built at installation time and doesn't exist when building
# Gnuastro. Therefore, this macro must not be defined in a user's program.
AC_DEFINE([IN_GNUASTRO_BUILD], [1], [In building, not usage])
# See if 'make check' should be made with Valgrind. This should be done
# before checking the compilation flags because it can re-write
# 'enable-debug').
AC_ARG_ENABLE(check-with-valgrind,
[AS_HELP_STRING([--enable-check-with-valgrind],
[Run 'make check' programs within Valgrind])],
[AS_IF([test "x$enable_check_with_valgrind" != xno],
[enable_check_with_valgrind=yes])],
[enable_check_with_valgrind=no])
AS_IF([test "x$enable_check_with_valgrind" = "xyes"],
[
enable_debug=yes;
AC_CHECK_PROG(has_valgrind, valgrind, [yes], [no])
AS_IF([test "x$has_valgrind" = "xno"],
[AC_MSG_ERROR([Valgrind not found. Please install it or don't use '--enable-check-with-valgrind'])])
])
AM_CONDITIONAL([COND_CHECK_WITH_VALGRIND], [test "x$enable_check_with_valgrind" = "xyes"])
# Set the compilation flags.
AC_ARG_ENABLE(debug,
[AS_HELP_STRING([--enable-debug],
[No optimization, debug flags, no shared lib.])],
[AS_IF([test "x$enable_debug" != xno], [enable_debug=yes])],
[enable_debug=no])
AS_IF([test "x$enable_debug" = "xyes"],
[cflags_add="-g -O0"; enable_shared=no],
[cflags_add="-O3"])
CFLAGS="-Wall $cflags_add $CFLAGS"
CXXFLAGS="-Wall $cflags_add $CXXFLAGS"
# See if the C++ compiler was present. 'CXX' has already been set by
# 'AC_PROG_CXX' (above). According to the Autoconf manual: "if none of the
# [AC_PROG_CXX] checks succeed, then as a last resort [it will] set 'CXX'
# to 'g++'". Therefore, we can't rely on it to see if the compiler
# executable is actually usable. Therefore tests that rely on it will
# fail. Unfortunately some OSs (like Fedora), don't install 'g++' with
# 'gcc', so it may not always be present. To fix this, here we are just
# using 'AC_CHECK_PROG' to see if the 'CXX' executable is reachable in the
# search path and if it isn't, we'll disable the C++ check during 'make
# check' with an Automake conditional.
AC_CHECK_PROG(has_cxx, $CXX, "yes", "no")
AM_CONDITIONAL([COND_HASCXX], [test "x$has_cxx" = "xyes"])
# Check for pthreads and add the appropriate compilation flags. AX_PTHREAD
# comes from the GNU Autoconf Archive's ax_pthread.m4, see there for the
# documentation.
AX_PTHREAD([],[AC_MSG_ERROR([AC_PACKAGE_NAME Needs POSIX Threads (pthread)])])
CXXFLAGS="$CXXFLAGS $PTHREAD_CFLAGS"
CFLAGS="$CFLAGS $PTHREAD_CFLAGS"
LIBS="$PTHREAD_LIBS $LIBS"
CC="$PTHREAD_CC"
# See if the C++ compiler understands '-Qunused-arguments'. AX_PTHREAD adds
# puts this option in 'PTHREAD_CFLAGS' when the C compiler knows this
# option. We then pass it to CFLAGS and CXXFLAGS above. But as reported in
# bug #52490, it can happen that sometimes, the C++ compiler doesn't
# recognize it. So we need to do a separate check for C++.
cxxflags_tmp=
for flg in $CXXFLAGS
do
AS_IF([test "$flg" = \-Qunused-arguments],
[ AC_LANG(C++)
AX_CHECK_COMPILE_FLAG([-Qunused-arguments],
[cxx_Qunused_arguments=yes;
cxxflags_tmp="$cxxflags_tmp $flg"],
[cxx_Qunused_arguments=no])
AC_LANG(C) ],
[ cxxflags_tmp="$cxxflags_tmp $flg"])
done
CXXFLAGS="$cxxflags_tmp"
# Check if 'malloc(0)' returns valid pointer
AC_FUNC_MALLOC
# Check the size of necessary system specific types.
AC_CHECK_SIZEOF([size_t])
AC_SUBST(SIZEOF_SIZE_T, [$ac_cv_sizeof_size_t])
AC_DEFINE_UNQUOTED([GAL_CONFIG_SIZEOF_SIZE_T], [$ac_cv_sizeof_size_t],
[On 32bit will be 4, on 64 bit, will be 8])
AC_CHECK_SIZEOF([long])
AC_SUBST(SIZEOF_LONG, [$ac_cv_sizeof_long])
AC_DEFINE_UNQUOTED([GAL_CONFIG_SIZEOF_LONG], [$ac_cv_sizeof_long],
[On 32bit will be 4, on 64 bit, will be 8])
AC_CHECK_SIZEOF([int])
AC_SUBST(SIZEOF_INT, [$ac_cv_sizeof_int])
AC_DEFINE_UNQUOTED([GAL_CONFIG_SIZEOF_INT], [$ac_cv_sizeof_int],
[It may be 16bit or 32bit])
# By default we assume no warnings
anywarnings=no
# Remove any occurance of the current directory './', '.', or the full
# address of the current directory in PATH. The main problem is the
# 'libtool' executable which Gnuastro builds internally in the top build
# directory. However, we also need to know if the system has libtool or
# not.
AC_MSG_CHECKING(if PATH contains current directory)
oldPATH=$PATH
currpwd=$(pwd)
# The first call to SED will remove any occurance of the current directory:
# './', '.', or the full address.
#
# NOTE 1: We cannot simply remove all '.'s, because hidden directories
# (like the '~/.local' that is suggested for local
# installations) will also be altered.
#
# NOTE 2: An empty string in the list of strings (separated by ':')
# means the current directory. This includes cases like: '::',
# or a leading and trailing ':'. So after all the removals of
# the current directory, we will remove all such cases.
#
# NOTE 3: The SED separator can be any character immediately after 's',
# it doesn't just have to be the commonly used '/'. Since '$pwd'
# will possibly contain many '/'s, it is much more easier to use
# a differen separator ('|' in this call to SED).
PATH=$(AS_ECHO([$PATH]) | $SED -e 's|'"$currpwd"'||g' \
-e 's|\.\.*//*||g' \
-e 's|:\.\.*:|:|g' \
-e 's|\.*$||' \
-e 's|^\.*||' \
-e 's|::*|:|g' \
-e 's|^:||' \
-e 's|:$||' )
AS_IF([test $oldPATH = $PATH],
[ path_warning=no ],
[ path_warning=yes; anywarnings=yes ])
AC_MSG_RESULT( $path_warning )
# Libraries
# ---------
#
# After each library is found, AC_SEARCH_LIBS adds the -lLIBRARY flag to
# the LIBS variable which is then given to all the Makefiles. Each new flag
# is added to the left of the old one so order matters here. Note that the
# LIBS variable is also used in checking the next libraries, so the linking
# with their dependent libraries is done automatically with this order, and
# we don't have to explicitly set the dependency flags.
has_gsl=yes
has_libgit2=1
has_cmath=yes
has_wcslib=yes
has_cfitsio=yes
has_libtiff=yes
has_libjpeg=yes
has_gslcblas=yes
missing_mandatory=no
missing_optional_lib=no
# Keep the original LIBS to re-set in the end.
orig_LIBS="$LIBS"
# Basics of the library linking checks
# ------------------------------------
#
# Outputs of 'AC_LIB_HAVE_LINKFLAGS' (which checks for libraries):
#
# - LIB<NAME>: contains the raw 'libNAME.so' or 'libNAME.a' file for some
# libraries. This is necessary for static libraries, but is problematic
# for shared libraries (they will not be linked to the produced
# library: when you run 'ldd libgnuastro.so', you don't see those that
# were linked with a '.so' file here).
#
# To make things worse, when linking Gnuastro's programs with
# Gnuastro's library, libtool will put raw files ('.a' or '.so' files,
# not '-lNAME') before 'libgnuastro.la' (which depends on them). As a
# result, building shared programs with Gnuastro's library will
# fail. But this is desired for static libraries.
#
# - LTLIB<NAME>: has '-lNAME', along with any necessary RPATH flags for
# the local operating system.
#
# Major environment variables:
#
# - LIBS: is primarily used in the compilation checks of the configure
# script where the host's compiler has full control.
#
# - LDADD: is passed to the rules that build Gnuastro's library and
# programs through the 'CONFIG_LDADD' variable.
#
# Since nothing complex is built during the configure script, we'll just
# populate 'LIBS' with 'LTLIB<NAME>'. However, building the programs and
# library is very complex and we have an even more complex BuildProgram in
# Gnaustro. So we fill 'LDADD' conditionally: 1) for building static
# library/programs, we'll use 'LIB<NAME>'. 2) for building shared
# libraries, we'll use 'LTLIB<NAME>'.
# Why C math library (for things like 'log')? Even though '-lm' is also
# found for GSL below, on some systems (reported on Ubuntu), if we don't
# add it explicitly here, the build will crash because of a failure to link
# with the math functions.
AC_LIB_HAVE_LINKFLAGS([m], [], [#include <math.h>])
AS_IF([test "x$LIBM" = x], [],
[LIBS="$LIBM $LIBS"
AS_IF([ test "x$enable_shared" = "xno" ],
[LDADD="$LIBM $LDADD"],
[LDADD="$LTLIBM $LDADD"]) ])
AC_LIB_HAVE_LINKFLAGS([gsl], [gslcblas], [
#include <gsl/gsl_rng.h>
void junk(void) { gsl_rng_env_setup(); } ])
AS_IF([test "x$LIBGSL" = x],
[missing_mandatory=yes; has_gsl=no; has_gslcblas=no],
[LIBS="$LIBGSL $LIBS"
AS_IF([ test "x$enable_shared" = "xno" ],
[LDADD="$LIBGSL $LDADD"],
[LDADD="$LTLIBGSL $LDADD"]) ])
# Since version 0.42, if 'libcurl' is installed, CFITSIO will link with it
# and thus it will be necessary to explicitly link with libcurl also. If it
# doesn't exist on the system, then CFITSIO won't link with it and there is
# no problem for Gnuastro either. So there is no need to stop the configure
# script if libcurl isn't found.
#
# For static builds, linking libcurl (also built in static-only mode) will
# depend on linking with zlib. So we'll need to also search for that
# also. But if libcurl isn't built in static-only mode, then it will have
# undefined symbols for many libraries (for example libpsl, libidn2,
# librtmp, libldap). So if you intend to make Gnuastro statically, then
# build Libcurl in static-only mode so you won't have to check for all
# these extra libraries here.
#
# Similarly, if the Bzip2 library was activated when building CFITSIO, it
# will be necessary in a static build to CFITSIO.
AC_LIB_HAVE_LINKFLAGS([z], [], [#include <zlib.h>])
AS_IF([test "x$LIBZ" = x], [],
[LIBS="$LIBZ $LIBS"
AS_IF([ test "x$enable_shared" = "xno" ],
[LDADD="$LIBZ $LDADD"],
[LDADD="$LTLIBZ $LDADD"]) ])
AC_LIB_HAVE_LINKFLAGS([bz2], [], [#include <bzlib.h>])
AS_IF([test "x$LIBBZ2" = x], [],
[LIBS="$LIBBZ2 $LIBS"
AS_IF([ test "x$enable_shared" = "xno" ],
[LDADD="$LIBBZ2 $LDADD"],
[LDADD="$LTLIBBZ2 $LDADD"]) ])
AC_LIB_HAVE_LINKFLAGS([curl], [], [#include <curl/curl.h>])
AS_IF([test "x$LIBCURL" = x], [],
[LIBS="$LIBCURL $LIBS"
AS_IF([ test "x$enable_shared" = "xno" ],
[LDADD="$LIBCURL $LDADD"],
[LDADD="$LTLIBCURL $LDADD"]) ])
AC_LIB_HAVE_LINKFLAGS([cfitsio], [], [
#include <fitsio.h>
void junk(void) {
int status;
fitsfile *f;
ffopen(&f, "junk", READONLY, &status);} ])
AS_IF([test "x$LIBCFITSIO" = x],
[missing_mandatory=yes; has_cfitsio=no],
[LIBS="$LIBCFITSIO $LIBS"
AS_IF([ test "x$enable_shared" = "xno" ],
[LDADD="$LIBCFITSIO $LDADD"],
[LDADD="$LTLIBCFITSIO $LDADD"]) ])
AC_LIB_HAVE_LINKFLAGS([wcs], [], [
#include <wcslib/wcshdr.h>
void junk(void) {
int nreject, nwcs;
struct wcsprm *wcs;
char *header="JUNK";
wcspih(header, 1, 0, 0, &nreject, &nwcs, &wcs);
} ])
AS_IF([test "x$LIBWCS" = x],
[missing_mandatory=yes; has_wcslib=no],
[LIBS="$LIBWCS $LIBS"
AS_IF([ test "x$enable_shared" = "xno" ],
[LDADD="$LIBWCS $LDADD"],
[LDADD="$LTLIBWCS $LDADD"]) ])
AC_ARG_WITH([libjpeg],
[AS_HELP_STRING([--without-libjpeg],
[disable support for libjpeg])],
[], [with_libjpeg=yes])
AS_IF([test "x$with_libjpeg" != xno],
[ AC_LIB_HAVE_LINKFLAGS([jpeg], [], [
#include <stdio.h>
#include <stdlib.h>
#include <jpeglib.h>
void junk(void) {
struct jpeg_decompress_struct cinfo;
jpeg_create_decompress(&cinfo);
} ]) ])
AS_IF([test "x$LIBJPEG" = x],
[missing_optional_lib=yes; has_libjpeg=no; anywarnings=yes],
[LIBS="$LIBJPEG $LIBS"
AS_IF([ test "x$enable_shared" = "xno" ],
[LDADD="$LIBJPEG $LDADD"],
[LDADD="$LTLIBJPEG $LDADD"]) ])
AM_CONDITIONAL([COND_HASLIBJPEG], [test "x$has_libjpeg" = "xyes"])
AC_ARG_WITH([libtiff],
[AS_HELP_STRING([--without-libtiff],
[disable support for libtiff])],
[], [with_libtiff=yes])
AS_IF([test "x$with_libtiff" != xno],
[ AC_LIB_HAVE_LINKFLAGS([lzma], [], [#include <lzma.h>])
AC_LIB_HAVE_LINKFLAGS([tiff], [], [
#include <tiffio.h>
void junk(void) {TIFF *tif=TIFFOpen("junk", "r");} ])
])
AS_IF([test "x$LIBTIFF" = x],
[missing_optional_lib=yes; has_libtiff=no; anywarnings=yes],
[LIBS="$LIBTIFF $LIBS"
AS_IF([ test "x$enable_shared" = "xno" ],
[LDADD="$LIBTIFF $LDADD"],
[LDADD="$LTLIBTIFF $LDADD"]) ])
AM_CONDITIONAL([COND_HASLIBTIFF], [test "x$has_libtiff" = "xyes"])
# libgit2 (very old versions of libgit2 don't have the 'git_libgit2_init').
AC_ARG_WITH([libgit2],
[AS_HELP_STRING([--without-libgit2],
[disable support for libgit2])],
[], [with_libgit2=yes])
AS_IF([test "x$with_libgit2" != xno],
[ AC_LIB_HAVE_LINKFLAGS([git2], [], [
#include <git2.h>
void junk(void) {git_libgit2_init();} ])
])
AS_IF([test "x$LIBGIT2" = x],
[missing_optional_lib=yes; has_libgit2=0],
[LIBS="$LIBGIT2 $LIBS"
AS_IF([ test "x$enable_shared" = "xno" ],
[LDADD="$LIBGIT2 $LDADD"],
[LDADD="$LTLIBGIT2 $LDADD"]) ])
AC_SUBST(HAVE_LIBGIT2_FOR_CONF, [$has_libgit2])
AC_DEFINE_UNQUOTED([GAL_CONFIG_HAVE_LIBGIT2], [$has_libgit2],
[libgit2 is installed on the system])
AS_IF([test "x$has_libgit2" = "x1"], [], [anywarnings=yes])
# Check if the compiler works with static linking
AS_IF([test "$lt_cv_prog_compiler_static_works" = no ],
[ AS_IF([test "$enable_shared" = no ],
[ anywarnings=yes;
enable_shared_disabled=yes ])
enable_shared=yes ])
# End of library linking list
# ---------------------------
#
# If we are in static mode, convert any string ending in 'libpthread.a' to
# '-lpthread' (because pthread is part of the C library and atleast in
# Gnuastro's usage so far, can't be statically linked (gives errors on
# undefined symbols like '_dl_pagesize' or '_dl_init_static_tls').
AS_IF([test "x$enable_shared" = "xno"],
[ LDADD=$(AS_ECHO(["$LDADD"]) \
| $AWK '{for(i=1; i<=NF; ++i) { \
if( $i ~ /libpthread.a/ ) \
$i="-lpthread" } \
print $0}')
])
# Higher-level library tests
# --------------------------
#
# Once we know that a library exsits, we need to check if it has some
# features or not. This must be done _after_ checking the existance of
# _all_ the libraries, because they may add elements to 'LIBS'/'LDADD' that
# causes possibly different versions of the libraries to be read.
# GSL's 'gsl_interp_steffen' isn't a function. So we'll need to use
# 'AC_LINK_IFELSE'. However, AC_LINK_IFELSE doesn't use 'LDADD', so we'll
# have to temporarily add 'LDADD' to LIBS, then set it back to the
# original.
AC_MSG_CHECKING(if GSL supports Steffen splines)
AC_LINK_IFELSE([AC_LANG_PROGRAM(
[[#include <gsl/gsl_interp.h>]],
[[const gsl_interp_type *itype=gsl_interp_steffen;]])],
[AC_MSG_RESULT(yes)
gsl_version_old=no; has_gsl_steffen=1;],
[AC_MSG_RESULT(no)
gsl_version_old=yes; has_gsl_steffen=0; anywarnings=yes;])
AC_DEFINE_UNQUOTED([GAL_CONFIG_HAVE_GSL_INTERP_STEFFEN],
[$has_gsl_steffen],
[GSL has the Steffen interpolation])
AC_SUBST(HAVE_GSL_STEFFEN, [$has_gsl_steffen])
# If the CFITSIO library has the 'fits_is_reentrant' function (it was added
# since version 3.30 of April 2012).
AC_CHECK_LIB([cfitsio], [fits_is_reentrant], [has_fits_is_reentrant=1],
[has_fits_is_reentrant=0; anywarnings=yes], [-lm])
AC_DEFINE_UNQUOTED([GAL_CONFIG_HAVE_FITS_IS_REENTRANT],
[$has_fits_is_reentrant],
[CFITSIO has the fits_is_reentrant function])
AC_SUBST(HAVE_FITS_IS_REENTRANT, [$has_fits_is_reentrant])
# If the WCS library has the 'wcslib_version' function.
AC_CHECK_LIB([wcs], [wcslib_version], [has_wcslib_version=1],
[has_wcslib_version=0; anywarnings=yes], [-lcfitsio -lm])
AC_DEFINE_UNQUOTED([GAL_CONFIG_HAVE_WCSLIB_VERSION], [$has_wcslib_version],
[WCSLIB comes with wcslib_version])
AC_SUBST(HAVE_WCSLIB_VERSION, [$has_wcslib_version])
# If the WCS library supports distortion
AC_CHECK_HEADER([wcslib/dis.h], [has_wcslib_dis_h=1],
[has_wcslib_dis_h=0; anywarnings=yes])
AC_DEFINE_UNQUOTED([GAL_CONFIG_HAVE_WCSLIB_DIS_H], [$has_wcslib_dis_h],
[WCSLIB has distortion header in dis.h])
AC_SUBST(HAVE_WCSLIB_DIS_H, [$has_wcslib_dis_h])
AM_CONDITIONAL([COND_HASWCSDIS_H], [test "x$has_wcslib_dis_h" = "x1"])
# If the WCS library has the 'mjdref' element.
AC_CHECK_MEMBER([struct wcsprm.mjdref], [has_wcslib_mjdref=1],
[has_wcslib_mjdref=0], [[#include <wcslib/wcs.h>]])
AC_DEFINE_UNQUOTED([GAL_CONFIG_HAVE_WCSLIB_MJDREF], [$has_wcslib_mjdref],
[WCSLIB comes with wcsprm.mjdref])
AC_SUBST(HAVE_WCSLIB_MJDREF, [$has_wcslib_mjdref])
# If the WCS library has the OBSFIX macro.
AC_CHECK_DECL(OBSFIX, [has_wcslib_obsfix=1],
[has_wcslib_obsfix=0], [[#include <wcslib/wcsfix.h>]])
AC_DEFINE_UNQUOTED([GAL_CONFIG_HAVE_WCSLIB_OBSFIX], [$has_wcslib_obsfix],
[WCSLIB comes with OBSFIX macro])
AC_SUBST(HAVE_WCSLIB_OBSFIX, [$has_wcslib_obsfix])
# If the WCS library has the 'wcsccs' function.
AC_CHECK_LIB([wcs], [wcsccs], [has_wcslib_wcsccs=1],
[has_wcslib_wcsccs=0; anywarnings=yes], [-lcfitsio -lm])
AC_DEFINE_UNQUOTED([GAL_CONFIG_HAVE_WCSLIB_WCSCCS], [$has_wcslib_wcsccs],
[WCSLIB comes with wcsccs])
AC_SUBST(HAVE_WCSLIB_WCSCCS, [$has_wcslib_wcsccs])
# If the pthreads library has 'pthread_barrier_wait'.
AC_CHECK_LIB([pthread], [pthread_barrier_wait], [has_pthread_barrier=1],
[has_pthread_barrier=0])
AC_DEFINE_UNQUOTED([GAL_CONFIG_HAVE_PTHREAD_BARRIER], [$has_pthread_barrier],
[System has pthread_barrier])
AC_SUBST(HAVE_PTHREAD_BARRIER, [$has_pthread_barrier])
# If a GNU Make header can be found (for Gnuastro's GNU Make extensions)
AC_CHECK_HEADER([gnumake.h], [has_gnumake_h=1],
[has_gnumake_h=0; anywarnings=yes])
AC_DEFINE_UNQUOTED([GAL_CONFIG_HAVE_GNUMAKE_H], [$has_gnumake_h],
[GNU Make's extension header is present.])
AC_SUBST(HAVE_GNUMAKE_H, [$has_gnumake_h])
AM_CONDITIONAL([COND_HASGNUMAKE_H], [test "x$has_gnumake_h" = "x1"])
# Programs
# --------
# Help2man:
AC_CHECK_PROG(has_help2man, help2man, [yes], [no])
AM_CONDITIONAL([COND_HASHELP2MAN], [test "x$has_help2man" = "xyes"])
# cURL:
AC_CHECK_PROG(has_curl, curl, [yes], [no])
AS_IF([test "x$has_curl" = "xno"], [anywarnings=yes])
# Check the libtool executable on the system. Note that Gnuastro also ships
# with a version of Libtool. We don't want Gnuastro's Libtool, here we want
# to see if the system has libtool independent of Gnuastro so BuildProgram
# can use it later. We also need to check some shells to run libtool within
# them.
AC_CHECK_PROG(has_libtool, libtool, [yes], [no])
AC_CHECK_PROG(has_bash, bash, [yes], [no])
AC_CHECK_PROG(has_zsh, zsh, [yes], [no])
# If Libtool is present, make sure it is GNU Libtool
AS_IF([test "x$has_libtool" = "xyes"],
[ AC_MSG_CHECKING(if libtool executable is GNU)
AS_IF( libtool --version 2> /dev/null | grep GNU 2>&1 > /dev/null,
[has_gnulibtool=yes], [has_gnulibtool=no])
AC_MSG_RESULT( $has_gnulibtool )],
[ has_gnulibtool=no ])
# When either the 'libtool' executable isn't GNU or it doesn't exist, then
# look for 'glibtool'.
AS_IF([test "x$has_gnulibtool" = "xyes"],
[ gnulibtool_exec=libtool ],
[ AC_CHECK_PROG(has_glibtool, glibtool, [yes], [no])
AS_IF( [test "x$has_glibtool" = "xyes"],
[has_gnulibtool=yes; gnulibtool_exec=glibtool],
[has_gnulibtool=no; anywarnings=yes] ) ])
# Older versions of GNU Libtool have problems with the 'dash' shell (a
# minimalist shell) and will crash (due to not having the '+=' operator),
# see bug #54430. So we need to check if the system's libtool and shell
# (called by 'sh' as in C's 'system' function within BuildProgram) can work
# with each other. If not, we need to search for Bash and tell BuildProgram
# to use Bash instead of the default. But older versions of Bash also don't
# support this operator, so we'll have to check with Bash is well.
libtool_shell="none"
AS_IF([test "x$has_gnulibtool" = "xyes"],
[
AC_MSG_CHECKING(for shell to use with libtool)
# Make a C source file and run Libtool on it with the specified
# shells.
outname=libtool_shell_test
cprog=libtool_shell_test.c
AS_ECHO(["#include <stdio.h>"]) > $cprog
AS_ECHO(["int main(void){printf(\"success\\n\"); return 0;}"]) >> $cprog
ltargs="--quiet --tag=CC --mode=link $CC $cprog -O3 -o $outname"
# Check the shells, starting with known shells and ultimately
# trying with 'sh' (can be any shell).
AS_IF([test "x$has_bash" = "xyes"],
[AS_IF(bash -c "$gnulibtool_exec $ltargs" > /dev/null 2>&1,
[libtool_shell="bash"],
[bash_version=$BASH_VERSION]) ],
[AS_IF([test "x$has_zsh" = "xyes"],
[AS_IF(zsh -c "$gnulibtool_exec $ltargs" > /dev/null 2>&1,
[libtool_shell="zsh"]) ],
[AS_IF(sh -c "$gnulibtool_exec $ltargs" > /dev/null 2>&1,
[libtool_shell="sh"]) ]) ])
# Clean up: note that no output might have been generated (when no
# proper shell was found). Therefore, for deleting the output file,
# we'll call 'rm' with '-f' so it doesn't complain with an error in
# such cases.
rm $cprog
rm -f $outname
AC_MSG_RESULT($libtool_shell)
])
# If a good shell to call Libtool could be found, then Libtool is usable
# within a program (BuildProgram in this case).
AS_IF([test "x$libtool_shell" = "xnone"],
[
anywarnings=yes;
usable_libtool=no;
AS_IF([test "x$bash_version" = x], [junk=1],
[AS_ECHO(["GNU Bash was found but not a suitable version: $bash_version"]) ])
],
[
usable_libtool=yes
AC_DEFINE_UNQUOTED([GAL_CONFIG_GNULIBTOOL_SHELL], ["$libtool_shell"],
[Shell program to use with GNU Libtool])
AC_DEFINE_UNQUOTED([GAL_CONFIG_GNULIBTOOL_EXEC], ["$gnulibtool_exec"],
[The executable to call GNU Libtool])
])
# Check Ghostscript: "-dPDFFitPage" option to Ghostscript, used by the
# library to convert from EPS to PDF, has been introduced in Ghostscript
# 9.10. Make sure we have at least that version.
#
# Below, only when Ghostscript exists, we check its version and only if its
# version is larger than 9.10, does Gnuastro finally assume the existence
# of Ghostscript. AX_COMPARE_VERSION comes from the GNU Autoconf Archive's
# ax_compare_version.m4.
AC_CHECK_PROG(has_ghostscript, gs, [yes], [no])
AS_IF([test "x$has_ghostscript" = "xyes"],
[AC_MSG_CHECKING(Ghostscript version)
gsversion=$(gs --version)
AX_COMPARE_VERSION([9.10], [gt], [$gsversion], [has_ghostscript=no])
AC_MSG_RESULT( $gsversion )
AC_DEFINE_UNQUOTED([PATH_GHOSTSCRIPT], ["$(which gs)"],
[Location of the host system's Ghostscript binary])
])
# Note: 'has_ghostscript' can be set to 'no' within the AS_IF above, so
# 'anywarnings' cannot be an [RUN-IF-FALSE] argument to the AS_IF above.
AS_IF([test "x$has_ghostscript" = "xno"], [anywarnings=yes])
AM_CONDITIONAL([COND_HASGHOSTSCRIPT], [test "x$has_ghostscript" = "xyes"])
# Check DS9 and TOPCAT
AC_CHECK_PROG(has_ds9, ds9, [yes], [no])
AS_IF([test "x$has_ds9" = "xno"], [anywarnings=yes])
AC_CHECK_PROG(has_topcat, topcat, [yes], [no])
AS_IF([test "x$has_topcat" = "xno"], [anywarnings=yes])
# Check Python3 and NumPy (in that order): and gets their include path if
# they do. This is done using two python scripts:
# py_check_cmd: Uses the sysconfig package's get_paths method
# to get the include path for Python.h header.
# np_check_cmd: Uses numpy's get_include method to get the
# include path for NumPy's core C-API.
#
# NOTE: If using a venv then set the $PYTHON variable to point to the
# python3 command of the venv before running ./configure to perform
# all the following checks in the venv.
AC_ARG_WITH([python],
[AS_HELP_STRING([--with-python],
[enable support for python])],
[], [with_python=no])
AS_IF([test "x$with_python" == xyes],
[
# Variables to simplify commands below.
py_check_cmd='from sysconfig import get_paths; \
print(get_paths().get("include"))'
np_check_cmd='from numpy import get_include; \
print(get_include())'
# Checks if user has a Python version>=3.0
AM_PATH_PYTHON(3.0,,[:])
AS_IF([test "$PYTHON" != :],
[
AC_DEFINE(HAVE_PYTHON, [1],
[Define to 1 if you have Python3.])
AC_MSG_CHECKING(if Numpy is available in the $PYTHON installation)
AS_IF([$PYTHON -c "$py_check_cmd" &> /dev/null],
[python_includedir="$($PYTHON -c "$py_check_cmd")"
AS_IF([$PYTHON -c "$np_check_cmd" &> /dev/null],
[numpy_includedir="$($PYTHON -c "$np_check_cmd")"])])
AS_IF([test "x$numpy_includedir" = x],
[AC_MSG_RESULT([no])], [AC_MSG_RESULT([yes])])
])
AC_SUBST(NUMPY_INCLUDE_DIR, [$numpy_includedir])
AC_SUBST(PYTHON_INCLUDE_DIR, [$python_includedir])
])
AS_IF([test "x$numpy_includedir" = x],
[has_numpy=0], [has_numpy=1;])
AC_SUBST(HAVE_PYTHON, [$has_numpy])
AM_CONDITIONAL([COND_NUMPY], [test "x$numpy_includedir" != x])
# If any necessary dependency is missing inform the user and abort.
AS_IF([test "x$missing_mandatory" = "xyes"],
[
# List missing packages: print the GSL CBLAS message only if GSL is
# present. Otherwise, it is just confusing for the users (CBLAS
# will be installed with GSL). The CBLAS message is only
# interesting if the GSL test has passed.
AS_ECHO([""])
AS_ECHO(["Missing MANDATORY dependencies (necessary to continue):"])
AS_IF([test "x$has_cmath" = "xno"],
[ AS_ECHO([" - C library (math): This may be the cause of all other failures."]) ])
AS_IF([test "x$has_gsl" = "xno"],
[ AS_ECHO([" - GNU Scientific Library (GSL): https://www.gnu.org/software/gsl"]) ],
[ AS_IF([test "x$has_gslcblas" = "xno"],
[ AS_ECHO([" - The BLAS support of GNU Scientific Library (GSL). This should have"])
AS_ECHO([" been installed along with GSL. Try re-installing GSL."]) ]) ])
AS_IF([test "x$has_cfitsio" = "xno"],
[ AS_ECHO([" - CFITSIO: https://heasarc.gsfc.nasa.gov/fitsio"]) ])
AS_IF([test "x$has_wcslib" = "xno"],
[ AS_ECHO([" - WCSLIB: http://www.atnf.csiro.au/people/mcalabre/WCS"]) ])
# Optional dependencies:
AS_IF([test "x$anywarnings" = xyes],
[
AS_ECHO([""])
AS_ECHO(["OPTIONAL warnings/dependencies (for improved functionality):"])
AS_IF([test "x$gsl_version_old" = "xyes"],
[ AS_ECHO([" - Old GSL version: https://www.gnu.org/s/gsl"]) ])
AS_IF([test "x$has_libjpeg" = "xno"],
[ AS_ECHO([" - Missing Libjpeg (JPEG files): http://ijg.org"]) ])
AS_IF([test "x$has_libtiff" = "xno"],
[ AS_ECHO([" - Missing Libtiff (TIFF files): http://libtiff.maptools.org"]) ])
AS_IF([test "x$has_libgit2" = "x0"],
[ AS_ECHO([" - Missing Libgit2: https://libgit2.org"]) ])
AS_IF([test "x$has_curl" = "x0"],
[ AS_ECHO([" - Missing cURL: https://curl.haxx.se"]) ])
dnl AS_IF([test "x$has_numpy" = "x0"],
dnl [ AS_ECHO([" - Missing Numpy (for Python wrappers): https://numpy.org"]) ])
AS_IF([test "x$has_ds9" = "xno"],
[ AS_ECHO([" - Missing SAO DS9: https://sites.google.com/cfa.harvard.edu/saoimageds9"]) ])
AS_IF([test "x$has_topcat" = "xno"],
[ AS_ECHO([" - Missing TOPCAT: http://www.star.bris.ac.uk/~mbt/topcat/"]) ])
AS_IF([test "x$usable_libtool" = "xno"],
[ AS_ECHO([" - Unusable GNU Libtool: https://www.gnu.org/s/libtool"])
AS_IF([test "x$has_gnulibtool" = "xyes"],
[ AS_ECHO([" -- GNU Libtool is present, tested shells not supported."]) ])
AS_IF([test "x$has_libtool" = "xyes"],
[ AS_ECHO([" -- A libtool implementation was found, but it isn't GNU."]) ])
])
AS_IF([test "x$has_ghostscript" = "xno"],
[ AS_ECHO([" - Missing GPL Ghostscript (v9.10 or later): https://www.ghostscript.com"])])
])
# Suggestions on fixing the problem.
AS_ECHO([""])
AS_ECHO(["You can use your package manager for easy and fast installation of all"])
AS_ECHO(["dependencies in one command. See the link below:"])
AS_ECHO([" https://www.gnu.org/s/gnuastro/manual/html_node/Dependencies-from-package-managers.html"])
AS_ECHO([""])
AS_ECHO(["If you have already installed a dependency (for example in '/install/path'),"])
AS_ECHO(["but this script can't link with it, add the path to the LDFLAGS, CPPFLAGS and"])
AS_ECHO(["LD_LIBRARY_PATH environment variables before running configure. For example"])
AS_ECHO(["with the following commands (just correct the '/install/path' part)."])
AS_ECHO([" $ export LDFLAGS=\"\$LDFLAGS -L/install/path/lib\""])
AS_ECHO([" $ export CPPFLAGS=\"\$CPPFLAGS -I/install/path/include\""])
AS_ECHO([" $ export LD_LIBRARY_PATH=\"\$LD_LIBRARY_PATH:/install/path/lib\""])
AS_ECHO([""])
AS_ECHO(["[TIP:] Put these commands in your startup file (for example '~/.bashrc') to"])
AS_ECHO(["avoid similar problems later. See the link below to learn more:"])
AS_ECHO([" https://www.gnu.org/s/gnuastro/manual/html_node/Installation-directory.html"])
AS_ECHO([""])
AS_ECHO([""])
AC_MSG_ERROR([Mandatory dependency(s) missing, === SEE MESSAGE ABOVE ===.])
])
# Gnulib checks (which are many!). We are doing these after the main
# Gnuastro dependencies so the configure script crashes early if the
# mandatory dependencies aren't present. However, the Gnulib checks are
# very low-level, and the changes in envornment that we made above (in
# particular 'LIBS') can cause conflicts with Gnulib's checks (in
# particular with WCSLIB, because on some systems, WCSLIB's library name:
# 'libwcs' can cause conflicts with the standard wide-character-string
# library: 'libwcs').
new_LIBS="$LIBS"
LIBS="$orig_LIBS"
gl_INIT
LIBS="$new_LIBS"
# Check if Gnulib tests should be done:
AC_ARG_ENABLE([gnulibcheck],
[AS_HELP_STRING([--enable-gnulibcheck],
[In 'make check', also test GNU Gnulib.])],
[enable_gnulibcheck=yes], [enable_gnulibcheck=no])
AM_CONDITIONAL([COND_GNULIBCHECK], [test $enable_gnulibcheck = yes])
# Gnulib checks for the proper name for the C99 equivalent 'restrict'
# keyword and puts it in the 'ac_cv_c_restrict' variable. If none exists,
# it will put a 'no' inside of this variable. As described in the output
# 'bootstrapped/m4/gnulib-common.m4', this is only necessary until Autoconf
# 2.70 is released. Afterwards, we can use AC_C_RESTRICT.
AS_IF([test "x$ac_cv_c_restrict" = "xno"],
[gal_restrict_replace=], [gal_restrict_replace=$ac_cv_c_restrict])
AC_SUBST(RESTRICT_REPLACEMENT, [$gal_restrict_replace])
# Set the one general parameters:
AC_DEFINE_UNQUOTED([CONF_POSTFIX], [".conf"], [Configuration file post fix.])
AC_DEFINE_UNQUOTED([USERCONFIG_DIR], [".local/etc/gnuastro"], [User data dir.])
AC_DEFINE_UNQUOTED([CONF_SHOWFMT], [" %-20s"],
[Configuration file name format.])
# Read arguments about which programs to install. After checking if
# the argument was actually called, remove any value the user might
# have given by setting them to "yes" if they are not "no". These
# options don't accept arguments.
ayes=false
AC_ARG_ENABLE([arithmetic],
[AS_HELP_STRING([--enable-arithmetic],
[Install Arithmetic and other enabled programs.])],
[AS_IF([test "x$enable_arithmetic" != xno],
[enable_arithmetic=yes; ayes=true])],
[enable_arithmetic=notset])
AC_ARG_ENABLE([buildprog],
[AS_HELP_STRING([--enable-buildprog],
[Install BuildProgram and other enabled programs.])],
[AS_IF([test "x$enable_buildprog" != xno],
[enable_buildprog=yes; ayes=true])],
[enable_buildprog=notset])
AC_ARG_ENABLE([convertt],
[AS_HELP_STRING([--enable-convertt],
[Install ConvertType and other enabled programs.])],
[AS_IF([test "x$enable_convertt" != xno],
[enable_convertt=yes; ayes=true])],
[enable_convertt=notset])
AC_ARG_ENABLE([convolve],
[AS_HELP_STRING([--enable-convolve],
[Install Convolve and other enabled programs.])],
[AS_IF([test "x$enable_convolve" != xno],
[enable_cognvolve=yes; ayes=true])],
[enable_convolve=notset])
AC_ARG_ENABLE([cosmiccal],
[AS_HELP_STRING([--enable-cosmiccal],
[Install CosmicCalculator and other enabled programs.])],
[AS_IF([test "x$enable_cosmiccal" != xno],
[enable_cosmiccal=yes; ayes=true])],
[enable_cosmiccal=notset])
AC_ARG_ENABLE([crop],
[AS_HELP_STRING([--enable-crop],
[Install Crop and other enabled programs.])],
[AS_IF([test "x$enable_crop" != xno],
[enable_crop=yes; ayes=true])],
[enable_crop=notset])
AC_ARG_ENABLE([fits],
[AS_HELP_STRING([--enable-fits],
[Install Fits and other enabled programs.])],
[AS_IF([test "x$enable_fits" != xno],
[enable_fits=yes; ayes=true])],
[enable_fits=notset])
AC_ARG_ENABLE([match],
[AS_HELP_STRING([--enable-match],
[Install Match and other enabled programs.])],
[AS_IF([test "x$enable_match" != xno],
[enable_match=yes; ayes=true])],
[enable_match=notset])
AC_ARG_ENABLE([mkcatalog],
[AS_HELP_STRING([--enable-mkcatalog],
[Install MakeCatalog and other enabled programs.])],
[AS_IF([test "x$enable_mkcatalog" != xno],
[enable_mkcatalog=yes; ayes=true])],
[enable_mkcatalog=notset])
AC_ARG_ENABLE([mkprof],
[AS_HELP_STRING([--enable-mkprof],