dev-libs/libmissing: revbump to install fixed headers and static lib
[gentoo.git] / dev-libs / libmissing / libmissing-1.1.0.ebuild
1 # Copyright 2019 Gentoo Authors
2 # Distributed under the terms of the GNU General Public License v2
3
4 EAPI=7
5
6 inherit autotools
7
8 # NOTE: PV is the libtool version number current:revision:age
9
10 DESCRIPTION="Library with missing functions based on GNUlib"
11 HOMEPAGE="https://prefix.gentoo.org"
12 GIT_TAG="b451121ab45497e78cb6f612c8673a9705193391"
13 SRC_URI="https://git.savannah.gnu.org/cgit/gnulib.git/snapshot/gnulib-${GIT_TAG}.tar.gz"
14
15 LICENSE="GPL-2"
16 SLOT="0"
17 KEYWORDS="~ppc-macos ~sparc-solaris ~sparc64-solaris ~x64-solaris ~x86-solaris"
18 #IUSE="static-libs"  # dynamic won't work :(
19
20 DEPEND=""
21 RDEPEND="${DEPEND}"
22 BDEPEND=""
23
24 S="${WORKDIR}/gnulib-${GIT_TAG}"
25
26 src_prepare() {
27         default
28
29         # create a config file with just the definitions we need
30         mkdir extern-inline || die
31         cd extern-inline || die
32
33         cat > configure.ac <<- EOS
34                 AC_PREREQ([2.69])
35                 AC_INIT([${PN}], [${PV}], [prefix@gentoo.org])
36
37                 AC_CONFIG_MACRO_DIR([../m4])
38                 AC_CONFIG_HEADER([missing-include.h])
39
40                 gl_EXTERN_INLINE
41         EOS
42
43         eautoreconf
44         sed -e '1,/PACKAGE_VERSION/d' missing-include.h.in \
45                 > "${T}"/missing-include.h
46         cd .. || die
47
48         mkdir "${PN}" || die
49         cd "${PN}" || die
50         cat > configure.ac <<- EOS
51                 AC_PREREQ([2.69])
52                 AC_INIT([${PN}], [${PV}], [prefix@gentoo.org])
53                 AM_INIT_AUTOMAKE
54                 LT_INIT
55
56                 AC_CONFIG_MACRO_DIR([m4])
57                 AC_CONFIG_HEADER([config.h])
58
59                 AC_PROG_CC
60                 gl_INIT
61                 gl_EARLY
62
63                 AC_CONFIG_FILES([Makefile lib/Makefile])
64
65                 AC_OUTPUT
66         EOS
67
68         cat > Makefile.am <<- EOS
69                 SUBDIRS = lib
70         EOS
71
72         local modules
73         local platform
74         local rev
75
76         case "${CHOST}" in
77                 *-apple-darwin*)
78                         rev=${CHOST##*-darwin}
79                         platform="Mac OS X 10.$((rev - 4))"
80                         ;;
81                 *-solaris2.*)
82                         rev=${CHOST##*-solaris2.}
83                         # we only support Solaris 10 (and perhaps 9) and up, so we
84                         # don't have to bother about 2.x, just X
85                         platform="Solaris ${rev}"
86                         ;;
87         esac
88
89         # blacklist some modules that cause collisions
90         # iconv      provided by virtual/iconv -> sys-libs/libiconv
91         modules=( $(
92                 cd "${S}"/doc/posix-functions
93                 grep -A1 "This function is missing" *.texi | \
94                         grep "${platform}" | \
95                         sed -e 's:^\(.[^-]*\)-.*$:\1:' | \
96                         xargs sed -n 's/^Gnulib module: \([a-z].*\)$/\1/p' | \
97                         sed -e 's: or .*$::' -e 's:, :\n:g' | \
98                         sort -u | \
99                         grep -v "iconv"
100         ) )
101
102         # get platform specific set of missing functions
103         einfo "Including sources for missing functions on ${platform}:"
104         einfo "${modules[*]}"
105         "${S}"/gnulib-tool -S \
106                 --import \
107                 --lib=libmissing \
108                 --libtool \
109                 --no-vc-files \
110                 --no-cache-modules \
111                 "${modules[@]}"
112
113         sed -i -e '/^noinst_LTLIBRARIES /s/noinst_/lib_/' lib/Makefile.am || die
114         echo "libmissing_la_LDFLAGS += -version-info ${PV//./:}" >> lib/Makefile.am
115         cat >> lib/Makefile.am << 'EOS'
116 install-data-local: $(BUILT_SOURCES)
117         @for hdr in $(BUILT_SOURCES); do \
118                 $(INSTALL_HEADER) -D "$$hdr" $(DESTDIR)$(includedir)/$${hdr}; \
119         done;
120 EOS
121
122         eautoreconf
123 }
124
125 src_configure() {
126         cd "${PN}" || die
127
128         # ensure we don't pick up installed libmissing
129         export CPPFLAGS+="-DDISABLE_LIBMISSING"   # disable libmissing headers
130         export BINUTILS_CONFIG_DISABLE_MISSING=1  # disable -lmissing from ldwrapper
131         export CPPFLAGS="${CPPFLAGS/-I${EPREFIX}\/usr\/include\/missing/}"
132         export LIBS="${LIBS/-lmissing/}"
133         einfo "CPPFLAGS: ${CPPFLAGS}"
134         einfo "LIBS: ${LIBS}"
135
136         # gnulib cannot be used a shared library, doing so results in stack
137         # protector checks failing for reasons yet unknown to me
138         econf --disable-shared --enable-static || die
139 }
140
141 src_compile() {
142         cd "${PN}" || die
143         default
144 }
145
146 src_install() {
147         cd "${PN}" || die
148
149         default
150
151         rm -f "${ED}"/usr/lib/libmissing.la || die
152
153         cd "${ED}/usr/include" || die
154
155         # fix config.h dependency so we can can distribute it without
156         local f
157         for f in $(grep "_GL_INLINE_HEADER_BEGIN" -l *.h */*.h) ; do
158                 cat "${T}"/missing-include.h "${f}" > "${f}.new"
159                 [[ -s "${f}.new" ]] && mv "${f}.new" "${f}"
160         done
161
162         # modify all header-files so we can disable them and that they won't
163         # clash with gnulib-based packages
164         for f in *.h */*.h ; do
165                 sed -i \
166                         -e '1i#ifdef DISABLE_LIBMISSING\n# include_next <'"${f}"'>\n#else' \
167                         -e '$a#endif /* DISABLE_LIBMISSING */' \
168                         -e 's/_GL_/_LIBMISSING_/g' \
169                         "${f}" || die
170         done
171 }