blob: f0946de2cc1f07ce4572b7586f2966af89c2e5f5 [file] [log] [blame]
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001SECTION = "devel"
2# Need binutils for libiberty.a
3# Would need transfig-native for documentation if it wasn't disabled
4DEPENDS = "elfutils binutils"
5SUMMARY = "An ELF prelinking utility"
Brad Bishopd7bf8c12018-02-25 22:55:05 -05006HOMEPAGE = "http://git.yoctoproject.org/cgit.cgi/prelink-cross/about/"
Patrick Williamsc124f4f2015-09-15 14:41:29 -05007DESCRIPTION = "The prelink package contains a utility which modifies ELF shared libraries \
8and executables, so that far fewer relocations need to be resolved at \
9runtime and thus programs come up faster."
10LICENSE = "GPLv2"
11LIC_FILES_CHKSUM = "file://COPYING;md5=c93c0550bd3173f4504b2cbd8991e50b"
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080012SRCREV = "a853a5d715d84eec93aa68e8f2df26b7d860f5b2"
Patrick Williamsc124f4f2015-09-15 14:41:29 -050013PV = "1.0+git${SRCPV}"
14
15#
16# The cron script attempts to re-prelink the system daily -- on
17# systems where users are adding applications, this might be reasonable
18# but for embedded, we should be re-running prelink -a after an update.
19#
20# Default is prelinking is enabled.
21#
22SUMMARY_${PN}-cron = "Cron scripts to control automatic prelinking"
23DESCRIPTION_${PN}-cron = "Cron scripts to control automatic prelinking. \
24See: ${sysconfdir}/cron.daily/prelink for configuration information."
25
26FILES_${PN}-cron = "${sysconfdir}/cron.daily ${sysconfdir}/default"
27
28PACKAGES =+ "${PN}-cron"
29
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080030SRC_URI = "git://git.yoctoproject.org/prelink-cross.git;branch=cross_prelink_staging \
Patrick Williamsc124f4f2015-09-15 14:41:29 -050031 file://prelink.conf \
32 file://prelink.cron.daily \
33 file://prelink.default \
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080034 file://macros.prelink \
35 file://0001-src-arch-mips.c-check-info-resolvetls-before-use-its.patch \
36"
Brad Bishop316dfdd2018-06-25 12:45:53 -040037UPSTREAM_CHECK_COMMITS = "1"
Patrick Williamsc124f4f2015-09-15 14:41:29 -050038
Brad Bishop79641f22019-09-10 07:20:22 -040039# error: error.h: No such file or directory
40COMPATIBLE_HOST_libc-musl = 'null'
41
Patrick Williamsc124f4f2015-09-15 14:41:29 -050042TARGET_OS_ORIG := "${TARGET_OS}"
43OVERRIDES_append = ":${TARGET_OS_ORIG}"
44
Patrick Williamsf1e5d692016-03-30 15:21:19 -050045S = "${WORKDIR}/git"
Patrick Williamsc124f4f2015-09-15 14:41:29 -050046
47inherit autotools
48
49BBCLASSEXTEND = "native"
50
51EXTRA_OECONF = "--disable-selinux --with-pkgversion=${PV}-${PR} \
52 --with-bugurl=http://bugzilla.yoctoproject.org/"
53
Patrick Williamsc0f7c042017-02-23 20:41:17 -060054
55#
56# For target prelink we need to ensure paths match the lib path layout
57# including for any configured multilibs
58#
59python do_linkerpaths () {
60 values = all_multilib_tune_list(["TUNE_ARCH", "baselib", "ABIEXTENSION"], d)
61
62 arches = values["TUNE_ARCH"]
63 baselibs = values["baselib"]
64 abis = values["ABIEXTENSION"]
65
66 def replace_lines(f, search, replacement, d, firstonly = False, secondonly = False):
67 f = d.expand(f)
68 if search == replacement:
69 return
70 bb.debug(2, "Replacing %s with %s in %s" % (search, replacement, f))
71 with open(f, "r") as data:
72 lines = data.readlines()
73 with open(f, "w") as data:
74 for line in lines:
75 if not secondonly and not firstonly:
76 line = line.replace(search, replacement)
77 elif secondonly and search in line:
78 secondonly = False
79 elif firstonly and search and search in line:
80 line = line.replace(search, replacement)
81 search = None
82 data.write(line)
83
84 def replace_lines_rtld(f, search, replacement, section, d):
85 f = d.expand(f)
86 bb.debug(2, "Replacing %s with %s in %s" % (search, replacement, f))
87 with open(f, "r") as data:
88 lines = data.readlines()
89 found = False
90 found2 = False
91 with open(f, "w") as data:
92 for line in lines:
93 if section in line:
94 if section == "else" and "if" in line:
95 found = False
96 else:
97 found = True
98 if found and "dst_LIB =" in line:
99 found2 = True
100 elif "}" in line:
101 found = False
102 found2 = False
103 if found2:
104 line = line.replace(search, replacement)
105 data.write(line)
106
107 for i, arch in enumerate(arches):
108 tune_baselib = baselibs[i]
109 abi = abis[i]
110
111 bits = 32
112 if arch == "powerpc":
113 replace_lines("${S}/src/arch-ppc.c", "/lib/ld.so.1", "/" + tune_baselib + "/ld.so.1", d)
114 elif arch == "powerpc64":
115 replace_lines("${S}/src/arch-ppc64.c", "/lib64/ld64.so.1", "/" + tune_baselib + "/ld64.so.1", d)
116 bits = 64
117 elif arch == "x86_64":
118 if abi == "x32":
119 replace_lines("${S}/src/arch-x86_64.c", "/libx32/ld-linux-x32.so.2", "/" + tune_baselib + "/ld-linux-x32.so.2", d)
120 else:
121 replace_lines("${S}/src/arch-x86_64.c", "/lib64/ld-linux-x86-64.so.2", "/" + tune_baselib + "/ld-linux-x86-64.so.2", d)
122 bits = 64
123 elif arch == "arm":
124 replace_lines("${S}/src/arch-arm.c", "/lib/ld-linux.so.3", "/" + tune_baselib + "/ld-linux.so.3", d)
125 replace_lines("${S}/src/arch-arm.c", "/lib/ld-linux-armhf.so.3", "/" + tune_baselib + "/ld-linux-armhf.so.3", d)
126 elif arch == "mips" or arch == "mipsel":
127 replace_lines("${S}/src/arch-mips.c", "/lib/ld.so.1", "/" + tune_baselib + "/ld.so.1", d, firstonly=True)
128 replace_lines("${S}/src/arch-mips.c", "/lib32/ld.so.1", "/" + tune_baselib + "/ld.so.1", d)
129 elif arch == "mips64" or arch == "mips64el":
130 replace_lines("${S}/src/arch-mips.c", "/lib/ld.so.1", "/" + tune_baselib + "/ld.so.1", d, secondonly=True)
131 replace_lines("${S}/src/arch-mips.c", "/lib64/ld.so.1", "/" + tune_baselib + "/ld.so.1", d)
132 bits = 64
133 elif arch.endswith("86"):
134 replace_lines("${S}/src/arch-i386.c", "/lib/ld-linux.so.2", "/" + tune_baselib + "/ld-linux.so.2", d)
135 if bits == 32 and tune_baselib != "lib":
136 replace_lines_rtld("${S}/src/rtld/rtld.c", "lib", tune_baselib, "else", d)
137 if bits == 64 and tune_baselib != "lib64":
138 replace_lines_rtld("${S}/src/rtld/rtld.c", "lib64", tune_baselib, "use_64bit", d)
139}
140
141python () {
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500142 overrides = d.getVar("OVERRIDES").split(":")
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600143 if "class-target" in overrides:
144 bb.build.addtask('do_linkerpaths', 'do_configure', 'do_patch', d)
145}
146
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500147do_configure_prepend () {
148 # Disable documentation!
149 echo "all:" > ${S}/doc/Makefile.am
150}
151
152do_install_append () {
153 install -d ${D}${sysconfdir}/cron.daily ${D}${sysconfdir}/default ${D}${sysconfdir}/rpm
154 install -m 0644 ${WORKDIR}/prelink.conf ${D}${sysconfdir}/prelink.conf
155 install -m 0644 ${WORKDIR}/prelink.cron.daily ${D}${sysconfdir}/cron.daily/prelink
156 install -m 0644 ${WORKDIR}/prelink.default ${D}${sysconfdir}/default/prelink
157 install -m 0644 ${WORKDIR}/macros.prelink ${D}${sysconfdir}/rpm/macros.prelink
158}
159
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500160# If we ae doing a cross install, we want to avoid prelinking.
161# Prelinking during a cross install should be handled by the image-prelink
162# bbclass. If the user desires this to run on the target at first boot
163# they will need to create a custom boot script.
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500164pkg_postinst_prelink() {
165#!/bin/sh
166
167if [ "x$D" != "x" ]; then
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500168 exit 0
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500169fi
170
171prelink -a
172}
173
174pkg_prerm_prelink() {
175#!/bin/sh
176
177if [ "x$D" != "x" ]; then
178 exit 1
179fi
180
181prelink -au
182}
183