-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathconfigure.ac
3383 lines (2701 loc) · 104 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
############################# MPC License ##############################
# Wed Nov 19 15:19:19 CET 2008 #
# Copyright or (C) or Copr. Commissariat a l'Energie Atomique #
# #
# IDDN.FR.001.230040.000.S.P.2007.000.10000 #
# This file is part of the MPC Runtime. #
# #
# This software is governed by the CeCILL-C license under French law #
# and abiding by the rules of distribution of free software. You can #
# use, modify and/ or redistribute the software under the terms of #
# the CeCILL-C license as circulated by CEA, CNRS and INRIA at the #
# following URL http://www.cecill.info. #
# #
# The fact that you are presently reading this means that you have #
# had knowledge of the CeCILL-C license and that you accept its #
# terms. #
# #
# Authors: #
# - CARRIBAULT Patrick [email protected] #
# - PERACHE Marc [email protected] #
# - JAEGER Julien [email protected] #
# #
########################################################################
#####################################################################
#### TABLE OF CONTENTS ####
#####################################################################
# This configure.ac is organized as follows:
#(you may use tags below to reach the proper section directly)
#
# - {sec:setup}: GENERAL INITIALIZATION
# - {sec:globals}: GLOBAL INFORMATION
# - {sec:version}: BUILD VERSION IDENTIFICATION
# - {sec:checks}: CHECKS BEFORE BUILD, including
# - {sec:arch}: ARCHITECTURE
# - {sec:programs} : EXTERNAL PROGRAMS
# - {sec:headers}: EXTERNAL HEADERS
# - {sec:libraries}: EXTERNAL LIBRARIES
# - {sec:datatypes}: DATA TYPES
# - {sec:funcs}: STANDARD FUNCTIONS
# - {sec:deps}: LOOKING FOR DEPENDENCIES, including...
# - {sec:pthread}: PThread API checks
# - {sec:modular}: MPC MODULAR CONFIGURATION
# - {sec:compiler}: COMPILERS IDENTIFICATION
# - {sec:finalize}: FINALIZATION & SUMMARY
#
#####################################################################
####################################
###### GENERAL INITIALIZATION ###### {sec:setup}
####################################
#Autoconf initialization w/ project name, version, bug report email, package name & website
AC_INIT([Multi-Processor Computing Framework],
[m4_esyscmd_s([./utils/get_version])],
[[email protected]], [mpcframework], [https://mpc.hpcframework.com])
# The first check is that the configure was generated with
# autogen.sh and not manually for example with autoconf
# it is crucial to ensure that configuration patches (located in ./config/conf_patches/)
# are applied before running the configure script for a patch
# description see the end of the autogen.sh file
GENERATED_WITH_AUTOGEN=$(tail -n 1 "$0" | grep -c "MPC_AUTOGEN_WAS_USED")
if test "x${GENERATED_WITH_AUTOGEN}" = "x0"; then
AC_MSG_ERROR([The configure script was not generated using autogen.sh])
fi
#Some basic setups: where build configuration/macro files are stored
#and check for source directory properly found
AC_CONFIG_AUX_DIR([config])
AC_CONFIG_MACRO_DIRS([config/m4])
AC_CONFIG_SRCDIR([src/MPC_Arch/src/timer.c])
# Language is C-based (init compilers properly)
AC_LANG(C)
# Pre-required maintainer tool to rebuild.
# Enforcing this ensure mimnimum changes to
# generated files under version control
AC_PREREQ(2.69)
# two first arguments are omitted: PACKAGE & VERSION (infered from AC_INIT)
# subdir-objects: any source file will map with a corresponding object file under same subtree from builddir
# foreign: not conformant with GNU standard strictness
# no-define: do not subst PACKAGE & VERSION (inferred from AC_INIT)
# std-options: Check any installed script provides a '--help' and '--version'
# no-dist: do not distribute the project through "make dist", MPC more complex than what provided
AM_INIT_AUTOMAKE([1.15 subdir-objects foreign no-define std-options])
# Avoid Makefile to print commands before running it
# Overriden by configure: --disable-silent-rules
# overriden by make: make V=1
AM_SILENT_RULES([yes])
# Editing the build system (new directory, source file, changes in *.am/*.ac)
# leads to regenerate the configuration. To do so, run "./autogen.sh" script.
# by using `--enable-maintainer-mode` as configure option, a change in build files
# will automatically trigger a new configuration (not working properly for now)
AM_MAINTAINER_MODE([disable])
#libtool initialization
LT_PREREQ([2.4.6])
LT_INIT([disable-static])
LT_LANG([C])
# TODO:
# Reload first configure environment if present
# this is needed as we want all the variables
# set by the root configure script (or first configure)
# to be present as we rerun this configure
#
MPC_CONFIG_RELOADED="no"
if test -f ${PWD}/bin/mpc_build_env.sh; then
MPC_CONFIG_RELOADED="yes"
. ${PWD}/bin/mpc_build_env.sh
fi
################################
###### GLOBAL INFORMATION ###### {sec:globals}
################################
if test "x${prefix}" = "xNONE"; then
AC_MSG_WARN([No prefix was passed will use /usr/local/])
prefix="/usr/local/"
fi
# installation prefix, defined for the whole build
AC_DEFINE_UNQUOTED([MPC_PREFIX_PATH], ["$prefix"], [Prefix Path for MPC])
#static list of supported architecture (to be expanded)
MPC_SUPPORTED_ARCHITECTURES_LIST="x86_64 ia64 i686 arm aarch64 powerpc64"
# General Configuration path
CONFIGURE_SCRIPT_PATH=$(dirname "`readlink -f "$0"`")
# Proceed to prefix checks
# Note that we used to prevent reinstall but it led to several overheads
# for user we then propose to leave the warning but let the code go without
# complaining. In particular this allows maintainer-mode to work cleanly
# and it also allows direct reconfiguring (with the ./reconfigure scrip
# generated in the buildir). This is then a tradeoff, changing MPC's
# configuration is sill a possible souce of error.
if test -f "${prefix}/bin/mpc_status"; then
AC_MSG_NOTICE([!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!])
AC_MSG_NOTICE([There seems to be a previous install of MPC in ${prefix}.])
AC_MSG_NOTICE([Reinstalling over it can lead to spurious errors if configuration changed.])
AC_MSG_NOTICE([It is recommended to remove MPC beforehand to avoid conflicts.])
AC_MSG_NOTICE([PROCEED at your OWN RISKS !!])
AC_MSG_NOTICE([!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!])
AC_MSG_WARN([You have 5 seconds to abort.])
sleep 5
fi
####################################
###### VERSION IDENTIFICATION ###### {sec:version}
####################################
#Create environment vars
#
# Compute version
#
MPC_VERSION_MAJOR="$($CONFIGURE_SCRIPT_PATH/utils/get_version --major)"
MPC_VERSION_MINOR="$($CONFIGURE_SCRIPT_PATH/utils/get_version --minor)"
MPC_VERSION_PATCH="$($CONFIGURE_SCRIPT_PATH/utils/get_version --patch)"
MPC_VERSION_TAINT="$($CONFIGURE_SCRIPT_PATH/utils/get_version --taint)"
MPC_VERSION_STRING="$($CONFIGURE_SCRIPT_PATH/utils/get_version --all)"
# define macros in mpc_config.h for proper use from sources
AC_DEFINE_UNQUOTED([MPC_VERSION_MAJOR], [$MPC_VERSION_MAJOR], [MPC Major Version])
AC_DEFINE_UNQUOTED([MPC_VERSION_MINOR], [$MPC_VERSION_MINOR], [MPC Minor Version])
AC_DEFINE_UNQUOTED([MPC_VERSION_PATCH], [$MPC_VERSION_PATCH], [MPC Patch Version])
AC_DEFINE_UNQUOTED([MPC_VERSION_PRE], ["$MPC_VERSION_TAINT"], [MPC Tainted Version])
AC_DEFINE_UNQUOTED([MPC_VERSION_STRING], ["$MPC_VERSION_STRING"], [MPC Tainted Version])
#Substitute any @MPC_VERSION_*@ in *.in files
AC_SUBST([MPC_VERSION_MAJOR])
AC_SUBST([MPC_VERSION_MINOR])
AC_SUBST([MPC_VERSION_PATCH])
AC_SUBST([MPC_VERSION_PRE])
AC_SUBST([MPC_VERSION_STRING])
#################################
###### CHECKS BEFORE BUILD ###### {sec:checks}
#################################
#### ARCHITECTURE #### {sec:arch}
######################
AC_CANONICAL_HOST
MPC_TARGET_ARCHITECTURE="$host_cpu"
# Check if architecture is in support list
AC_MSG_CHECKING([Support for target architecture])
if test -z "${MPC_SUPPORTED_ARCHITECTURES_LIST##*$MPC_TARGET_ARCHITECTURE*}" ; then
AC_MSG_RESULT([$MPC_TARGET_ARCHITECTURE])
AC_SUBST([MPC_TARGET_ARCHITECTURE])
else
AC_MSG_RESULT([No])
AC_MSG_ERROR([Current architecture is not supported yet. Please contact support team])
fi
#### EXTERNAL PROGRAMS #### {sec:programs}
###########################
AC_PROG_CC([gcc apcc icc pgcc clang])
AC_PROG_CXX([g++ ap++ icpc pg++ pgcpp clan++])
AC_PROG_FC([gfortran apfortran ifort pgfortran pgf77 flang])
AC_PROG_INSTALL
AM_PROG_AS
AC_PROG_LN_S
AC_PROG_MKDIR_P
AM_PATH_PYTHON([],[HAVE_PYTHON="yes"],[HAVE_PYTHON="no"])
if test "x${HAVE_PYTHON}" = "xyes"; then
AX_PYTHON_MODULE([json])
AX_PYTHON_MODULE([argparse])
fi
AM_CONDITIONAL([HAVE_PYTHON], [test "x$HAVE_PYTHON" = "xyes" -a "x${HAVE_PYMOD_JSON}" = "xyes" -a "x${HAVE_PYMOD_ARGPARSE}" = "xyes"])
AC_SUBST([PYTHON], [$PYTHON])
# Optional Pandoc Generator (dynamically regen manpages
AC_PATH_PROG([PANDOC],[pandoc],[:])
AM_CONDITIONAL([CAN_USE_PANDOC], [test "x$PANDOC" != "x:"])
#### EXTERNAL HEADERS #### {sec:headers}
##########################
AC_HEADER_STDC
AC_CHECK_HEADER_STDBOOL
AC_CHECK_HEADERS([ aio.h \
asm/unistd.h \
assert.h \
ctype.h \
errno.h \
execinfo.h \
elf.h \
fcntl.h \
getopt.h \
hwloc.h \
immintrin.h \
limits.h \
linux/personality.h \
netdb.h \
netinet/in.h \
netinet/tcp.h \
pthread.h \
regex.h \
sched.h \
semaphore.h \
setjmp.h \
signal.h \
stddef.h \
stdlib.h \
stdint.h \
stdbool.h \
string.h \
sys/mman.h \
sys/param.h \
sys/pstat.h \
sys/socket.h \
sys/stat.h \
sys/syscall.h \
sys/time.h \
sys/types.h \
sys/ucontext.h \
sys/un.h \
sys/utsname.h \
sys/wait.h \
time.h \
ucontext.h \
unistd.h \
wchar.h \
valgrind/memcheck.h \
valgrind/valgrind.h \
])
#### EXTERNAL LIBRARIES #### {sec:libraries}
############################
AC_CHECK_LIB([m],[log])
AC_CHECK_LIB(pthread, pthread_create)
AC_CHECK_SIZEOF(pthread_t,,[#include <pthread.h>])
#### DATATYPES #### {sec:datatypes}
###################
# Configure subtitutions for mpc_common_types.h
AC_CHECK_HEADER([stdbool.h],[HAVE_STDBOOL_H=1],[HAVE_STDBOOL_H=0])
AC_SUBST([HAVE_STDBOOL_H], [$HAVE_STDBOOL_H])
AC_CHECK_HEADER([stdint.h],[HAVE_STDINT_H=1],[HAVE_STDINT_H=0])
AC_SUBST([HAVE_STDINT_H], [$HAVE_STDINT_H])
AC_CHECK_HEADER([wchar.h],[HAVE_WCHAR_H=1],[HAVE_WCHAR_H=0])
AC_SUBST([HAVE_WCHAR_H], [$HAVE_WCHAR_H])
# Configure substitutions for mpc_thread_config.h
AC_CHECK_HEADER([semaphore.h],[HAVE_SEMAPHORE_H=1],[HAVE_SEMAPHORE_H=0])
AC_SUBST([HAVE_SEMAPHORE_H], [$HAVE_SEMAPHORE_H])
AC_CHECK_HEADER([pthread.h],[HAVE_PTHREAD_H=1],[HAVE_PTHREAD_H=0])
AC_SUBST([HAVE_PTHREAD_H], [$HAVE_PTHREAD_H])
AC_C_INLINE
AC_TYPE_INT16_T
AC_TYPE_INT32_T
AC_TYPE_INT64_T
AC_TYPE_INT8_T
AC_TYPE_OFF_T
AC_C_RESTRICT
AC_TYPE_SIZE_T
AC_TYPE_SSIZE_T
AC_TYPE_UINT16_T
AC_TYPE_UINT32_T
AC_TYPE_UINT64_T
AC_TYPE_UINT8_T
AC_CHECK_TYPES([ptrdiff_t])
AC_CHECK_TYPES([__float128])
AX_GCC_BUILTIN([__builtin_return_address])
AX_GCC_BUILTIN([__builtin_frame_address])
AX_GCC_BUILTIN([__builtin_expect])
if test "x${ax_cv_have___builtin_expect}" = "xyes"; then
HAVE_BUILTIN_EXPECT=1
else
HAVE_BUILTIN_EXPECT=0
fi
AC_SUBST([HAVE_BUILTIN_EXPECT])
AC_C_CONST
AC_C_RESTRICT
AC_C_VOLATILE
AC_C_INLINE
# Check for regular TLS support
AX_TLS([AC_DEFINE([TLS_SUPPORT], [1], [TLS extension supported by compiler])],
[AC_DEFINE([TLS_SUPPORT], [0], [TLS extension NOT supported by compiler])])
AC_CHECK_SIZEOF(char)
AC_CHECK_SIZEOF(short)
AC_CHECK_SIZEOF(int)
AC_CHECK_SIZEOF(float)
AC_CHECK_SIZEOF(long)
AC_SUBST([SIZEOF_LONG], [$ac_cv_sizeof_long])
AC_CHECK_SIZEOF(double)
AC_CHECK_SIZEOF(size_t)
AC_CHECK_SIZEOF(void*)
AC_CHECK_SIZEOF(long long)
#### EXTERNAL FUNCTIONS #### {sec:funcs}
############################
AC_FUNC_FORK
AC_FUNC_MALLOC
AC_FUNC_MMAP
AC_FUNC_REALLOC
AC_CHECK_FUNCS([memcpy memmove memset statfs])
AC_CHECK_FUNCS([strcasecmp strchr strdup strerror strstr strtol snprintf vsnprintf])
AC_CHECK_FUNCS([gethostbyname gethostname])
AC_CHECK_FUNCS([gettimeofday])
AC_CHECK_FUNCS([mmap mremap munmap posix_memalign memalign])
AC_CHECK_FUNCS([setenv getenv])
AC_CHECK_FUNCS([uname])
AC_CHECK_FUNCS([regcomp])
AC_CHECK_FUNCS([socket connect accept])
AC_CHECK_FUNCS([dup2 fdatasync])
AC_CHECK_FUNCS([makecontext setcontext getcontext swapcontext])
AC_CHECK_SIZEOF(sigset_t,,[#include <signal.h>])
######################################
###### LOOKING FOR DEPENDENCIES ###### {sec:deps}
######################################
# Rpath helper
#
# $1: LDFLAGS to inspect
#
promote_to_rpath()
{
# In MPC in order to fortify link/runtime dependencies
# we prefer to add rpath as much as possible to be
# more independent from the build env (closer to static build)
# the role of this helper is to look for libdirs and
# add them as rpaths (if not already present)
# Remove space in GCC's library search path args
CURRENT_RPATH=""
# Extract existing RPATH
for arg in $@
do
if echo "$arg" | grep "^\\-Wl,\\-rpath=" > /dev/null; then
# Ensure path exists
RPATH=$(echo "$arg" | sed s/^-Wl,-rpath=//g)
if test -d "${RPATH}"; then
CURRENT_RPATH="${CURRENT_RPATH}:$RPATH"
fi
fi
done
NEW_RPATH=""
# Extract -L args
for arg in $@
do
if echo "$arg" | grep "^-L" > /dev/null; then
arg=$(echo "$arg" | sed "s/-L /-L/g")
# Ensure path exists
LPATH=$(echo "$arg" | sed s/^-L//g)
if test -d "${LPATH}"; then
CNT=$(echo "$CURRENT_RPATH" | grep -c "${LPATH}")
#If path not in rpath then emit it
if test "x${CNT}" = "x0"; then
NEW_RPATH="${NEW_RPATH} -Wl,-rpath=${LPATH}"
fi
fi
fi
done
echo "$NEW_RPATH $@"
}
# Library detector helper
prefix_candidate_path="/usr /usr/local /opt"
prefix_candidate_sub_include_path=". include include/slurm include/slurm-wml"
#
# $1 header name
# $2 provided prefix
#
# Sets check_or_infer_prefix_include or returns ""
#
__check_or_infer_prefix_include()
{
check_or_infer_prefix_include="no"
looked_up_header=$1
provided_prefix=$2
var_prefix=$3
AC_CHECK_HEADER([$looked_up_header],[hfound=yes],[hfound=no])
if test "x$hfound" = "xyes"; then
check_or_infer_prefix_include=yes
return
fi
AC_MSG_NOTICE([Checking for $1 header manually in different places])
for pref in $provided_prefix $prefix_candidate_path
do
for suffix in $prefix_candidate_sub_include_path
do
#AC_MSG_CHECKING([for '$looked_up_header' in '$pref/$suffix'])
if test -f "$pref/$suffix/$looked_up_header"
then
#AC_MSG_RESULT([yes])
# Set include path for matched header
CPPFLAGS+=" -I$pref/$suffix/"
AX_RESET_HEADERS_CACHE([$looked_up_header])
AC_CHECK_HEADER([$looked_up_header],[],[AC_MSG_ERROR([Failed to autodetect '$looked_up_header' in '$pref/$suffix'])])
check_or_infer_prefix_include=yes
AC_MSG_NOTICE(['$1' found in $pref/$suffix])
return
fi
done
done
}
prefix_candidate_sub_lib_path=". lib lib64"
#
# libname
#
___unset_lib_cache()
{
cache_vars=$(set | cut -d "=" -f 1 | grep ac_cv_lib | sed "s/'//g")
for i in $cache_vars
do
AS_UNSET([$i])
done
}
#
# $1 lib name
# $2 lib function name
# $3 provided prefix
#
# Sets check_or_infer_prefix_include or returns ""
#
__check_or_infer_prefix_lib()
{
check_or_infer_prefix_lib="no"
looked_up_lib=$1
looked_up_function=$2
provided_prefix=$3
var_prefix=$4
AC_CHECK_LIB($looked_up_lib, $looked_up_function, [lib_found=1], [lib_found=0])
if test "x$lib_found" = "x1"
then
LDFLAGS=" -l$1 $LDFLAGS"
check_or_infer_prefix_lib=yes
return
fi
AC_MSG_NOTICE([Checking for '$looked_up_lib' library in different places])
for pref in $provided_prefix $prefix_candidate_path
do
for suffix in $prefix_candidate_sub_lib_path
do
lib_found=0
AC_MSG_NOTICE("Looking in $pref/$suffix/")
OLD_LDFLAGS=$LDFLAGS
LDFLAGS=$(promote_to_rpath " -L$pref/$suffix/ -Wl,-rpath=$pref/$suffix/ -l$1 $LDFLAGS")
___unset_lib_cache
AC_CHECK_LIB($looked_up_lib, $looked_up_function, [lib_found=1], [lib_found=0])
if test "x$lib_found" = "x1"
then
AC_MSG_NOTICE(['$looked_up_lib' found in $pref/$suffix])
check_or_infer_prefix_lib=yes
return
fi
LDFLAGS=$OLD_LDFLAGS
done
done
}
# Get the value from a define
# $1 Header to inspect
# $2 Define to extract
# $3 can fail
#
extract_integer_define_value()
{
can_fail="$3"
if test -z "$can_fail"; then
can_fail="yes"
fi
AC_MSG_CHECKING([$2 existence])
MACRO_VALUE=""
AC_RUN_IFELSE(
[AC_LANG_PROGRAM([#include <$1>
#include <stdio.h>],
[
long long int val = $2;
FILE *out = fopen("./conftest.out", "w");
if(!out)
return 1;
fprintf(out, "%lld\n", val);
fclose(out);
])],
[MACRO_VALUE="`cat conftest.out`"],
[MACRO_VALUE=""])
if test -z "$MACRO_VALUE"; then
if test "x$can_fail" = "xyes"; then
AC_MSG_FAILURE([Failed to lookup for $2 in $1])
else
AC_MSG_RESULT([not found])
fi
else
AC_MSG_RESULT([$MACRO_VALUE ($1)])
fi
}
# Add a pkg-config search path if not already here
# $1 : search path to add
#
append_to_pkg_config_if_needed()
{
TSOURCE=$(echo "$1" | xargs)
for p in $(echo "$PKG_CONFIG_PATH" | sed "s/:/ /g")
do
TPATH=$(echo "$p" | xargs)
if test "x${TSOURCE}" = "x${TPATH}"; then
return
fi
done
AC_MSG_NOTICE([${TSOURCE} prepended to pkg-config search paths])
export PKG_CONFIG_PATH=${TSOURCE}:$PKG_CONFIG_PATH
}
# Get a var from PKG-CONFIG
#
# $1: pkg-name
# $2: var name
#
# echos content if found "" if not
#
#
__get_pkg_config_var()
{
VARS=$(pkg-config --print-variables "$1" 2>/dev/null)
# Command worked
if test "$?" = "0"; then
# Make sure var is known
if echo "$VARS" | grep "$2" > /dev/null 2>&1 ; then
# Get var content
DATA=$(pkg-config --variable="$2" "$1" 2>/dev/null)
if test "$?" = "0"; then
echo "$DATA"
fi
fi
fi
}
#
# Add a given path arg if not present yet
#
# $1 : Args (-L / -I)
# $2 : PATH to add
# $3 : existing flags
#
#
__append_if_not_here()
{
if test -z "${2}"; then
return
fi
if echo "$3" | grep "$2" > /dev/null 2>&1 ; then
echo "$3"
else
echo "${3} ${1}${2}"
fi
}
# Ensure -L are present for faulty pkg-config files
#
# $1 : pkg-name
# $2 : LDFLAGS (single string)
#
#
extract_pkg_config_lib_prefixes()
{
PLDFLAGS="$2"
# Do we have a libdir var ?
PLIBD=$(__get_pkg_config_var "$1" libdir)
if test -d "$PLIBD"; then
# LIBDIR EXISTS
RET=$(__append_if_not_here "-L" "$PLIBD" "$PLDFLAGS")
# On some debian systems PMIX is installed in a subdir of libdir
# This is a special case we handle here
if test "$1" = "pmix"; then
if test -d "${PLIBD}/pmix2/lib/"; then
RET=$(__append_if_not_here "-L" "${PLIBD}/pmix2/lib/" "$RET")
fi
fi
echo "$RET"
# DONE
return
fi
# Do we have a pcfiledir var ?
PCDIR=$(__get_pkg_config_var "$1" pcfiledir)
if test -n "$PCDIR"; then
if test -d "${PCDIR}/../"; then
# LIBDIR EXISTS
RET=$(__append_if_not_here "-L" "${PCDIR}/../" "$PLDFLAGS")
echo "$RET"
# DONE
return
fi
fi
# Nothing to add
echo "$PLDFLAGS"
}
# Ensure -I are present for faulty pkg-config files
#
# $1 : pkg-name
# $2 : CFLAGS (single string)
#
#
extract_pkg_config_inc_prefixes()
{
PCFLAGS="$2"
# Do we have an includedir var ?
PINCD=$(__get_pkg_config_var "$1" includedir)
if test -d "$PINCD"; then
# INCIDR EXISTS
RET=$(__append_if_not_here "-I" "$PINCD" "$PCFLAGS")
# On some debian systems PMIX is installed in a subdir of libdir
# This is a special case we handle here
if test "$1" = "pmix"; then
PLIBD=$(__get_pkg_config_var "$1" libdir)
if test -n "$PLIBD"; then
if test -d "${PLIBD}/pmix2/include/"; then
RET=$(__append_if_not_here "-I" "${PLIBD}/pmix2/include/" "$RET")
fi
fi
fi
echo "$RET"
# DONE
return
fi
# Do we have a pcfiledir var ?
PCDIR=$(__get_pkg_config_var "$1" pcfiledir)
if test -n "$PCDIR"; then
if test -d "${PCDIR}/../../include/"; then
# PCDIR EXISTS
RET=$(__append_if_not_here "-I" "${PCDIR}/../../include/" "$PCFLAGS")
echo "$RET"
# DONE
return
fi
fi
# Nothing to add
echo "$PCFLAGS"
}
ALL_LIBS_CONFIGURATION=""
#
# $1 : package name
# $2 : CFLAGS
# $3 : LDFLAGS
add_to_lib_configuration()
{
LIBS_LIST_WITH_PATHS="${LIBS_LIST_WITH_PATHS}\n# $libname"
LIBS_LIST_WITH_PATHS="${LIBS_LIST_WITH_PATHS} $(for((i=0;$i<21-$(echo -n $libname | wc -m);i++));do printf "%s" ".";done;)"
LIBS_LIST_WITH_PATHS="${LIBS_LIST_WITH_PATHS} $XXCFLAGS $XXLIB"
TO_ADD=""
if test -n "$2"; then
TO_ADD="# $1 FLAGS $(for((i=0;$i<21-7-$(echo -n $libname | wc -m);i++));do printf "%s" ".";done;) $2 $3"
fi
if test -n "${TO_ADD}"; then
ALL_LIBS_CONFIGURATION=$(
cat << EOF
$ALL_LIBS_CONFIGURATION
${TO_ADD}
EOF
)
fi
}
LIBS_LIST_WITH_PATHS=""
#
# $1 header_name (ex. hwloc.h)
# $2 libname (ex. hwloc)
# $3 looked up function (ex. hwloc_topology_init)
# $4 LIBCODE (ex XML, HWLOC, ...)
# $5 optionnal library version (need pkg-config)
# $6 optionnal lib_prefix
# $7 optionnal alternative lib name (when different from pkg_config)
#
AC_DEFUN([MPC_DETECT_DEPENDENCY],
[
AS_VAR_PUSHDEF([dep_found], [mpc_dep_found])
AC_ARG_WITH([$2],
[AS_HELP_STRING([--with-$2],
[Provide prefix for $2])],
[whole_prefix=$withval],[whole_prefix="/usr/"])
# As spack may export paths inside the env (e.g. CPATH)
# pkg-config way deduplicate them however we want to
# capture these cflags to be sure we work later on
# we then use this variable to inhibit this behavior
export PKG_CONFIG_ALLOW_SYSTEM_CFLAGS=1
if test "x${whole_prefix}" != "xno"; then
# This IF is long !!
# >>>>>>>>>>>>>>>>>>>
inc_prefix=""
AC_ARG_WITH([$2-inc],
[AS_HELP_STRING([--with-$2-inc],
[Provide include path for $2])],
[inc_prefix=$withval],[])
lib_prefix=""
AC_ARG_WITH([$2-libs],
[AS_HELP_STRING([--with-$2-libs],
[Provide library path for $2])],
[lib_prefix=$withval],[lib_prefix="$6"])
check_or_infer_prefix_result="no"
header_name=$1
libname=$2
alt_libname=$7
function_name=$3
var_prefix=$4
version="$5"
if test -z "$lib_prefix"
then
lib_prefix="$whole_prefix/lib"
fi
if test -d "${lib_prefix}/pkgconfig"; then
append_to_pkg_config_if_needed "${lib_prefix}/pkgconfig"
fi
if test -n "$whole_prefix"
then
if test -d "${whole_prefix}/lib/pkgconfig"; then
append_to_pkg_config_if_needed "${whole_prefix}/lib/pkgconfig"
fi
fi
if test -z "$inc_prefix"
then
inc_prefix="$whole_prefix/include/"
fi
AC_SUBST([$4_CFLAGS])
AC_SUBST([$4_LIBS])
#echo "PREF : $whole_prefix LIB: $lib_prefix INC: $inc_prefix"
# First try with PKG config
AC_MSG_NOTICE([Locating $libname$version with pkg-config])
PKG_CHECK_MODULES([$4], [$libname $version], [pkg_found=1], [pkg_found=0])
if test "x$pkg_found" = "x1"
then
# Make sure lib paths are explicitly known
$4_LIBS=$(extract_pkg_config_lib_prefixes "$libname" "${$4_LIBS}")
$4_CFLAGS=$(extract_pkg_config_inc_prefixes "$libname" "${$4_CFLAGS}")
# Ensure PKG config dependencies are also
# injected using RPATH
$4_LIBS=$(promote_to_rpath ${$4_LIBS})
AC_MSG_NOTICE([$4 FLAGS are ${$4_LIBS}])
#Insert flags
CPPFLAGS="${$4_CFLAGS} $CPPFLAGS"
LDFLAGS="${$4_LIBS} $LDFLAGS"
AC_SUBST([$4_CFLAGS])
AC_SUBST([$4_LIBS])
AC_MSG_NOTICE([$libname found using pkg-config])
AC_MSG_CHECKING([Compiling a simple progam with $libname flags])
# Make sure we still link to crash early
AC_LINK_IFELSE([AC_LANG_SOURCE([int main() {return 0;}])],
[
AC_MSG_RESULT([yes])
], [
AC_MSG_RESULT([no])
AC_MSG_ERROR([Cannot link after adding $libname flags.])
])
check_or_infer_prefix_result="yes"
else
__check_or_infer_prefix_include "$header_name" "$inc_prefix" "$var_prefix"
if test -n "${alt_libname}"; then
libname="${alt_libname}"
fi
__check_or_infer_prefix_lib "$libname" "$function_name" "$lib_prefix" "$var_prefix"
if test "x$check_or_infer_prefix_include" = "xyes" -a "x$check_or_infer_prefix_lib" = "xyes"
then
check_or_infer_prefix_result="yes"
else
check_or_infer_prefix_result="no"
fi
fi
AC_MSG_CHECKING([$2 cflags])
XXCFLAGS=$(eval echo \${$4_CFLAGS})
AC_MSG_RESULT([$XXCFLAGS])
AC_MSG_CHECKING([$2 ldflags])
XXLIB=$(eval echo \${$4_LIBS})
AC_MSG_RESULT([$XXLIB])
echo $LIBS_WITH_PATH
add_to_lib_configuration "$libname" "$XXCFLAGS" "$XXLIB"
AS_VAR_SET([dep_found], [$check_or_infer_prefix_result])
else
AC_MSG_NOTICE([!! $2 is explicitly deactivated])
AS_VAR_SET([dep_found], ["no"])
fi
# <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
whole_prefix=""
])
AC_DEFUN([MPC_REQUIRED_DEPENDENCY],
[
if test "x$2" = "xno"
then
AC_MSG_WARN([consider using --with-$1=PREFIX])
AC_MSG_WARN([consider using --with-$1-libs=LIBS])
AC_MSG_WARN([consider using --with-$1-include=INCS])
AC_MSG_ERROR([Failed to locate required dependency $1])
fi
])
MPC_DETECT_DEPENDENCY([hwloc.h],[hwloc], [hwloc_topology_init], [HWLOC], [> 2.0.0])
MPC_REQUIRED_DEPENDENCY([hwloc], [$mpc_dep_found])
MPC_DETECT_DEPENDENCY([opa_config.h],[openpa], [OPA_Queue_init], [OPA], [], [], [opa])
AC_ARG_ENABLE([rpmbuild],
[AS_HELP_STRING([--enable-rpmbuild],
[outputs rpm archive])],
[build_rpm_archive=yes],
[build_rpm_archive=no])
build_openpa=no
if test "x$mpc_dep_found" = "xno"; then
build_openpa=yes
if test "x$build_rpm_archive" = "xyes"
then
AC_MSG_NOTICE([Openpa not found, will build my own internal Openpa])
AC_CONFIG_SUBDIRS([contrib/openpa])
else
AC_MSG_ERROR([Could not locate openpa 'opa_config.h'.])
fi
fi
AM_CONDITIONAL([MPC_BUILD_OPENPA], [test "x$build_openpa" = "xyes"])
AC_ARG_ENABLE([ck],
[AS_HELP_STRING([--enable-ck],
[If CK is to be used])],
[use_ck=$enableval],
[use_ck=maybe])
if test "x$use_ck" = "xyes"; then
MPC_DETECT_DEPENDENCY([ck_stack.h],[ck], [ck_stack_pop_upmc], [CK], [], [], [ck])
MPC_REQUIRED_DEPENDENCY([ck], [$mpc_dep_found])
AC_DEFINE([MPC_USE_CK], [1], [concurrency-kit support is enabled])
ck_enabled="yes"
fi
AM_CONDITIONAL([CK_ENABLED], [test "x$ck_enabled" = "xyes"])
#
# Detect MPC Allocator
#
AC_ARG_ENABLE([mpcalloc],
[AS_HELP_STRING([--enable-mpcalloc],
[If the MPC allocator is to be used])],
[use_mpcalloc=$enableval],
[use_mpcalloc=maybe])