blob: b1261d594262f660435ce0dc03971cf0d31ef094 [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
39TARGET_OS_ORIG := "${TARGET_OS}"
40OVERRIDES_append = ":${TARGET_OS_ORIG}"
41
Patrick Williamsf1e5d692016-03-30 15:21:19 -050042S = "${WORKDIR}/git"
Patrick Williamsc124f4f2015-09-15 14:41:29 -050043
44inherit autotools
45
46BBCLASSEXTEND = "native"
47
48EXTRA_OECONF = "--disable-selinux --with-pkgversion=${PV}-${PR} \
49 --with-bugurl=http://bugzilla.yoctoproject.org/"
50
Patrick Williamsc0f7c042017-02-23 20:41:17 -060051
52#
53# For target prelink we need to ensure paths match the lib path layout
54# including for any configured multilibs
55#
56python do_linkerpaths () {
57 values = all_multilib_tune_list(["TUNE_ARCH", "baselib", "ABIEXTENSION"], d)
58
59 arches = values["TUNE_ARCH"]
60 baselibs = values["baselib"]
61 abis = values["ABIEXTENSION"]
62
63 def replace_lines(f, search, replacement, d, firstonly = False, secondonly = False):
64 f = d.expand(f)
65 if search == replacement:
66 return
67 bb.debug(2, "Replacing %s with %s in %s" % (search, replacement, f))
68 with open(f, "r") as data:
69 lines = data.readlines()
70 with open(f, "w") as data:
71 for line in lines:
72 if not secondonly and not firstonly:
73 line = line.replace(search, replacement)
74 elif secondonly and search in line:
75 secondonly = False
76 elif firstonly and search and search in line:
77 line = line.replace(search, replacement)
78 search = None
79 data.write(line)
80
81 def replace_lines_rtld(f, search, replacement, section, d):
82 f = d.expand(f)
83 bb.debug(2, "Replacing %s with %s in %s" % (search, replacement, f))
84 with open(f, "r") as data:
85 lines = data.readlines()
86 found = False
87 found2 = False
88 with open(f, "w") as data:
89 for line in lines:
90 if section in line:
91 if section == "else" and "if" in line:
92 found = False
93 else:
94 found = True
95 if found and "dst_LIB =" in line:
96 found2 = True
97 elif "}" in line:
98 found = False
99 found2 = False
100 if found2:
101 line = line.replace(search, replacement)
102 data.write(line)
103
104 for i, arch in enumerate(arches):
105 tune_baselib = baselibs[i]
106 abi = abis[i]
107
108 bits = 32
109 if arch == "powerpc":
110 replace_lines("${S}/src/arch-ppc.c", "/lib/ld.so.1", "/" + tune_baselib + "/ld.so.1", d)
111 elif arch == "powerpc64":
112 replace_lines("${S}/src/arch-ppc64.c", "/lib64/ld64.so.1", "/" + tune_baselib + "/ld64.so.1", d)
113 bits = 64
114 elif arch == "x86_64":
115 if abi == "x32":
116 replace_lines("${S}/src/arch-x86_64.c", "/libx32/ld-linux-x32.so.2", "/" + tune_baselib + "/ld-linux-x32.so.2", d)
117 else:
118 replace_lines("${S}/src/arch-x86_64.c", "/lib64/ld-linux-x86-64.so.2", "/" + tune_baselib + "/ld-linux-x86-64.so.2", d)
119 bits = 64
120 elif arch == "arm":
121 replace_lines("${S}/src/arch-arm.c", "/lib/ld-linux.so.3", "/" + tune_baselib + "/ld-linux.so.3", d)
122 replace_lines("${S}/src/arch-arm.c", "/lib/ld-linux-armhf.so.3", "/" + tune_baselib + "/ld-linux-armhf.so.3", d)
123 elif arch == "mips" or arch == "mipsel":
124 replace_lines("${S}/src/arch-mips.c", "/lib/ld.so.1", "/" + tune_baselib + "/ld.so.1", d, firstonly=True)
125 replace_lines("${S}/src/arch-mips.c", "/lib32/ld.so.1", "/" + tune_baselib + "/ld.so.1", d)
126 elif arch == "mips64" or arch == "mips64el":
127 replace_lines("${S}/src/arch-mips.c", "/lib/ld.so.1", "/" + tune_baselib + "/ld.so.1", d, secondonly=True)
128 replace_lines("${S}/src/arch-mips.c", "/lib64/ld.so.1", "/" + tune_baselib + "/ld.so.1", d)
129 bits = 64
130 elif arch.endswith("86"):
131 replace_lines("${S}/src/arch-i386.c", "/lib/ld-linux.so.2", "/" + tune_baselib + "/ld-linux.so.2", d)
132 if bits == 32 and tune_baselib != "lib":
133 replace_lines_rtld("${S}/src/rtld/rtld.c", "lib", tune_baselib, "else", d)
134 if bits == 64 and tune_baselib != "lib64":
135 replace_lines_rtld("${S}/src/rtld/rtld.c", "lib64", tune_baselib, "use_64bit", d)
136}
137
138python () {
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500139 overrides = d.getVar("OVERRIDES").split(":")
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600140 if "class-target" in overrides:
141 bb.build.addtask('do_linkerpaths', 'do_configure', 'do_patch', d)
142}
143
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500144do_configure_prepend () {
145 # Disable documentation!
146 echo "all:" > ${S}/doc/Makefile.am
147}
148
149do_install_append () {
150 install -d ${D}${sysconfdir}/cron.daily ${D}${sysconfdir}/default ${D}${sysconfdir}/rpm
151 install -m 0644 ${WORKDIR}/prelink.conf ${D}${sysconfdir}/prelink.conf
152 install -m 0644 ${WORKDIR}/prelink.cron.daily ${D}${sysconfdir}/cron.daily/prelink
153 install -m 0644 ${WORKDIR}/prelink.default ${D}${sysconfdir}/default/prelink
154 install -m 0644 ${WORKDIR}/macros.prelink ${D}${sysconfdir}/rpm/macros.prelink
155}
156
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500157# If we ae doing a cross install, we want to avoid prelinking.
158# Prelinking during a cross install should be handled by the image-prelink
159# bbclass. If the user desires this to run on the target at first boot
160# they will need to create a custom boot script.
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500161pkg_postinst_prelink() {
162#!/bin/sh
163
164if [ "x$D" != "x" ]; then
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500165 exit 0
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500166fi
167
168prelink -a
169}
170
171pkg_prerm_prelink() {
172#!/bin/sh
173
174if [ "x$D" != "x" ]; then
175 exit 1
176fi
177
178prelink -au
179}
180