Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1 | SECTION = "devel" |
| 2 | # Need binutils for libiberty.a |
| 3 | # Would need transfig-native for documentation if it wasn't disabled |
| 4 | DEPENDS = "elfutils binutils" |
| 5 | SUMMARY = "An ELF prelinking utility" |
| 6 | DESCRIPTION = "The prelink package contains a utility which modifies ELF shared libraries \ |
| 7 | and executables, so that far fewer relocations need to be resolved at \ |
| 8 | runtime and thus programs come up faster." |
| 9 | LICENSE = "GPLv2" |
| 10 | LIC_FILES_CHKSUM = "file://COPYING;md5=c93c0550bd3173f4504b2cbd8991e50b" |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame^] | 11 | SRCREV = "ef20628dd78b92e1a3123afc67b64cf010bdd9e4" |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 12 | PV = "1.0+git${SRCPV}" |
| 13 | |
| 14 | # |
| 15 | # The cron script attempts to re-prelink the system daily -- on |
| 16 | # systems where users are adding applications, this might be reasonable |
| 17 | # but for embedded, we should be re-running prelink -a after an update. |
| 18 | # |
| 19 | # Default is prelinking is enabled. |
| 20 | # |
| 21 | SUMMARY_${PN}-cron = "Cron scripts to control automatic prelinking" |
| 22 | DESCRIPTION_${PN}-cron = "Cron scripts to control automatic prelinking. \ |
| 23 | See: ${sysconfdir}/cron.daily/prelink for configuration information." |
| 24 | |
| 25 | FILES_${PN}-cron = "${sysconfdir}/cron.daily ${sysconfdir}/default" |
| 26 | |
| 27 | PACKAGES =+ "${PN}-cron" |
| 28 | |
| 29 | SRC_URI = "git://git.yoctoproject.org/prelink-cross.git;branch=cross_prelink \ |
| 30 | file://prelink.conf \ |
| 31 | file://prelink.cron.daily \ |
| 32 | file://prelink.default \ |
| 33 | file://macros.prelink" |
| 34 | |
| 35 | TARGET_OS_ORIG := "${TARGET_OS}" |
| 36 | OVERRIDES_append = ":${TARGET_OS_ORIG}" |
| 37 | |
Patrick Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 38 | S = "${WORKDIR}/git" |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 39 | |
| 40 | inherit autotools |
| 41 | |
| 42 | BBCLASSEXTEND = "native" |
| 43 | |
| 44 | EXTRA_OECONF = "--disable-selinux --with-pkgversion=${PV}-${PR} \ |
| 45 | --with-bugurl=http://bugzilla.yoctoproject.org/" |
| 46 | |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame^] | 47 | |
| 48 | # |
| 49 | # For target prelink we need to ensure paths match the lib path layout |
| 50 | # including for any configured multilibs |
| 51 | # |
| 52 | python do_linkerpaths () { |
| 53 | values = all_multilib_tune_list(["TUNE_ARCH", "baselib", "ABIEXTENSION"], d) |
| 54 | |
| 55 | arches = values["TUNE_ARCH"] |
| 56 | baselibs = values["baselib"] |
| 57 | abis = values["ABIEXTENSION"] |
| 58 | |
| 59 | def replace_lines(f, search, replacement, d, firstonly = False, secondonly = False): |
| 60 | f = d.expand(f) |
| 61 | if search == replacement: |
| 62 | return |
| 63 | bb.debug(2, "Replacing %s with %s in %s" % (search, replacement, f)) |
| 64 | with open(f, "r") as data: |
| 65 | lines = data.readlines() |
| 66 | with open(f, "w") as data: |
| 67 | for line in lines: |
| 68 | if not secondonly and not firstonly: |
| 69 | line = line.replace(search, replacement) |
| 70 | elif secondonly and search in line: |
| 71 | secondonly = False |
| 72 | elif firstonly and search and search in line: |
| 73 | line = line.replace(search, replacement) |
| 74 | search = None |
| 75 | data.write(line) |
| 76 | |
| 77 | def replace_lines_rtld(f, search, replacement, section, d): |
| 78 | f = d.expand(f) |
| 79 | bb.debug(2, "Replacing %s with %s in %s" % (search, replacement, f)) |
| 80 | with open(f, "r") as data: |
| 81 | lines = data.readlines() |
| 82 | found = False |
| 83 | found2 = False |
| 84 | with open(f, "w") as data: |
| 85 | for line in lines: |
| 86 | if section in line: |
| 87 | if section == "else" and "if" in line: |
| 88 | found = False |
| 89 | else: |
| 90 | found = True |
| 91 | if found and "dst_LIB =" in line: |
| 92 | found2 = True |
| 93 | elif "}" in line: |
| 94 | found = False |
| 95 | found2 = False |
| 96 | if found2: |
| 97 | line = line.replace(search, replacement) |
| 98 | data.write(line) |
| 99 | |
| 100 | for i, arch in enumerate(arches): |
| 101 | tune_baselib = baselibs[i] |
| 102 | abi = abis[i] |
| 103 | |
| 104 | bits = 32 |
| 105 | if arch == "powerpc": |
| 106 | replace_lines("${S}/src/arch-ppc.c", "/lib/ld.so.1", "/" + tune_baselib + "/ld.so.1", d) |
| 107 | elif arch == "powerpc64": |
| 108 | replace_lines("${S}/src/arch-ppc64.c", "/lib64/ld64.so.1", "/" + tune_baselib + "/ld64.so.1", d) |
| 109 | bits = 64 |
| 110 | elif arch == "x86_64": |
| 111 | if abi == "x32": |
| 112 | replace_lines("${S}/src/arch-x86_64.c", "/libx32/ld-linux-x32.so.2", "/" + tune_baselib + "/ld-linux-x32.so.2", d) |
| 113 | else: |
| 114 | replace_lines("${S}/src/arch-x86_64.c", "/lib64/ld-linux-x86-64.so.2", "/" + tune_baselib + "/ld-linux-x86-64.so.2", d) |
| 115 | bits = 64 |
| 116 | elif arch == "arm": |
| 117 | replace_lines("${S}/src/arch-arm.c", "/lib/ld-linux.so.3", "/" + tune_baselib + "/ld-linux.so.3", d) |
| 118 | replace_lines("${S}/src/arch-arm.c", "/lib/ld-linux-armhf.so.3", "/" + tune_baselib + "/ld-linux-armhf.so.3", d) |
| 119 | elif arch == "mips" or arch == "mipsel": |
| 120 | replace_lines("${S}/src/arch-mips.c", "/lib/ld.so.1", "/" + tune_baselib + "/ld.so.1", d, firstonly=True) |
| 121 | replace_lines("${S}/src/arch-mips.c", "/lib32/ld.so.1", "/" + tune_baselib + "/ld.so.1", d) |
| 122 | elif arch == "mips64" or arch == "mips64el": |
| 123 | replace_lines("${S}/src/arch-mips.c", "/lib/ld.so.1", "/" + tune_baselib + "/ld.so.1", d, secondonly=True) |
| 124 | replace_lines("${S}/src/arch-mips.c", "/lib64/ld.so.1", "/" + tune_baselib + "/ld.so.1", d) |
| 125 | bits = 64 |
| 126 | elif arch.endswith("86"): |
| 127 | replace_lines("${S}/src/arch-i386.c", "/lib/ld-linux.so.2", "/" + tune_baselib + "/ld-linux.so.2", d) |
| 128 | if bits == 32 and tune_baselib != "lib": |
| 129 | replace_lines_rtld("${S}/src/rtld/rtld.c", "lib", tune_baselib, "else", d) |
| 130 | if bits == 64 and tune_baselib != "lib64": |
| 131 | replace_lines_rtld("${S}/src/rtld/rtld.c", "lib64", tune_baselib, "use_64bit", d) |
| 132 | } |
| 133 | |
| 134 | python () { |
| 135 | overrides = d.getVar("OVERRIDES", True).split(":") |
| 136 | if "class-target" in overrides: |
| 137 | bb.build.addtask('do_linkerpaths', 'do_configure', 'do_patch', d) |
| 138 | } |
| 139 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 140 | do_configure_prepend () { |
| 141 | # Disable documentation! |
| 142 | echo "all:" > ${S}/doc/Makefile.am |
| 143 | } |
| 144 | |
| 145 | do_install_append () { |
| 146 | install -d ${D}${sysconfdir}/cron.daily ${D}${sysconfdir}/default ${D}${sysconfdir}/rpm |
| 147 | install -m 0644 ${WORKDIR}/prelink.conf ${D}${sysconfdir}/prelink.conf |
| 148 | install -m 0644 ${WORKDIR}/prelink.cron.daily ${D}${sysconfdir}/cron.daily/prelink |
| 149 | install -m 0644 ${WORKDIR}/prelink.default ${D}${sysconfdir}/default/prelink |
| 150 | install -m 0644 ${WORKDIR}/macros.prelink ${D}${sysconfdir}/rpm/macros.prelink |
| 151 | } |
| 152 | |
| 153 | # If we're using image-prelink, we want to skip this on the host side |
| 154 | # but still do it if the package is installed on the target... |
| 155 | pkg_postinst_prelink() { |
| 156 | #!/bin/sh |
| 157 | |
| 158 | if [ "x$D" != "x" ]; then |
| 159 | ${@bb.utils.contains('USER_CLASSES', 'image-prelink', 'exit 0', 'exit 1', d)} |
| 160 | fi |
| 161 | |
| 162 | prelink -a |
| 163 | } |
| 164 | |
| 165 | pkg_prerm_prelink() { |
| 166 | #!/bin/sh |
| 167 | |
| 168 | if [ "x$D" != "x" ]; then |
| 169 | exit 1 |
| 170 | fi |
| 171 | |
| 172 | prelink -au |
| 173 | } |
| 174 | |