xref: /OK3568_Linux_fs/buildroot/package/gobject-introspection/gobject-introspection.mk (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1################################################################################
2#
3# gobject-introspection
4#
5################################################################################
6
7GOBJECT_INTROSPECTION_VERSION_MAJOR = 1.68
8GOBJECT_INTROSPECTION_VERSION = $(GOBJECT_INTROSPECTION_VERSION_MAJOR).0
9GOBJECT_INTROSPECTION_SITE = http://ftp.gnome.org/pub/GNOME/sources/gobject-introspection/$(GOBJECT_INTROSPECTION_VERSION_MAJOR)
10GOBJECT_INTROSPECTION_SOURCE = gobject-introspection-$(GOBJECT_INTROSPECTION_VERSION).tar.xz
11GOBJECT_INTROSPECTION_INSTALL_STAGING = YES
12GOBJECT_INTROSPECTION_AUTORECONF = YES
13GOBJECT_INTROSPECTION_LICENSE = LGPL-2.0+, GPL-2.0+, BSD-2-Clause
14GOBJECT_INTROSPECTION_LICENSE_FILES = COPYING.LGPL COPYING.GPL giscanner/scannerlexer.l
15
16GOBJECT_INTROSPECTION_DEPENDENCIES = \
17	host-autoconf-archive \
18	host-gobject-introspection \
19	host-prelink-cross \
20	host-qemu \
21	libffi \
22	libglib2 \
23	python3 \
24	zlib
25
26HOST_GOBJECT_INTROSPECTION_DEPENDENCIES = \
27	host-bison \
28	host-flex \
29	host-libglib2 \
30	host-python3
31
32# g-ir-scanner will default to /usr/bin/ld for linking if this is not set.
33GOBJECT_INTROSPECTION_NINJA_ENV += \
34	CC="$(TARGET_CC)"
35
36# When building, gobject-introspection uses tools/g-ir-scanner to build several
37# .gir and .typelib files. g-ir-scanner does not use LDFLAGS, and by default,
38# links to the system-installed libglib2 path. To remedy this issue, defining
39# LD_LIBRARY_PATH forces g-ir-scanner to use our host installed libglib2 files.
40HOST_GOBJECT_INTROSPECTION_NINJA_ENV += \
41	LD_LIBRARY_PATH="$(if $(LD_LIBRARY_PATH),$(LD_LIBRARY_PATH):)$(HOST_DIR)/lib"
42
43# Use the host gi-scanner to prevent the scanner from generating incorrect
44# elf classes.
45GOBJECT_INTROSPECTION_CONF_OPTS = \
46	-Dgi_cross_use_prebuilt_gi=true \
47	-Dgi_cross_binary_wrapper="$(STAGING_DIR)/usr/bin/g-ir-scanner-qemuwrapper" \
48	-Dgi_cross_ldd_wrapper="$(STAGING_DIR)/usr/bin/g-ir-scanner-lddwrapper" \
49	-Dbuild_introspection_data=true \
50	-Ddoctool=disabled
51
52ifeq ($(BR2_PACKAGE_CAIRO),y)
53GOBJECT_INTROSPECTION_DEPENDENCIES += cairo
54GOBJECT_INTROSPECTION_CONF_OPTS += -Dcairo=enabled
55else
56GOBJECT_INTROSPECTION_CONF_OPTS += -Dcairo=disabled
57endif
58
59# GI_SCANNER_DISABLE_CACHE=1 prevents g-ir-scanner from writing cache data to ${HOME}
60GOBJECT_INTROSPECTION_CONF_ENV = \
61	GI_SCANNER_DISABLE_CACHE=1
62
63HOST_GOBJECT_INTROSPECTION_CONF_ENV = \
64	GI_SCANNER_DISABLE_CACHE=1
65
66# Make sure g-ir-tool-template uses the host python.
67define GOBJECT_INTROSPECTION_FIX_TOOLS_PYTHON_PATH
68	$(SED) '1s%#!.*%#!$(HOST_DIR)/bin/python3%' $(@D)/tools/g-ir-tool-template.in
69endef
70HOST_GOBJECT_INTROSPECTION_PRE_CONFIGURE_HOOKS += GOBJECT_INTROSPECTION_FIX_TOOLTEMPLATE_PYTHON_PATH
71
72# Perform the following:
73# - Just as above, Ensure that g-ir-tool-template.in uses the host python.
74# - Install all of the wrappers needed to build gobject-introspection.
75# - Create a safe modules directory which does not exist so we don't load random things
76#   which may then get deleted (or their dependencies) and potentially segfault
77define GOBJECT_INTROSPECTION_INSTALL_PRE_WRAPPERS
78	$(SED) '1s%#!.*%#!$(HOST_DIR)/bin/python3%' $(@D)/tools/g-ir-tool-template.in
79
80	$(INSTALL) -D -m 755 $(GOBJECT_INTROSPECTION_PKGDIR)/g-ir-scanner-lddwrapper.in \
81		$(STAGING_DIR)/usr/bin/g-ir-scanner-lddwrapper
82
83	$(INSTALL) -D -m 755 $(GOBJECT_INTROSPECTION_PKGDIR)/g-ir-scanner-qemuwrapper.in \
84		$(STAGING_DIR)/usr/bin/g-ir-scanner-qemuwrapper
85	$(SED) "s%@QEMU_USER@%$(QEMU_USER)%g" \
86		$(STAGING_DIR)/usr/bin/g-ir-scanner-qemuwrapper
87	$(SED) "s%@QEMU_USERMODE_ARGS@%$(call qstrip,$(BR2_PACKAGE_HOST_QEMU_USER_MODE_ARGS))%g" \
88		$(STAGING_DIR)/usr/bin/g-ir-scanner-qemuwrapper
89	$(SED) "s%@TOOLCHAIN_HEADERS_VERSION@%$(BR2_TOOLCHAIN_HEADERS_AT_LEAST)%g" \
90		$(STAGING_DIR)/usr/bin/g-ir-scanner-qemuwrapper
91
92	# Use a modules directory which does not exist so we don't load random things
93	# which may then get deleted (or their dependencies) and potentially segfault
94	mkdir -p $(STAGING_DIR)/usr/lib/gio/modules-dummy
95endef
96GOBJECT_INTROSPECTION_PRE_CONFIGURE_HOOKS += GOBJECT_INTROSPECTION_INSTALL_PRE_WRAPPERS
97
98# Move the real compiler and scanner to .real, and replace them with the wrappers.
99# Using .real has the following advantages:
100# - There is no need to change the logic for other packages.
101# - The wrappers call the .real files using qemu.
102define GOBJECT_INTROSPECTION_INSTALL_WRAPPERS
103	# Move the real binaries to their names.real, then replace them with
104	# the wrappers.
105	$(foreach w,g-ir-compiler g-ir-scanner,
106		mv $(STAGING_DIR)/usr/bin/$(w) $(STAGING_DIR)/usr/bin/$(w).real
107		$(INSTALL) -D -m 755 \
108			$(GOBJECT_INTROSPECTION_PKGDIR)/$(w).in $(STAGING_DIR)/usr/bin/$(w)
109	)
110	$(SED) "s%@BASENAME_TARGET_CPP@%$(notdir $(TARGET_CPP))%g" \
111		-e "s%@BASENAME_TARGET_CC@%$(notdir $(TARGET_CC))%g" \
112		-e "s%@BASENAME_TARGET_CXX@%$(notdir $(TARGET_CXX))%g" \
113		-e "s%@TARGET_CPPFLAGS@%$(TARGET_CPPFLAGS)%g" \
114		-e "s%@TARGET_CFLAGS@%$(TARGET_CFLAGS)%g" \
115		-e "s%@TARGET_CXXFLAGS@%$(TARGET_CXXFLAGS)%g" \
116		-e "s%@TARGET_LDFLAGS@%$(TARGET_LDFLAGS)%g" \
117		$(STAGING_DIR)/usr/bin/g-ir-scanner
118
119	# Gobject-introspection installs Makefile.introspection in
120	# $(STAGING_DIR)/usr/share which is needed for autotools-based programs to
121	# build .gir and .typelib files. Unfortunately, gobject-introspection-1.0.pc
122	# uses $(prefix)/share as the directory, which
123	# causes the host /usr/share being used instead of $(STAGING_DIR)/usr/share.
124	# Change datadir to $(libdir)/../share which will prefix $(STAGING_DIR)
125	# to the correct location.
126	$(SED) "s%^datadir=.*%datadir=\$${libdir}/../share%g" \
127		$(STAGING_DIR)/usr/lib/pkgconfig/gobject-introspection-1.0.pc
128
129	# By default, girdir and typelibdir use datadir and libdir as their prefix,
130	# of which pkg-config appends the sysroot directory. This results in files
131	# being installed in $(STAGING_DIR)/$(STAGING_DIR)/path/to/files.
132	# Changing the prefix to prefix prevents this error.
133	$(SED) "s%girdir=.*%girdir=\$${prefix}/share/gir-1.0%g" \
134		$(STAGING_DIR)/usr/lib/pkgconfig/gobject-introspection-1.0.pc
135
136	$(SED) "s%typelibdir=.*%typelibdir=\$${prefix}/lib/girepository-1.0%g" \
137		$(STAGING_DIR)/usr/lib/pkgconfig/gobject-introspection-1.0.pc
138
139	# Set includedir to $(STAGING_DIR)/usr/share/gir-1.0 instead of . or
140	# g-ir-compiler won't find .gir files resulting in a build failure for
141	# autotools-based based programs
142	$(SED) "s%includedir=.%includedir=$(STAGING_DIR)/usr/share/gir-1.0%g" \
143		$(STAGING_DIR)/usr/share/gobject-introspection-1.0/Makefile.introspection
144endef
145GOBJECT_INTROSPECTION_POST_INSTALL_STAGING_HOOKS += GOBJECT_INTROSPECTION_INSTALL_WRAPPERS
146
147# Only .typelib files are needed to run.
148define GOBJECT_INTROSPECTION_REMOVE_DEVELOPMENT_FILES
149	find $(TARGET_DIR)/usr/share \( -iname "*.gir" -o -iname \*.rnc \) -delete
150endef
151GOBJECT_INTROSPECTION_TARGET_FINALIZE_HOOKS += GOBJECT_INTROSPECTION_REMOVE_DEVELOPMENT_FILES
152
153$(eval $(meson-package))
154$(eval $(host-meson-package))
155