-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcollect.extra-libs.in
126 lines (119 loc) · 5.16 KB
/
collect.extra-libs.in
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
#!@SHELL@
# ICON
#
# ------------------------------------------
# Copyright (C) 2004-2024, DWD, MPI-M, DKRZ, KIT, ETH, MeteoSwiss
# Contact information: icon-model.org
# See AUTHORS.TXT for a list of authors
# See LICENSES/ for license information
# SPDX-License-Identifier: BSD-3-Clause
# ------------------------------------------
# Collect extra dependencies of the bundled libraries:
result=''
for subdir in @icon_bundled_config_subdirs@ @icon_bundled_cmake_subdirs@; do
extra_libs=''
case $subdir in
externals/comin/build)
# Extract dl libs from comin cmake variable
extra_libs=`cmake -L $subdir | sed -n 's/^COMIN_DL_LIBS\(:[A-Z]\+\)=\(-l\)\?\(.\+\)/-l\3/p'`
# We do not need extra_libs if its value is already in the LIBS:
if test -n "$extra_libs"; then
set dummy @LIBS@; shift
case ' '"$@"' ' in
*" $extra_libs "*)
extra_libs= ;;
*) ;;
esac
fi
;;
externals/sct)
# The bundled version of SCT, which we link statically, might require
# additional linker flags:
# 1) a flag enabling linking to librt;
# 2) a flag enabling linking to C code that uses OpenMP.
# First, we check whether we already have '-lrt' in the LIBS:
set dummy @LIBS@; shift
case ' '"$@"' ' in
*' -lrt '*) ;;
*)
# If that is not the case, check whether the configure script of SCT
# "decided" to include '-lrt' in the LIBS of SCT:
sct_LIBS=`echo '@''LIBS@' | "$subdir/config.status" -q --file=- | sed 's/^ *//;s/ *$//'`
case " $sct_LIBS " in
*' -lrt '*)
# If yes, we need to link with '-lrt':
extra_libs='-lrt' ;;
*) ;;
esac
;;
esac
# Second, get the flags enabling the Fortran compiler to link C code that
# uses OpenMP.
sct_OPENMP_FC_C_FLAGS=`echo '@''OPENMP_FC_C_FLAGS@' | "$subdir/config.status" -q --file=- | sed 's/^ *//;s/ *$//'`
# Check, whether we already have the flag in the linking command:
set dummy @FC@ @FCFLAGS@ @ICON_FCFLAGS@ @LDFLAGS@ @LIBS@; shift
# (note that the following does not properly account for multiple flags,
# which is, however, very unlikely):
case ' '"$@"' ' in
*" $sct_OPENMP_FC_C_FLAGS "*)
# If that is not the case, we need to link with the flag:
extra_libs="$sct_OPENMP_FC_C_FLAGS${extra_libs:+ $sct_OPENMP_FC_C_FLAGS}" ;;
*) ;;
esac
;;
externals/cdi)
# The bundled version of CDI, which we link statically, might require
# additional linker flags enabling linking to librt:
extra_libs=`echo '@''LIBRT@' | "$subdir/config.status" -q --file=- | sed 's/^ *//;s/ *$//'`
if test -z "$extra_libs"; then
cdi_ENABLE_MPI_FALSE=`echo '@''ENABLE_MPI_FALSE@' | "$subdir/config.status" -q --file=- | sed 's/^ *//;s/ *$//'`
if test "x$cdi_ENABLE_MPI_FALSE" = 'x#'; then
# We are here because either CDI does not depend on librt or the
# dependency is hidden by the libtool script of CDI (e.g. it found a
# libtool .la file that has '-lrt' among the 'dependency_libs',
# overlinked to librt and the configure script of CDI reported that no
# additional linker flags are required to link to the library, hence
# LIBRT was set to an empty string). The absence of the dependency on
# librt is very unlikely and here we could simply set the variable
# extra_libs to '-lrt'. However, we use this case as an example of how
# such issues can be resolved in general. Note that libcdipio.la might
# not exist yet, therefore we cannot parse it. Instead, we are going
# to run the libtool script of CDI in a way that is close to how the
# make program will call it:
cdi_LINK=`echo "@""SHELL@ @abs_top_builddir@/$subdir/libtool --tag=CC --mode=link @""CC@ @""CFLAGS@ @""LDFLAGS@ -o libconftest.la @""LIBS@" | "$subdir/config.status" -q --file=-`
# The libtool script generates some extra files and subdirectories,
# which we would like to remove easily. Therefore, we create a
# temporary subdirectory and switch to it:
@MKDIR_P@ conftest.dir && cd conftest.dir
# If calling the libtool script of CDI is successful and the created
# dummy libtool file 'libconftest.la' has '-lrt' among the
# 'dependency_libs', we set extra_libs to '-lrt':
(eval $cdi_LINK) >/dev/null 2>&1
if test $? -eq 0 && grep "dependency_libs=.*[ ']-lrt[ '].*" libconftest.la >/dev/null 2>&1; then
extra_libs='-lrt'
fi
cd ..
rm -rf conftest.dir
fi
fi
# We do not need extra_libs if its value is already in the LIBS:
if test -n "$extra_libs"; then
set dummy @LIBS@; shift
case ' '"$@"' ' in
*" $extra_libs "*)
extra_libs= ;;
*) ;;
esac
fi
;;
*) ;;
esac
if test -n "$extra_libs"; then
if test -n "$result"; then
result="$result $extra_libs"
else
result=$extra_libs
fi
fi
done
echo "$result"