blob: 85c8001dea89bc51f55e7c534fd7b6557489256b [file] [log] [blame]
Brad Bishop316dfdd2018-06-25 12:45:53 -04001SUMMARY = "Middleware layer between GObject-using C libraries and language bindings"
2HOMEPAGE = "https://wiki.gnome.org/action/show/Projects/GObjectIntrospection"
3BUGTRACKER = "https://bugzilla.gnome.org/"
4SECTION = "libs"
5LICENSE = "LGPLv2+ & GPLv2+"
6LIC_FILES_CHKSUM = "file://COPYING;md5=90d577535a3898e1ae5dbf0ae3509a8c \
7 file://tools/compiler.c;endline=20;md5=fc5007fc20022720e6c0b0cdde41fabd \
8 file://giscanner/sourcescanner.c;endline=22;md5=194d6e0c1d00662f32d030ce44de8d39 \
9 file://girepository/giregisteredtypeinfo.c;endline=21;md5=661847611ae6979465415f31a759ba27"
10
11SRC_URI = "${GNOME_MIRROR}/${BPN}/1.54/${BPN}-${PV}.tar.xz \
12 file://0001-Revert-an-incomplete-upstream-attempt-at-cross-compi.patch \
13 file://0002-configure.ac-add-host-gi-gi-cross-wrapper-gi-ldd-wra.patch \
14 file://0003-giscanner-add-use-binary-wrapper-option.patch \
15 file://0004-giscanner-add-a-use-ldd-wrapper-option.patch \
16 file://0005-Prefix-pkg-config-paths-with-PKG_CONFIG_SYSROOT_DIR-.patch \
17 file://0001-giscanner-add-a-lib-dirs-envvar-option.patch \
18 "
19SRC_URI[md5sum] = "126c29e4d54adbed2ed4e2b04483de41"
20SRC_URI[sha256sum] = "b88ded5e5f064ab58a93aadecd6d58db2ec9d970648534c63807d4f9a7bb877e"
21
22inherit autotools pkgconfig gtk-doc python3native qemu gobject-introspection-data upstream-version-is-even
23BBCLASSEXTEND = "native"
24
25# needed for writing out the qemu wrapper script
26export STAGING_DIR_HOST
27export B
28
29DEPENDS_append = " libffi zlib glib-2.0 python3 flex-native bison-native"
30
31# target build needs qemu to run temporary introspection binaries created
32# on the fly by g-ir-scanner and a native version of itself to run
33# native versions of its own tools during build.
34# Also prelink-rtld is used to find out library dependencies of introspection binaries
35# (standard ldd doesn't work when cross-compiling).
36DEPENDS_class-target_append = " gobject-introspection-native qemu-native prelink-native"
37
38SSTATE_SCAN_FILES += "g-ir-scanner-qemuwrapper g-ir-scanner-wrapper g-ir-compiler-wrapper g-ir-scanner-lddwrapper Gio-2.0.gir postinst-ldsoconf-${PN}"
39
40do_configure_prepend_class-native() {
41 # Tweak the native python scripts so that they don't refer to the
42 # full path of native python binary (the solution is taken from glib-2.0 recipe)
43 # This removes the risk of exceeding Linux kernel's shebang line limit (128 bytes)
44 sed -i -e '1s,#!.*,#!${USRBINPATH}/env python3,' ${S}/tools/g-ir-tool-template.in
45}
46
47do_configure_prepend_class-target() {
48 # Write out a qemu wrapper that will be given to gi-scanner so that it
49 # can run target helper binaries through that.
50 qemu_binary="${@qemu_wrapper_cmdline(d, '$STAGING_DIR_HOST', ['\$GIR_EXTRA_LIBS_PATH','.libs','$STAGING_DIR_HOST/${libdir}','$STAGING_DIR_HOST/${base_libdir}'])}"
51 cat > ${B}/g-ir-scanner-qemuwrapper << EOF
52#!/bin/sh
53# Use a modules directory which doesn't exist so we don't load random things
54# which may then get deleted (or their dependencies) and potentially segfault
55export GIO_MODULE_DIR=${STAGING_LIBDIR}/gio/modules-dummy
56
57$qemu_binary "\$@"
58if [ \$? -ne 0 ]; then
59 echo "If the above error message is about missing .so libraries, then setting up GIR_EXTRA_LIBS_PATH in the recipe should help."
60 echo "(typically like this: GIR_EXTRA_LIBS_PATH=\"$""{B}/something/.libs\" )"
61 exit 1
62fi
63EOF
64 chmod +x ${B}/g-ir-scanner-qemuwrapper
65
66 # Write out a wrapper for g-ir-scanner itself, which will be used when building introspection files
67 # for glib-based packages. This wrapper calls the native version of the scanner, and tells it to use
68 # a qemu wrapper for running transient target binaries produced by the scanner, and an include directory
69 # from the target sysroot.
70 cat > ${B}/g-ir-scanner-wrapper << EOF
71#!/bin/sh
72# This prevents g-ir-scanner from writing cache data to $HOME
73export GI_SCANNER_DISABLE_CACHE=1
74
75g-ir-scanner --lib-dirs-envvar=GIR_EXTRA_LIBS_PATH --use-binary-wrapper=${STAGING_BINDIR}/g-ir-scanner-qemuwrapper --use-ldd-wrapper=${STAGING_BINDIR}/g-ir-scanner-lddwrapper --add-include-path=${STAGING_DATADIR}/gir-1.0 "\$@"
76EOF
77 chmod +x ${B}/g-ir-scanner-wrapper
78
79 # Write out a wrapper for g-ir-compiler, which runs the target version of it through qemu.
80 # g-ir-compiler writes out the raw content of a C struct to disk, and therefore is architecture dependent.
81 cat > ${B}/g-ir-compiler-wrapper << EOF
82#!/bin/sh
83${STAGING_BINDIR}/g-ir-scanner-qemuwrapper ${STAGING_BINDIR}/g-ir-compiler "\$@"
84EOF
85 chmod +x ${B}/g-ir-compiler-wrapper
86
87 # Write out a wrapper to use instead of ldd, which does not work when a binary is built
88 # for a different architecture
89 cat > ${B}/g-ir-scanner-lddwrapper << EOF
90#!/bin/sh
91prelink-rtld --root=$STAGING_DIR_HOST "\$@"
92EOF
93 chmod +x ${B}/g-ir-scanner-lddwrapper
94
95 # Also tweak the target python scripts so that they don't refer to the
96 # native version of python binary (the solution is taken from glib-2.0 recipe)
97 sed -i -e '1s,#!.*,#!${USRBINPATH}/env python3,' ${S}/tools/g-ir-tool-template.in
98}
99
100# Configure target build to use native tools of itself and to use a qemu wrapper
101# and optionally to generate introspection data
102EXTRA_OECONF_class-target += "--enable-host-gi \
103 --disable-static \
104 --enable-gi-cross-wrapper=${B}/g-ir-scanner-qemuwrapper \
105 --enable-gi-ldd-wrapper=${B}/g-ir-scanner-lddwrapper \
106 ${@bb.utils.contains('GI_DATA_ENABLED', 'True', '--enable-introspection-data', '--disable-introspection-data', d)} \
107 "
108
109PACKAGECONFIG ?= ""
110PACKAGECONFIG[doctool] = "--enable-doctool,--disable-doctool,python3-mako,"
111
112do_compile_prepend() {
113 # This prevents g-ir-scanner from writing cache data to $HOME
114 export GI_SCANNER_DISABLE_CACHE=1
115
116 # Needed to run g-ir unit tests, which won't be able to find the built libraries otherwise
117 export GIR_EXTRA_LIBS_PATH=$B/.libs
118}
119
120# Our wrappers need to be available system-wide, because they will be used
121# to build introspection files for all other gobject-based packages
122do_install_append_class-target() {
123 install -d ${D}${bindir}/
124 install ${B}/g-ir-scanner-qemuwrapper ${D}${bindir}/
125 install ${B}/g-ir-scanner-wrapper ${D}${bindir}/
126 install ${B}/g-ir-compiler-wrapper ${D}${bindir}/
127 install ${B}/g-ir-scanner-lddwrapper ${D}${bindir}/
128}
129
130# .typelib files are needed at runtime and so they go to the main package
131FILES_${PN}_append = " ${libdir}/girepository-*/*.typelib"
132
133# .gir files go to dev package, as they're needed for developing (but not for running)
134# things that depends on introspection.
135FILES_${PN}-dev_append = " ${datadir}/gir-*/*.gir"
136FILES_${PN}-dev_append = " ${datadir}/gir-*/*.rnc"
137
138# These are used by gobject-based packages
139# to generate transient introspection binaries
140FILES_${PN}-dev_append = " ${datadir}/gobject-introspection-1.0/gdump.c \
141 ${datadir}/gobject-introspection-1.0/Makefile.introspection"
142
143# These are used by dependent packages (e.g. pygobject) to build their
144# testsuites.
145FILES_${PN}-dev_append = " ${datadir}/gobject-introspection-1.0/tests/*.c \
146 ${datadir}/gobject-introspection-1.0/tests/*.h"
147
148FILES_${PN}-dbg += "${libdir}/gobject-introspection/giscanner/.debug/"
149FILES_${PN}-staticdev += "${libdir}/gobject-introspection/giscanner/*.a"
150
151# we need target versions of introspection tools in sysroot so that they can be run via qemu
152# when building introspection files in other packages
153SYSROOT_DIRS_append_class-target = " ${bindir}"
154
155SYSROOT_PREPROCESS_FUNCS_append_class-target = " gi_binaries_sysroot_preprocess"
156gi_binaries_sysroot_preprocess() {
157 # Tweak the binary names in the introspection pkgconfig file, so that it
158 # picks up our wrappers which do the cross-compile and qemu magic.
159 sed -i \
160 -e "s|g_ir_scanner=.*|g_ir_scanner=${bindir}/g-ir-scanner-wrapper|" \
161 -e "s|g_ir_compiler=.*|g_ir_compiler=${bindir}/g-ir-compiler-wrapper|" \
162 ${SYSROOT_DESTDIR}${libdir}/pkgconfig/gobject-introspection-1.0.pc
163}
164
165# Need to ensure ld.so.conf exists so prelink-native works
166# both before we build and if we install from sstate
167do_configure[prefuncs] += "gobject_introspection_preconfigure"
168python gobject_introspection_preconfigure () {
169 oe.utils.write_ld_so_conf(d)
170}
171
172SYSROOT_PREPROCESS_FUNCS_append = " gi_ldsoconf_sysroot_preprocess"
173gi_ldsoconf_sysroot_preprocess () {
174 mkdir -p ${SYSROOT_DESTDIR}${bindir}
175 dest=${SYSROOT_DESTDIR}${bindir}/postinst-ldsoconf-${PN}
176 echo "#!/bin/sh" > $dest
177 echo "mkdir -p ${STAGING_DIR_TARGET}${sysconfdir}" >> $dest
178 echo "echo ${base_libdir} >> ${STAGING_DIR_TARGET}${sysconfdir}/ld.so.conf" >> $dest
179 echo "echo ${libdir} >> ${STAGING_DIR_TARGET}${sysconfdir}/ld.so.conf" >> $dest
180 chmod 755 $dest
181}
182
183# Remove wrapper files from the package, only used for cross-compiling
184PACKAGE_PREPROCESS_FUNCS += "gi_package_preprocess"
185gi_package_preprocess() {
186 rm -f ${PKGD}${bindir}/g-ir-scanner-qemuwrapper
187 rm -f ${PKGD}${bindir}/g-ir-scanner-wrapper
188 rm -f ${PKGD}${bindir}/g-ir-compiler-wrapper
189 rm -f ${PKGD}${bindir}/g-ir-scanner-lddwrapper
190}