summaryrefslogtreecommitdiff
path: root/am/wlelim.m4
blob: 4a87feb135c04d76ad3d99ba6319c16ac50b47fd (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
dnl This file is part of GNU mailutils.
dnl Copyright (C) 2019 Free Software Foundation, Inc.
dnl
dnl GNU Mailutils is free software; you can redistribute it and/or modify
dnl it under the terms of the GNU General Public License as published by
dnl the Free Software Foundation; either version 3 of the License, or
dnl (at your option) any later version.
dnl
dnl GNU Mailutils is distributed in the hope that it will be useful,
dnl but WITHOUT ANY WARRANTY; without even the implied warranty of
dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
dnl GNU General Public License for more details.
dnl
dnl You should have received a copy of the GNU General Public License
dnl along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>.

# Some packages provide configuration helper tools that emit the cc
# flags to be used when linking a program with that package.  Normally
# the output of such a tool consists of a series of -l (eventualy -L)
# options in the right order.  However, some tools thoughtlessly emit
# linker options (-Wl,option) as well.  The most notorious example of
# these is krb5-config.  Such options cannot be reliably used with
# libtool.  The `-Wl,-rpath -Wl,DIR' option is particularly harmful.
# When creating the wrapper script for a program, libtool adds all DIRs
# given to it with the -rpath options to the beginning of the installation
# library directory list.  When the wrapper relinks the program for local
# use (e.g. in testsuite), it will append the path in the source tree to
# that list *after* all these rpaths.  As a result, when running the
# program, it will pick the libraries installed in the system instead of
# their local versions from the source tree.
#
# This module provides macros for eliminating the -Wl options from the
# shell variables.
#
# Obviously, libtool should be fixed to place rpaths from the source tree
# before any other directories.
#
# For the record, there are also other issues that can cause wrong libraries
# to be used on some systems.  See, for example this libtool bug report:
#   https://debbugs.gnu.org/cgi/bugreport.cgi?bug=27510
# This issue has not been addressed yet.

dnl MU_WLELIM_INIT
dnl --------------
dnl Initialize the Wl elimination procedure by emitting auxiliary shell
dnl functions used in it.
dnl Normally you don't need to use this macro explicitly, as it will be
dnl called exactly once by the first expansion of the MU_WLELIM_VAR or
dnl MU_WLELIM_SUBST (see below).
AC_DEFUN([MU_WLELIM_INIT],[
m4_ifdef([MU_WLELIM_INIT_SENTINEL],[],
[# The following three functions were inspired by libtool.

# func_append VAR STRING
# ----------------------
# Append STRING to the value of the variable VAR.  Unless VAR is empty
# or undefined, precede STRING with a single space
func_append()
{
    eval "@S|@1=\@S|@@S|@1\@S|@{@S|@1:+ }\@S|@2"
}

# Sed substitution that helps us do robust quoting.  It backslashifies
# metacharacters that are still active within double-quoted strings.
sed_quote_subst='s|\([`"@S|@\\]\)|\\\1|g'

# func_quote_for_eval ARG...
# --------------------------
# Quote ARGs to be evaled later.  Leave return in the variable
# func_quote_for_eval_result.
func_quote_for_eval()
{
    func_quote_for_eval_result=
    for arg
    do
      case @S|@arg in
        *[\\\`\"\@S|@]*)
	  _G_arg=`echo "@S|@arg" | @S|@{SED:-sed} "@S|@sed_quote_subst"` ;;
        *)
          _G_arg=@S|@1 ;;
      esac
      func_append func_quote_for_eval_result "@S|@_G_arg"
    done
}

# func_append_quoted VAR STRING
# -----------------------------
# Append space character and STRING to the value of the variable VAR.
# Take care to properly quote the STRING, so that @S|@VAR will be evaled
# correctly. 
func_append_quoted()
{
    func_quote_for_eval "@S|@2"
    eval "@S|@1=\@S|@@S|@1\\ \@S|@func_quote_for_eval_result"
}

# func_elim_linker_options2 VAR ARG...
# ------------------------------------
# Eliminate ARGs that contain linker command line options (-Wl,...).
# Append the remaining ones to the value of the variable VAR.
func_elim_linker_options2()
{
    elim_linker_options_var=@S|@1
    shift
    eval @S|@elim_linker_options_var=
    for opt
    do
	case @S|@opt in
	    -Wl,*) ;;
	    *)     func_append_quoted @S|@elim_linker_options_var "@S|@opt"
	esac
    done
}

# func_elim_linker_options VAR
# ----------------------------
# Eliminate linker command line options from the value of the variable
# VAR.
func_elim_linker_options()
{
    eval func_elim_linker_options2 @S|@1 \@S|@@S|@1
}
m4_define([MU_WLELIM_INIT_SENTINEL],[TRUE])])
])

dnl MU_WLELIM_VAR(VARNAME)
dnl ----------------------
dnl Mark shell variable VARNAME as needing linker option elimination.
AC_DEFUN([MU_WLELIM_VAR],[MU_WLELIM_INIT
m4_set_add(mu_linker_substvars,$1)])

dnl MU_WLELIM_SUBST(VARNAME)
dnl ------------------------
dnl AC_SUBST the variable VARNAME and mark it as needing linker option
dnl elimination.
AC_DEFUN([MU_WLELIM_SUBST],[AC_SUBST($@)
MU_WLELIM_VAR($1)])

dnl MU_WLELIM_COMMIT
dnl ----------------
dnl Commit the changes by eliminating the linker options from all variables
dnl collected so far.
AC_DEFUN([MU_WLELIM_COMMIT],[m4_set_foreach(mu_linker_substvars,VAR,
 [func_elim_linker_options VAR
])])

dnl END of wlelim.m4

Return to:

Send suggestions and report system problems to the System administrator.