summaryrefslogtreecommitdiffstats
path: root/meta/recipes-devtools/rpm/rpm_5.4.16.bb
blob: d264d5011a92196d209a2bb21aead5a2dccc069d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162

@media only all and (prefers-color-scheme: dark) {
.highlight .hll { background-color: #49483e }
.highlight .c { color: #75715e } /* Comment */
.highlight .err { color: #960050; background-color: #1e0010 } /* Error */
.highlight .k { color: #66d9ef } /* Keyword */
.highlight .l { color: #ae81ff } /* Literal */
.highlight .n { color: #f8f8f2 } /* Name */
.highlight .o { color: #f92672 } /* Operator */
.highlight .p { color: #f8f8f2 } /* Punctuation */
.highlight .ch { color: #75715e } /* Comment.Hashbang */
.highlight .cm { color: #75715e } /* Comment.Multiline */
.highlight .cp { color: #75715e } /* Comment.Preproc */
.highlight .cpf { color: #75715e } /* Comment.PreprocFile */
.highlight .c1 { color: #75715e } /* Comment.Single */
.highlight .cs { color: #75715e } /* Comment.Special */
.highlight .gd { color: #f92672 } /* Generic.Deleted */
.highlight .ge { font-style: italic } /* Generic.Emph */
.highlight .gi { color: #a6e22e } /* Generic.Inserted */
.highlight .gs { font-weight: bold } /* Generic.Strong */
.highlight .gu { color: #75715e } /* Generic.Subheading */
.highlight .kc { color: #66d9ef } /* Keyword.Constant */
.highlight .kd { color: #66d9ef } /* Keyword.Declaration */
.highlight .kn { color: #f92672 } /* Keyword.Namespace */
.highlight .kp { color: #66d9ef } /* Keyword.Pseudo */
.highlight .kr { color: #66d9ef } /* Keyword.Reserved */
.highlight .kt { color: #66d9ef } /* Keyword.Type */
.highlight .ld { color: #e6db74 } /* Literal.Date */
.highlight .m { color: #ae81ff } /* Literal.Number */
.highlight .s { color: #e6db74 } /* Literal.String */
.highlight .na { color: #a6e22e } /* Name.Attribute */
.highlight .nb { color: #f8f8f2 } /* Name.Builtin */
.highlight .nc { color: #a6e22e } /* Name.Class */
.highlight .no { color: #66d9ef } /* Name.Constant */
.highlight .nd { color: #a6e22e } /* Name.Decorator */
.highlight .ni { color: #f8f8f2 } /* Name.Entity */
.highlight .ne { color: #a6e22e } /* Name.Exception */
.highlight .nf { color: #a6e22e } /* Name.Function */
.highlight .nl { color: #f8f8f2 } /* Name.Label */
.highlight .nn { color: #f8f8f2 } /* Name.Namespace */
.highlight .nx { color: #a6e22e } /* Name.Other */
.highlight .py { color: #f8f8f2 } /* Name.Property */
.highlight .nt { color: #f92672 } /* Name.Tag */
.highlight .nv { color: #f8f8f2 } /* Name.Variable */
.highlight .ow { color: #f92672 } /* Operator.Word */
.highlight .w { color: #f8f8f2 } /* Text.Whitespace */
.highlight .mb { color: #ae81ff } /* Literal.Number.Bin */
.highlight .mf { color: #ae81ff } /* Literal.Number.Float */
.highlight .mh { color: #ae81ff } /* Literal.Number.Hex */
.highlight .mi { color: #ae81ff } /* Literal.Number.Integer */
.highlight .mo { color: #ae81ff } /* Literal.Number.Oct */
.highlight .sa { color: #e6db74 } /* Literal.String.Affix */
.highlight .sb { color: #e6db74 } /* Literal.String.Backtick */
.highlight .sc { color: #e6db74 } /* Literal.String.Char */
.highlight .dl { color: #e6db74 } /* Literal.String.Delimiter */
.highlight .sd { color: #e6db74 } /* Literal.String.Doc */
.highlight .s2 { color: #e6db74 } /* Literal.String.Double */
.highlight .se { color: #ae81ff } /* Literal.String.Escape */
.highlight .sh { color: #e6db74 } /* Literal.String.Heredoc */
.highlight .si { color: #e6db74 } /* Literal.String.Interpol */
.highlight .sx { color: #e6db74 } /* Literal.String.Other */
.highlight .sr { color: #e6db74 } /* Literal.String.Regex */
.highlight .s1 { color: #e6db74 } /* Literal.String.Single */
.highlight .ss { color: #e6db74 } /* Literal.String.Symbol */
.highlight .bp { color: #f8f8f2 } /* Name.Builtin.Pseudo */
.highlight .fm { color: #a6e22e } /* Name.Function.Magic */
.highlight .vc { color: #f8f8f2 } /* Name.Variable.Class */
.highlight .vg { color: #f8f8f2 } /* Name.Variable.Global */
.highlight .vi { color: #f8f8f2 } /* Name.Variable.Instance */
.highlight .vm { color: #f8f8f2 } /* Name.Variable.Magic */
.highlight .il { color: #ae81ff } /* Literal.Number.Integer.Long */
}
@media (prefers-color-scheme: light) {
.highlight .hll { background-color: #ffffcc }
.highlight .c { color: #888888 } /* Comment */
.highlight .err { color: #a61717; background-color: #e3d2d2 } /* Error */
.highlight .k { color: #008800; font-weight: bold } /* Keyword */
.highlight .ch { color: #888888 } /* Comment.Hashbang */
.highlight .cm { color: #888888 } /* Comment.Multiline */
.highlight .cp { color: #cc0000; font-weight: bold } /* Comment.Preproc */
.highlight .cpf { color: #888888 } /* Comment.PreprocFile */
.highlight .c1 { color: #888888 } /* Comment.Single */
.highlight .cs { color: #cc0000; font-weight: bold; background-color: #fff0f0 } /* Comment.Special */
.highlight .gd { color: #000000; background-color: #ffdddd } /* Generic.Deleted */
.highlight .ge { font-style: italic } /* Generic.Emph */
.highlight .gr { color: #aa0000 } /* Generic.Error */
.highlight .gh { color: #333333 } /* Generic.Heading */
.highlight .gi { color: #000000; background-color: #ddffdd } /* Generic.Inserted */
.highlight .go { color: #888888 } /* Generic.Output */
.highlight .gp { color: #555555 } /* Generic.Prompt */
.highlight .gs { font-weight: bold } /* Generic.Strong */
.highlight .gu { color: #666666 } /* Generic.Subheading */
.highlight .gt { color: #aa0000 } /* Generic.Traceback */
.highlight .kc { color: #008800; font-weight: bold } /* Keyword.Constant */
.highlight .kd { color: #008800; font-weight: bold } /* Keyword.Declaration */
.highlight .kn { color: #008800; font-weight: bold } /* Keyword.Namespace */
.highlight .kp { color: #008800 } /* Keyword.Pseudo */
.highlight .kr { color: #008800; font-weight: bold } /* Keyword.Reserved */
.highlight .kt { color: #888888; font-weight: bold } /* Keyword.Type */
.highlight .m { color: #0000DD; font-weight: bold } /* Literal.Number */
.highlight .s { color: #dd2200; background-color: #fff0f0 } /* Literal.String */
.highlight .na { color: #336699 } /* Name.Attribute */
.highlight .nb { color: #003388 } /* Name.Builtin */
.highlight .nc { color: #bb0066; font-weight: bold } /* Name.Class */
.highlight .no { color: #003366; font-weight: bold } /* Name.Constant */
.highlight .nd { color: #555555 } /* Name.Decorator */
.highlight .ne { color: #bb0066; font-weight: bold } /* Name.Exception */
.highlight .nf { color: #0066bb; font-weight: bold } /* Name.Function */
.highlight .nl { color: #336699; font-style: italic } /* Name.Label */
.highlight .nn { color: #bb0066; font-weight: bold } /* Name.Namespace */
.highlight .py { color: #336699; font-weight: bold } /* Name.Property */
.highlight .nt { color: #bb0066; font-weight: bold } /* Name.Tag */
.highlight .nv { color: #336699 } /* Name.Variable */
.highlight .ow { color: #008800 } /* Operator.Word */
.highlight .w { color: #bbbbbb } /* Text.Whitespace */
.highlight .mb { color: #0000DD; font-weight: bold } /* Literal.Number.Bin */
.highlight .mf { color: #0000DD; font-weight: bold } /* Literal.Number.Float */
.highlight .mh { color: #0000DD; font-weight: bold } /* Literal.Number.Hex */
.highlight .mi { color: #0000DD; font-weight: bold } /* Literal.Number.Integer */
.highlight .mo { color: #0000DD; font-weight: bold } /* Literal.Number.Oct */
.highlight .sa { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Affix */
.highlight .sb { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Backtick */
.highlight .sc { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Char */
.highlight .dl { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Delimiter */
.highlight .sd { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Doc */
.highlight .s2 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Double */
.highlight .se { color: #0044dd; background-color: #fff0f0 } /* Literal.String.Escape */
.highlight .sh { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Heredoc */
.highlight .si { color: #3333bb; background-color: #fff0f0 } /* Literal.String.Interpol */
.highlight .sx { color: #22bb22; background-color: #f0fff0 } /* Literal.String.Other */
.highlight .sr { color: #008800; background-color: #fff0ff } /* Literal.String.Regex */
.highlight .s1 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Single */
.highlight .ss { color: #aa6600; background-color: #fff0f0 } /* Literal.String.Symbol */
.highlight .bp { color: #003388 } /* Name.Builtin.Pseudo */
.highlight .fm { color: #0066bb; font-weight: bold } /* Name.Function.Magic */
.highlight .vc { color: #336699 } /* Name.Variable.Class */
.highlight .vg { color: #dd7700 } /* Name.Variable.Global */
.highlight .vi { color: #3333bb } /* Name.Variable.Instance */
.highlight .vm { color: #336699 } /* Name.Variable.Magic */
.highlight .il { color: #0000DD; font-weight: bold } /* Literal.Number.Integer.Long */
}
# Copyright (C) 2006  OpenedHand LTD

# Point to an empty file so any user's custom settings don't break things
QUILTRCFILE ?= "${STAGING_ETCDIR_NATIVE}/quiltrc"

PATCHDEPENDENCY = "${PATCHTOOL}-native:do_populate_sysroot"

PATCH_GIT_USER_NAME ?= "OpenEmbedded"
PATCH_GIT_USER_EMAIL ?= "oe.patch@oe"

inherit terminal

python () {
    if d.getVar('PATCHTOOL') == 'git' and d.getVar('PATCH_COMMIT_FUNCTIONS') == '1':
        tasks = list(filter(lambda k: d.getVarFlag(k, "task"), d.keys()))
        extratasks = []
        def follow_chain(task, endtask, chain=None):
            if not chain:
                chain = []
            chain.append(task)
            for othertask in tasks:
                if othertask == task:
                    continue
                if task == endtask:
                    for ctask in chain:
                        if ctask not in extratasks:
                            extratasks.append(ctask)
                else:
                    deps = d.getVarFlag(othertask, 'deps', False)
                    if task in deps:
                        follow_chain(othertask, endtask, chain)
            chain.pop()
        follow_chain('do_unpack', 'do_patch')
        try:
            extratasks.remove('do_unpack')
        except ValueError:
            # For some recipes do_unpack doesn't exist, ignore it
            pass

        d.appendVarFlag('do_patch', 'prefuncs', ' patch_task_patch_prefunc')
        for task in extratasks:
            d.appendVarFlag(task, 'postfuncs', ' patch_task_postfunc')
}

python patch_task_patch_prefunc() {
    # Prefunc for do_patch
    func = d.getVar('BB_RUNTASK')
    srcsubdir = d.getVar('S')

    patchdir = os.path.join(srcsubdir, 'patches')
    if os.path.exists(patchdir):
        if os.listdir(patchdir):
            d.setVar('PATCH_HAS_PATCHES_DIR', '1')
        else:
            os.rmdir(patchdir)
}

python patch_task_postfunc() {
    # Prefunc for task functions between do_unpack and do_patch
    import oe.patch
    import shutil
    func = d.getVar('BB_RUNTASK')
    srcsubdir = d.getVar('S')

    if os.path.exists(srcsubdir):
        if func == 'do_patch':
            haspatches = (d.getVar('PATCH_HAS_PATCHES_DIR') == '1')
            patchdir = os.path.join(srcsubdir, 'patches')
            if os.path.exists(patchdir):
                shutil.rmtree(patchdir)
                if haspatches:
                    stdout, _ = bb.process.run('git status --porcelain patches', cwd=srcsubdir)
                    if stdout:
                        bb.process.run('git checkout patches', cwd=srcsubdir)
        stdout, _ = bb.process.run('git status --porcelain .', cwd=srcsubdir)
        if stdout:
            useroptions = []
            oe.patch.GitApplyTree.gitCommandUserOptions(useroptions, d=d)
            bb.process.run('git add .; git %s commit -a -m "Committing changes from %s\n\n%s"' % (' '.join(useroptions), func, oe.patch.GitApplyTree.ignore_commit_prefix + ' - from %s' % func), cwd=srcsubdir)
}

def src_patches(d, all=False, expand=True):
    import oe.patch
    return oe.patch.src_patches(d, all, expand)

def should_apply(parm, d):
    """Determine if we should apply the given patch"""
    import oe.patch
    return oe.patch.should_apply(parm, d)

should_apply[vardepsexclude] = "DATE SRCDATE"

python patch_do_patch() {
    import oe.patch

    patchsetmap = {
        "patch": oe.patch.PatchTree,
        "quilt": oe.patch.QuiltTree,
        "git": oe.patch.GitApplyTree,
    }

    cls = patchsetmap[d.getVar('PATCHTOOL') or 'quilt']

    resolvermap = {
        "noop": oe.patch.NOOPResolver,
        "user": oe.patch.UserResolver,
    }

    rcls = resolvermap[d.getVar('PATCHRESOLVE') or 'user']

    classes = {}

    s = d.getVar('S')

    os.putenv('PATH', d.getVar('PATH'))

    # We must use one TMPDIR per process so that the "patch" processes
    # don't generate the same temp file name.

    import tempfile
    process_tmpdir = tempfile.mkdtemp()
    os.environ['TMPDIR'] = process_tmpdir

    for patch in src_patches(d):
        _, _, local, _, _, parm = bb.fetch.decodeurl(patch)

        if "patchdir" in parm:
            patchdir = parm["patchdir"]
            if not os.path.isabs(patchdir):
                patchdir = os.path.join(s, patchdir)
        else:
            patchdir = s

        if not patchdir in classes:
            patchset = cls(patchdir, d)
            resolver = rcls(patchset, oe_terminal)
            classes[patchdir] = (patchset, resolver)
            patchset.Clean()
        else:
            patchset, resolver = classes[patchdir]

        bb.note("Applying patch '%s' (%s)" % (parm['patchname'], oe.path.format_display(local, d)))
        try:
            patchset.Import({"file":local, "strippath": parm['striplevel']}, True)
        except Exception as exc:
            bb.utils.remove(process_tmpdir, True)
            bb.fatal(str(exc))
        try:
            resolver.Resolve()
        except bb.BBHandledException as e:
            bb.utils.remove(process_tmpdir, True)
            bb.fatal(str(e))

    bb.utils.remove(process_tmpdir, True)
    del os.environ['TMPDIR']
}
patch_do_patch[vardepsexclude] = "PATCHRESOLVE"

addtask patch after do_unpack
do_patch[dirs] = "${WORKDIR}"
do_patch[depends] = "${PATCHDEPENDENCY}"

EXPORT_FUNCTIONS do_patch
id='n606' href='#n606'>606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742
SUMMARY = "The RPM package management system"
DESCRIPTION = "The RPM Package Manager (RPM) is a powerful command line driven \
package management system capable of installing, uninstalling, \
verifying, querying, and updating software packages. Each software \
package consists of an archive of files along with information about \
the package like its version, a description, etc."

SUMMARY_${PN}-libs = "Libraries for manipulating RPM packages"
DESCRIPTION_${PN}-libs = "This package contains the RPM shared libraries."

SUMMARY_${PN}-dev = "Development files for manipulating RPM packages"
DESCRIPTION_${PN}-dev = "This package contains the RPM C library and header files. These \
development files will simplify the process of writing programs that \
manipulate RPM packages and databases. These files are intended to \
simplify the process of creating graphical package managers or any \
other tools that need an intimate knowledge of RPM packages in order \
to function."

SUMMARY_${PN}-common = "Common RPM paths, scripts, documentation and configuration"
DESCRIPTION_${PN}-common = "The rpm-common package contains paths, scripts, documentation \
and configuration common between RPM Package Manager."

SUMMARY_${PN}-build = "Scripts and executable programs used to build packages"
DESCRIPTION_${PN}-build = "The rpm-build packagec ontains the scripts and executable programs \
that are used to build packages using the RPM Package Manager."

SUMMARY_python-rpm = "Python bindings for apps which will manupulate RPM packages"
DESCRIPTION_python-rpm = "The rpm-python package contains a module that permits applications \
written in the Python programming language to use the interface \
supplied by the RPM Package Manager libraries."

SUMMARY_perl-module-rpm = "Perl bindings for apps which will manipulate RPM packages"
DESCRIPTION_perl-modules-rpm = "The perl-modules-rpm package contains a module that permits applications \
written in the Perl programming language to use the interface \
supplied by the RPM Package Manager libraries."

HOMEPAGE = "http://rpm5.org/"
LICENSE = "LGPLv2.1 & Apache-2.0"
LIC_FILES_CHKSUM = "file://COPYING.LIB;md5=2d5025d4aa3495befef8f17206a5b0a1"
LIC_FILES_CHKSUM += "file://rpmio/mongo.c;begin=5;end=18;md5=d8327ba2c71664c059143e6d333b8901"

# We must have gettext-native, we need gettextize, which may not be provided
DEPENDS = "libpcre attr acl ossp-uuid file byacc-native gettext-native"
DEPENDS_append_class-native = " file-replacement-native"

# rpm2cpio is a shell script, which is part of the rpm src.rpm.  It is needed
# in order to extract the distribution SRPM into a format we can extract...

# There is no official 5.4.16 release yet, so start w/ 5.4.15 and patch it
# based on CVS
S = "${WORKDIR}/rpm-5.4.15"

SRC_URI = "http://www.rpm5.org/files/rpm/rpm-5.4/rpm-5.4.15-0.20140824.src.rpm;name=srpm;extract=rpm-5.4.15.tar.gz \
	   http://downloads.yoctoproject.org/releases/rpm5/rpm-5.4.15-to-5.4.16-20160225.patch.gz;name=rpm-patch \
	   http://downloads.yoctoproject.org/releases/rpm5/syck-5.4.15-to-5.4.16-20160225.patch.gz;name=syck-patch \
	   http://downloads.yoctoproject.org/releases/rpm5/beecrypt-5.4.15-to-5.4.16-20160225.patch.gz;name=beecrypt-patch \
	   http://downloads.yoctoproject.org/releases/rpm5/lua-5.4.15-to-5.4.16-20160225.patch.gz;name=lua-patch \
	   file://perfile_rpmdeps.sh \
	   file://pythondeps.sh \
"

SRC_URI[srpm.md5sum] = "d53782842ac11b3100a43fb2958c9bc0"
SRC_URI[srpm.sha256sum] = "d4ae5e9ed5df8ab9931b660f491418d20ab5c4d72eb17ed9055b80b71ef6c4ee"

SRC_URI[rpm-patch.md5sum] = "8b7deb1c9574d3d47ed8ba8c690fd8bf"
SRC_URI[rpm-patch.sha256sum] = "1c1983d001b04eaa23eb2c8d9598b9d0899acb0a89f54a2d4c4e974086fd17a5"

SRC_URI[syck-patch.md5sum] = "f31d7a32105a364688354419ec3559e4"
SRC_URI[syck-patch.sha256sum] = "4dd1d04489206d8b5d1970f2a8d143a002f2895cefbe15d73459785096545e8a"

SRC_URI[beecrypt-patch.md5sum] = "9e71ee3ccb0a52985a071dd250279132"
SRC_URI[beecrypt-patch.sha256sum] ="df7c0708a7fab9bdf6d46194519b42e736f99cb0599dcc1c3c1bf1b228705cde"

SRC_URI[lua-patch.md5sum] = "ca10d03d83b1fc1c31a0b50819534cd7"
SRC_URI[lua-patch.sha256sum] = "6bde435cc827a7d4b2520e8f3e1c9bd2ca74375de0a4402aa99ef4d48eab9a7e"

# Bug fixes
SRC_URI += " \
	   file://header-include-fix.patch \
	   file://rpm-libsql-fix.patch \
	   file://rpm-platform.patch \
	   file://rpm-platform2.patch \
	   file://rpm-tools-mtree-LDFLAGS.patch \
	   file://rpm-canonarch.patch \
	   file://rpm-no-loopmsg.patch \
	   file://rpm-resolvedep.patch \
	   file://rpm-packageorigin.patch \
	   file://uclibc-support.patch \
	   file://rpmatch.patch \
	   file://makefile-am-exec-hook.patch \
	   file://python-rpm-rpmsense.patch \
	   file://debugedit-segv.patch \
	   file://debugedit-valid-file-to-fix-segment-fault.patch \
	   file://rpm-platform-file-fix.patch \
	   file://rpm-lsb-compatibility.patch \
	   file://rpm-tag-generate-endian-conversion-fix.patch \
	   file://rpm-hardlink-segfault-fix.patch \
	   file://rpm-payload-use-hashed-inode.patch \
	   file://rpm-fix-logio-cp.patch \
	   file://0001-using-poptParseArgvString-to-parse-the-_gpg_check_pa.patch \
	   file://rpm-opendb-before-verifyscript-to-avoid-null-point.patch \
	   file://0001-define-EM_AARCH64.patch \
	   file://rpm-rpmfc.c-fix-for-N32-MIPS64.patch \
	   file://rpm-lib-transaction.c-fix-file-conflicts-for-mips64-N32.patch \
	   file://rpm-mongodb-sasl.patch \
	   file://rpm-fix-parseEmbedded.patch \
	   file://rpm-rpmio-headers.patch \
	   file://rpm-python-restore-origin.patch \
	   file://rpm-keccak-sse-intrin.patch \
	   file://rpm-atomic-ops.patch \
	   file://rpm-gnu-atomic.patch \
	   file://rpm-tagname-type.patch \
	   file://rpm-python-tagname.patch \
	   file://rpm-python-AddErase.patch \
	   file://rpm-rpmpgp-popt.patch \
	   file://rpm-fix-lua-tests-compilation-failure.patch \
	   file://rpmqv.c-check-_gpg_passphrase-before-ask-for-input.patch \
	   file://0001-Disable-__sync_add_and_fetch_8-on-nios2.patch \
	   file://gcc6-stdlib.patch \
	   file://0001-system.h-query.c-support-nosignature.patch \
"

# OE specific changes
SRC_URI += " \
	   file://rpm-log-auto-rm.patch \
	   file://rpm-db-reduce.patch \
	   file://rpm-autogen.patch \
	   file://rpm-showrc.patch \
	   file://rpm-fileclass.patch \
	   file://rpm-scriptletexechelper.patch \
	   file://rpmdeps-oecore.patch \
	   file://rpm-no-perl-urpm.patch \
	   file://rpm-macros.patch \
	   file://rpm-lua.patch \
	   file://rpm-ossp-uuid.patch \
	   file://rpm-uuid-include.patch \
	   file://rpm-pkgconfigdeps.patch \
	   file://no-ldflags-in-pkgconfig.patch \
	   file://dbconvert.patch \
	   file://rpm-db_buffer_small.patch \
	   file://rpm-py-init.patch \
	   file://rpm-reloc-macros.patch \
	   file://rpm-db5-or-db6.patch \
	   file://rpm-db60.patch \
	   file://rpmqv_cc_b_gone.patch \
	   file://rpm-realpath.patch \
	   file://rpm-check-rootpath-reasonableness.patch \
	   file://rpm-macros.in-disable-external-key-server.patch \
	   file://configure.ac-check-for-both-gpg2-and-gpg.patch \
	   file://rpm-disable-auto-stack-protector.patch \
	   file://popt-disable-auto-stack-protector.patch \
	   file://rpm-syck-fix-gram.patch \
	   file://rpm-rpmdb-grammar.patch \
	   file://rpm-disable-blaketest.patch \
	   file://rpm-autogen-force.patch \
	   file://rpmdb-more-verbose-error-logging-in-rpmTempFile.patch \
"

SRC_URI_append_libc-musl = "\
           file://0001-rpm-Fix-build-on-musl.patch \
"
# Uncomment the following line to enable platform score debugging
# This is useful when identifying issues with Smart being unable
# to process certain package feeds.
#SRC_URI += "file://rpm-debug-platform.patch"

UPSTREAM_CHECK_REGEX = "rpm-(?P<pver>(\d+[\.\-_]*)+)-.*$"

inherit autotools gettext python-dir

acpaths = "-I ${S}/db/dist/aclocal -I ${S}/db/dist/aclocal_java"

# The local distribution macro directory
distromacrodir = "${libdir}/rpm/poky"

# Specify the default rpm macros in terms of adjustable variables
rpm_macros = "%{_usrlibrpm}/macros:%{_usrlibrpm}/${DISTRO}/macros:%{_usrlibrpm}/${DISTRO}/%{_target}/macros:%{_etcrpm}/macros.*:%{_etcrpm}/macros:%{_etcrpm}/%{_target}/macros:~/.oerpmmacros"
rpm_macros_class-native = "%{_usrlibrpm}/macros:%{_usrlibrpm}/${DISTRO}/macros:%{_usrlibrpm}/${DISTRO}/%{_target}/macros:~/.oerpmmacros"
rpm_macros_class-nativesdk = "%{_usrlibrpm}/macros:%{_usrlibrpm}/${DISTRO}/macros:%{_usrlibrpm}/${DISTRO}/%{_target}/macros:~/.oerpmmacros"

# sqlite lua tcl augeas nss gcrypt neon xz xar keyutils perl selinux

# Set the digest algorithm used for verifying file integrity
# If this value changes, and two different packages have different values
# the "same file" validation (two packages have a non-conflict file)
# will fail.  This may lead to upgrade problems.  You should treat this
# value as a distribution wide setting, and only change it when you intend
# a full system upgrade!
#
# Defined file digest algorithm values (note: not all are available!):
#       1       MD5 (legacy RPM default)
#       2       SHA1
#       3       RIPEMD-160
#       5       MD2
#       6       TIGER-192
#       8       SHA256
#       9       SHA384
#       10      SHA512
#       11      SHA224
#       104     MD4
#       105     RIPEMD-128
#       106     CRC-32
#       107     ADLER-32
#       108     CRC-64 (ECMA-182 polynomial, untested uint64_t problems)
#       109     Jenkins lookup3.c hashlittle()
#       111     RIPEMD-256
#       112     RIPEMD-320
#       188     BLAKE2B
#       189     BLAKE2BP
#       190     BLAKE2S
#       191     BLAKE2SP
RPM_FILE_DIGEST_ALGO ?= "1"

# All packages build with RPM5 contain a non-repudiable signature.
# The purpose of this signature is not to show authenticity of a package,
# but instead act as a secondary package wide validation that shows it
# wasn't damaged by accident in transport.  (When later you sign the package, 
# this signature may or may not be replaced as there are three signature 
# slots, one for DSA/RSA, one for ECSDA, and one reserved.)
#
# There is a known issue w/ RSA signatures that if they start with an 0x00
# the signing and validation may fail.
#
# The following is the list of choices for the non-rpudiable signature
# (note: not all of these are implemented):
#       DSA             (default)
#       RSA             (implies SHA1)
#       ECDSA           (implies SHA256)
#       DSA/SHA1
#       DSA/SHA224
#       DSA/SHA256
#       DSA/SHA384
#       DSA/SHA512
#       RSA/SHA1
#       RSA/SHA224
#       RSA/SHA256
#       RSA/SHA384
#       RSA/SHA512
#       ECDSA/SHA224    (using NIST P-224)
#       ECDSA/SHA256    (using NIST P-256)
#       ECDSA/SHA384    (using NIST P-384)
#       ECDSA/SHA512    (using NIST P-521)
RPM_SELF_SIGN_ALGO ?= "DSA"

# Note: perl and sqlite w/o db specified does not currently work.
#       tcl, augeas, nss, gcrypt, xar and keyutils support is untested.
PACKAGECONFIG ??= "db bzip2 zlib popt openssl libelf python"

# Note: switching to internal popt may not work, as it will generate
# a shared library which will intentionally not be packaged.
#
# If you intend to use the internal version, additional work may be required.
PACKAGECONFIG[popt] = "--with-popt=external,--with-popt=internal,popt,"

PACKAGECONFIG[bzip2] = "--with-bzip2,--without-bzip2,bzip2,"
PACKAGECONFIG[xz] = "--with-xz,--without-xz,xz,"
PACKAGECONFIG[zlib] = "--with-zlib,--without-zlib,zlib,"
PACKAGECONFIG[xar] = "--with-xar,--without-xar,xar,"

WITH_PYTHON = " --with-python=${PYTHON_BASEVERSION} \
		--with-python-inc-dir=${STAGING_INCDIR}/python${PYTHON_BASEVERSION} \
		--with-python-lib-dir=${libdir}/python${PYTHON_BASEVERSION}/site-packages \
		--without-pythonembed"
PACKAGECONFIG[python] = "${WITH_PYTHON},--without-python,python,"

# Perl modules are not built, but they could be enabled fairly easily
# the perl module creation and installation would need to be patched.
# (currently has host perl contamination issues)
WITH_PERL = "--with-perl --without-perlembed --without-perl-urpm"
WITHOUT_PERL = "--without-perl --without-perl-urpm"
PACKAGECONFIG[perl] = "${WITH_PERL},${WITHOUT_PERL},perl,"

# The --with-dbsql will only tell RPM to check for support, db
# may or may not be built w/ the dbsql support.
WITH_DB = "--with-db --with-dbsql --without-db-tools-integrated"
PACKAGECONFIG[db] = "${WITH_DB},--without-db,db,"

PACKAGECONFIG[sqlite] = "--with-sqlite,--without-sqlite,sqlite3,"

# This switch simply disables external beecrypt, RPM5 always uses beecrypt
# for base64 processing and various digest algorithms.
# Beecrypt is only the preferred crypto engine if it's the only engine enabled.
PACKAGECONFIG[beecrypt] = "--with-beecrypt=external,--with-beecrypt=internal,beecrypt,"

# --with-usecrypto= setting defined the item as the preferred system
# crypto engine, which will take priority over the included beecrypt
PACKAGECONFIG[openssl] = "--with-openssl --with-usecrypto=openssl,--without-openssl,openssl,"
PACKAGECONFIG[nss] = "--with-nss --with-usecrypto=nss,--without-nss,nss,"
PACKAGECONFIG[gcrypt] = "--with-gcrypt --with-usecrypto=gcrypt,--without-gcrypt,gcrypt,"

PACKAGECONFIG[keyutils] = "--with-keyutils,--without-keyutils,keyutils,"
PACKAGECONFIG[libelf] = "--with-libelf,--without-libelf,elfutils,"

WITH_SELINUX = "--with-selinux --with-sepol --with-semanage"
WITHOUT_SELINUX = "--without-selinux --without-sepol --without-semanage"
PACKAGECONFIG[selinux] = "${WITH_SELINUX},${WITHOUT_SELINUX},libselinux,"

WITH_NEON = "--with-neon --with-libproxy --with-expat --without-gssapi"
WITHOUT_NEON = "--without-neon --without-libproxy --without-expat --without-gssapi"
PACKAGECONFIG[neon] = "${WITH_NEON},${WITHOUT_NEON},neon expat,"

PACKAGECONFIG[lua] = "--with-lua,--without-lua,expat,"
PACKAGECONFIG[tcl] = "--with-tcl,--without-tcl,tcl,"

PACKAGECONFIG[augeas] = "--with-augeas,--without-augeas,augeas,"

EXTRA_OECONF += "--verbose \
		--sysconfdir=${sysconfdir} \
		--with-file \
		--with-path-magic=%{_usrlibrpm}/../../share/misc/magic.mgc \
		--with-syck=internal \
		--without-readline \
		--without-libtasn1 \
		--without-pakchois \
		--without-gnutls \
		--with-pcre \
		--enable-utf8 \
		--with-uuid \
		--with-attr \
		--with-acl \
		--with-pthreads \
		--without-cudf \
		--without-ficl \
		--without-aterm \
		--without-nix \
		--without-bash \
		--without-rc \
		--without-js \
		--without-gpsee \
		--without-ruby \
		--without-squirrel \
		--without-sasl2 \
		--without-tomcrypt \
		--with-build-extlibdep \
		--with-build-maxextlibdep \
		--without-valgrind \
		--disable-openmp \
		--enable-build-pic \
		--enable-build-versionscript \
		--enable-build-warnings \
		--enable-build-debug \
		--enable-maintainer-mode \
		--with-path-macros=${rpm_macros} \
		--with-path-lib=${libdir}/rpm \
		--with-bugreport=http://bugzilla.yoctoproject.org \
		--program-prefix= \
		YACC=byacc"

CFLAGS_append = " -DRPM_VENDOR_WINDRIVER -DRPM_VENDOR_POKY -DRPM_VENDOR_OE -D_GLIBCXX_INCLUDE_NEXT_C_HEADERS"

LDFLAGS_append_libc-uclibc = "-lrt -lpthread"

PACKAGES = "${PN}-dbg ${PN} ${PN}-doc ${PN}-libs ${PN}-dev ${PN}-staticdev ${PN}-common ${PN}-build python-rpm perl-module-rpm ${PN}-locale"

SOLIBS = "5.4.so"

# Based on %files section in the rpm.spec

FILES_${PN} =  "${bindir}/rpm \
		${bindir}/rpmconstant \
		${libdir}/rpm/rpm.* \
		${libdir}/rpm/tgpg \
		${libdir}/rpm/macros \
		${libdir}/rpm/rpmpopt \
		${libdir}/rpm/rpm2cpio \
		${libdir}/rpm/vcheck \
		${libdir}/rpm/helpers \
		${libdir}/rpm/qf \
		${libdir}/rpm/cpuinfo.yaml \
		${libdir}/rpm/bin/mtree \
		${libdir}/rpm/bin/rpmkey \
		${libdir}/rpm/bin/rpmrepo \
		${libdir}/rpm/bin/rpmrepo.real \
		${libdir}/rpm/bin/rpmspecdump \
		${libdir}/rpm/bin/rpmspecdump.real \
		${libdir}/rpm/bin/wget \
		${localstatedir}/cache \
		${localstatedir}/cache/rpm \
		${localstatedir}/cache/wdj \
		${localstatedir}/lib \
		${localstatedir}/lib/rpm \
		${localstatedir}/lib/wdj \
		${bindir}/rpm.real \
		${bindir}/rpmconstant.real \
		${bindir}/rpm2cpio.real \
		"

FILES_${PN}-common = "${bindir}/rpm2cpio \
		${bindir}/gendiff \
		${sysconfdir}/rpm \
		${localstatedir}/spool/repackage \
		"

FILES_${PN}-libs = "${libdir}/librpm-*.so \
		${libdir}/librpmconstant-*.so \
		${libdir}/librpmdb-*.so \
		${libdir}/librpmio-*.so \
		${libdir}/librpmmisc-*.so \
		${libdir}/librpmbuild-*.so \
		"

FILES_${PN}-build = "${prefix}/src/rpm \
		${bindir}/rpmbuild \
		${bindir}/rpmbuild.real \
		${libdir}/rpm/brp-* \
		${libdir}/rpm/check-files \
		${libdir}/rpm/cross-build \
		${libdir}/rpm/find-debuginfo.sh \
		${libdir}/rpm/find-lang.sh \
		${libdir}/rpm/find-prov.pl \
		${libdir}/rpm/find-provides.perl \
		${libdir}/rpm/find-req.pl \
		${libdir}/rpm/find-requires.perl \
		${libdir}/rpm/getpo.sh \
		${libdir}/rpm/http.req \
		${libdir}/rpm/javadeps.sh \
		${libdir}/rpm/mono-find-provides \
		${libdir}/rpm/mono-find-requires \
		${libdir}/rpm/executabledeps.sh \
		${libdir}/rpm/libtooldeps.sh \
		${libdir}/rpm/osgideps.pl \
		${libdir}/rpm/perldeps.pl \
		${libdir}/rpm/perl.prov \
		${libdir}/rpm/perl.req \
		${libdir}/rpm/php.prov \
		${libdir}/rpm/php.req \
		${libdir}/rpm/pkgconfigdeps.sh \
		${libdir}/rpm/pythondeps.sh \
		${libdir}/rpm/bin/debugedit \
		${libdir}/rpm/bin/debugedit.real \
		${libdir}/rpm/bin/rpmcache \
		${libdir}/rpm/bin/rpmcache.real \
		${libdir}/rpm/bin/rpmcmp \
		${libdir}/rpm/bin/rpmcmp.real \
		${libdir}/rpm/bin/rpmdeps \
		${libdir}/rpm/bin/rpmdeps.real \
		${libdir}/rpm/bin/rpmdeps-oecore \
		${libdir}/rpm/bin/rpmdeps-oecore.real \
		${libdir}/rpm/bin/rpmdigest \
		${libdir}/rpm/bin/rpmdigest.real \
		${libdir}/rpm/bin/abi-compliance-checker.pl \
		${libdir}/rpm/bin/api-sanity-autotest.pl \
		${libdir}/rpm/bin/chroot \
		${libdir}/rpm/bin/cp \
		${libdir}/rpm/bin/dbsql \
		${libdir}/rpm/bin/find \
		${libdir}/rpm/bin/install-sh \
		${libdir}/rpm/bin/lua \
		${libdir}/rpm/bin/luac \
		${libdir}/rpm/bin/mkinstalldirs \
		${libdir}/rpm/bin/rpmlua \
		${libdir}/rpm/bin/rpmluac \
		${libdir}/rpm/bin/sqlite3 \
		${libdir}/rpm/macros.d/cmake \
		${libdir}/rpm/macros.d/java \
		${libdir}/rpm/macros.d/libtool \
		${libdir}/rpm/macros.d/mandriva \
		${libdir}/rpm/macros.d/mono \
		${libdir}/rpm/macros.d/perl \
		${libdir}/rpm/macros.d/php \
		${libdir}/rpm/macros.d/pkgconfig \
		${libdir}/rpm/macros.d/python \
		${libdir}/rpm/macros.d/ruby \
		${libdir}/rpm/macros.d/selinux \
		${libdir}/rpm/macros.d/tcl \
		${libdir}/rpm/macros.rpmbuild \
		${libdir}/rpm/u_pkg.sh \
		${libdir}/rpm/vpkg-provides.sh \
		${libdir}/rpm/vpkg-provides2.sh \
		${libdir}/rpm/perfile_rpmdeps.sh \
		${distromacrodir} \
		"
RDEPENDS_${PN} = "base-files run-postinsts"
RDEPENDS_${PN}_class-native = ""
RDEPENDS_${PN}_class-nativesdk = ""
RDEPENDS_${PN}-build = "file bash perl"

RDEPENDS_python-rpm = "${PN} python"

FILES_python-rpm = "${libdir}/python*/site-packages/rpm"
PROVIDES += "python-rpm"

FILES_perl-module-rpm = "${libdir}/perl/*/* \
		"

RDEPENDS_${PN}-dev += "bash"

FILES_${PN}-dev = "${includedir}/rpm \
		${libdir}/librpm.la \
		${libdir}/librpm.so \
		${libdir}/librpmconstant.la \
		${libdir}/librpmconstant.so \
		${libdir}/librpmdb.la \
		${libdir}/librpmdb.so \
		${libdir}/librpmio.la \
		${libdir}/librpmio.so \
		${libdir}/librpmmisc.la \
		${libdir}/librpmmisc.so \
		${libdir}/librpmbuild.la \
		${libdir}/librpmbuild.so \
		${libdir}/rpm/lib/liblua.la \
		${libdir}/pkgconfig/rpm.pc \
		${libdir}/rpm/rpmdb_loadcvt \
		${libdir}/rpm/include \
		"

FILES_${PN}-staticdev = " \
		${libdir}/librpm.a \
		${libdir}/librpmconstant.a \
		${libdir}/librpmdb.a \
		${libdir}/librpmio.a \
		${libdir}/librpmmisc.a \
		${libdir}/librpmbuild.a \
		${libdir}/rpm/lib/liblua.a \
		${libdir}/python*/site-packages/rpm/*.a \
		"

do_configure() {
	# Disable tests!
	echo "all:" > ${S}/tests/Makefile.am
	sed -e 's/@__MKDIR_P@/%{__mkdir} -p/' -i ${S}/macros/macros.in

	( cd ${S}; ${S}/autogen.sh )

	# NASTY hack to make sure configure files the right pkg-config file...
	sed -e 's/pkg-config --exists uuid/pkg-config --exists ossp-uuid/g' \
	    -e 's/pkg-config uuid/pkg-config ossp-uuid/g' -i ${S}/configure

	( cd ${S}/syck ; set +e ; rm -- -l* ; make distclean ) || :

	export varprefix=${localstatedir}
	oe_runconf
}

do_install_append() {
	# Configure -distribution wide- package crypto settings
	# If these change, effectively all packages have to be upgraded!
	sed -i -e 's,%_build_file_digest_algo.*,%_build_sign ${RPM_FILE_DIGEST_ALGO},' ${D}/${libdir}/rpm/macros.rpmbuild
	sed -i -e 's,%_build_sign.*,%_build_sign ${RPM_SELF_SIGN_ALGO},' ${D}/${libdir}/rpm/macros.rpmbuild

	sed -i -e 's,%__scriptlet_requires,#%%__scriptlet_requires,' ${D}/${libdir}/rpm/macros
	sed -i -e 's,%__perl_provides,#%%__perl_provides,' ${D}/${libdir}/rpm/macros ${D}/${libdir}/rpm/macros.d/*
	sed -i -e 's,%__perl_requires,#%%__perl_requires,' ${D}/${libdir}/rpm/macros ${D}/${libdir}/rpm/macros.d/*
	sed -i -e 's,%_repackage_all_erasures[^_].*,%_repackage_all_erasures 0,' ${D}/${libdir}/rpm/macros
	sed -i -e 's,^#%_openall_before_chroot.*,%_openall_before_chroot\t1,' ${D}/${libdir}/rpm/macros

	# Enable MIPS64 N32 transactions.  (This is a no-op on non-MIPS targets.)
	sed -i -e 's,%_transaction_color[^_].*,%_transaction_color 7,' ${D}/${libdir}/rpm/macros

	# Enable Debian style arbitrary tags...
	sed -i -e 's,%_arbitrary_tags[^_].*,%_arbitrary_tags %{_arbitrary_tags_debian},' ${D}/${libdir}/rpm/macros

	install -m 0755 ${WORKDIR}/pythondeps.sh ${D}/${libdir}/rpm/pythondeps.sh
	install -m 0755 ${WORKDIR}/perfile_rpmdeps.sh ${D}/${libdir}/rpm/perfile_rpmdeps.sh

	# Remove unpackaged files (based on list in rpm.spec)
	rm -f ${D}/${libdir}/rpm/{Specfile.pm,cpanflute,cpanflute2,rpmdiff,rpmdiff.cgi,sql.prov,sql.req,tcl.req,trpm}

	rm -f ${D}/${mandir}/man8/rpmcache.8*
	rm -f ${D}/${mandir}/man8/rpmgraph.8*
	rm -f ${D}/${mandir}/*/man8/rpmcache.8*
	rm -f ${D}/${mandir}/*/man8/rpmgraph.8*
	rm -rf ${D}/${mandir}/{fr,ko}

	rm -f ${D}/${includedir}/popt.h
	rm -f ${D}/${libdir}/libpopt.*
	rm -f ${D}/${libdir}/pkgconfig/popt.pc
	rm -f ${D}/${datadir}/locale/*/LC_MESSAGES/popt.mo
	rm -f ${D}/${mandir}/man3/popt.3

	rm -f ${D}/${mandir}/man1/xar.1*
	rm -f ${D}/${bindir}/xar
	rm -rf ${D}/${includedir}/xar
	rm -f ${D}/${libdir}/libxar*

	rm -f ${D}/${bindir}/lz*
	rm -f ${D}/${bindir}/unlzma
	rm -f ${D}/${bindir}/unxz
	rm -f ${D}/${bindir}/xz*
	rm -rf ${D}/${includedir}/lzma*
	rm -f ${D}/${mandir}/man1/lz*.1
	rm -f ${D}/${libdir}/pkgconfig/liblzma*

	rm -f ${D}/${libdir}/python%{with_python_version}/site-packages/*.a
	rm -f ${D}/${libdir}/python%{with_python_version}/site-packages/*.la
	rm -f ${D}/${libdir}/python%{with_python_version}/site-packages/rpm/*.a
	rm -f ${D}/${libdir}/python%{with_python_version}/site-packages/rpm/*.la

	#find ${D}/${libdir}/perl5 -type f -a \( -name perllocal.pod -o -name .packlist \
	#	-o \( -name '*.bs' -a -empty \) \) -exec rm -f {} ';'
	#find ${D}/${libdir}/perl5 -type d -depth -exec rmdir {} 2>/dev/null ';'

	rm -f ${D}/${libdir}/rpm/dbconvert.sh

	rm -f ${D}/${libdir}/rpm/libsqldb.*

	# We don't want, nor need the Mandriva multiarch items
	rm -f ${D}/${bindir}/multiarch-dispatch
	rm -f ${D}/${bindir}/multiarch-platform
	rm -f ${D}/${libdir}/rpm/check-multiarch-files
	rm -f ${D}/${libdir}/rpm/mkmultiarch
	rm -f ${D}/${includedir}/multiarch-dispatch.h

	rm -f ${D}/${libdir}/rpm/gstreamer.sh
	rm -f ${D}/${libdir}/rpm/gem_helper.rb
	rm -f ${D}/${libdir}/rpm/rubygems.rb
	rm -f ${D}/${libdir}/rpm/kmod-deps.sh
	rm -f ${D}/${libdir}/rpm/pythoneggs.py
	rm -f ${D}/${libdir}/rpm/macros.d/kernel
	rm -f ${D}/${libdir}/rpm/macros.d/gstreamer
	rm -f ${D}/${libdir}/rpm/bin/mgo
	rm -f ${D}/${libdir}/rpm/bin/dbconvert
	rm -f ${D}/${libdir}/rpm/bin/pom2spec

	rm -rf ${D}/var/lib/wdj ${D}/var/cache/wdj
	rm -f ${D}/${libdir}/rpm/bin/api-sanity-checker.pl

}

do_install_append_class-target() {
	# Create and install distribution specific macros
	mkdir -p ${D}/${distromacrodir}
	cat << EOF > ${D}/${distromacrodir}/macros
%_defaultdocdir		${docdir}

%_prefix                ${prefix}
%_exec_prefix           ${exec_prefix}
%_datarootdir           ${datadir}
%_bindir                ${bindir}
%_sbindir               ${sbindir}
%_libexecdir            %{_libdir}/%{name}
%_datadir               ${datadir}
%_sysconfdir            ${sysconfdir}
%_sharedstatedir        ${sharedstatedir}
%_localstatedir         ${localstatedir}
%_lib                   lib
%_libdir                %{_exec_prefix}/%{_lib}
%_includedir            ${includedir}
%_oldincludedir         ${oldincludedir}
%_infodir               ${infodir}
%_mandir                ${mandir}
%_localedir             %{_libdir}/locale
EOF

	# Create and install multilib specific macros
	${@multilib_rpmmacros(d)}
}

do_install_append_class-native () {
	sed -i -e 's|^#!.*/usr/bin/python|#! /usr/bin/env nativepython|' ${D}/${libdir}/python2.7/site-packages/rpm/transaction.py
}

do_install_append_class-nativesdk () {
	sed -i -e 's|^#!.*/usr/bin/python|#! /usr/bin/env python|' ${D}/${libdir}/python2.7/site-packages/rpm/transaction.py
}

def multilib_rpmmacros(d):
    localdata = d.createCopy()
    # We need to clear the TOOLCHAIN_OPTIONS (--sysroot)
    localdata.delVar('TOOLCHAIN_OPTIONS')

    # Set 'localdata' values to be consistent with 'd' values.
    localdata.setVar('distromacrodir', d.getVar('distromacrodir', True))
    localdata.setVar('WORKDIR', d.getVar('WORKDIR', True))

    ret = gen_arch_macro(localdata)

    variants = d.getVar("MULTILIB_VARIANTS", True) or ""
    for item in variants.split():
        # Load overrides from 'd' to avoid having to reset the value...
        localdata = d.createCopy()
        overrides = d.getVar("OVERRIDES", False) + ":virtclass-multilib-" + item
        localdata.setVar("OVERRIDES", overrides)
        localdata.setVar("MLPREFIX", item + "-")
        bb.data.update_data(localdata)
        ret += gen_arch_macro(localdata)
    return ret

def gen_arch_macro(d):
    # Generate shell script to produce the file as part of do_install
    val  = "mkdir -p ${D}/${distromacrodir}/${TARGET_ARCH}-${TARGET_OS}\n"
    val += "cat << EOF > ${D}/${distromacrodir}/${TARGET_ARCH}-${TARGET_OS}/macros\n"
    val += "%_lib               ${baselib}\n"
    val += "%_libdir            ${libdir}\n"
    val += "%_localedir         ${localedir}\n"
    val += "\n"
    val += "# Toolchain configuration\n"
    val += "%TOOLCHAIN_OPTIONS  %{nil}\n"
    val += "%__ar               ${@d.getVar('AR', True).replace('$','%')}\n"
    val += "%__as               ${@d.getVar('AS', True).replace('$','%')}\n"
    val += "%__cc               ${@d.getVar('CC', True).replace('$','%')}\n"
    val += "%__cpp              ${@d.getVar('CPP', True).replace('$','%')}\n"
    val += "%__cxx              ${@d.getVar('CXX', True).replace('$','%')}\n"
    val += "%__ld               ${@d.getVar('LD', True).replace('$','%')}\n"
    val += "%__nm               ${@d.getVar('NM', True).replace('$','%')}\n"
    val += "%__objcopy          ${@d.getVar('OBJCOPY', True).replace('$','%')}\n"
    val += "%__objdump          ${@d.getVar('OBJDUMP', True).replace('$','%')}\n"
    val += "%__ranlib           ${@d.getVar('RANLIB', True).replace('$','%')}\n"
    val += "%__strip            ${@d.getVar('STRIP', True).replace('$','%')}\n"
    val += "EOF\n"
    val += "\n"
    return d.expand(val)


add_native_wrapper() {
        create_wrapper ${D}/${bindir}/rpm \
		RPM_USRLIBRPM='`dirname $''realpath`'/${@os.path.relpath(d.getVar('libdir', True), d.getVar('bindir', True))}/rpm \
		RPM_ETCRPM='$'{RPM_ETCRPM-'`dirname $''realpath`'/${@os.path.relpath(d.getVar('sysconfdir', True), d.getVar('bindir', True))}/rpm} \
		RPM_LOCALEDIRRPM='`dirname $''realpath`'/${@os.path.relpath(d.getVar('datadir', True), d.getVar('bindir', True))}/locale

        create_wrapper ${D}/${bindir}/rpm2cpio \
		RPM_USRLIBRPM='`dirname $''realpath`'/${@os.path.relpath(d.getVar('libdir', True), d.getVar('bindir', True))}/rpm \
		RPM_ETCRPM='$'{RPM_ETCRPM-'`dirname $''realpath`'/${@os.path.relpath(d.getVar('sysconfdir', True), d.getVar('bindir', True))}/rpm} \
		RPM_LOCALEDIRRPM='`dirname $''realpath`'/${@os.path.relpath(d.getVar('datadir', True), d.getVar('bindir', True))}/locale

        create_wrapper ${D}/${bindir}/rpmbuild \
		RPM_USRLIBRPM='`dirname $''realpath`'/${@os.path.relpath(d.getVar('libdir', True), d.getVar('bindir', True))}/rpm \
		RPM_ETCRPM='$'{RPM_ETCRPM-'`dirname $''realpath`'/${@os.path.relpath(d.getVar('sysconfdir', True), d.getVar('bindir', True))}/rpm} \
		RPM_LOCALEDIRRPM='`dirname $''realpath`'/${@os.path.relpath(d.getVar('datadir', True), d.getVar('bindir', True))}/locale

        create_wrapper ${D}/${bindir}/rpmconstant \
		RPM_USRLIBRPM='`dirname $''realpath`'/${@os.path.relpath(d.getVar('libdir', True), d.getVar('bindir', True))}/rpm \
		RPM_ETCRPM='$'{RPM_ETCRPM-'`dirname $''realpath`'/${@os.path.relpath(d.getVar('sysconfdir', True), d.getVar('bindir', True))}/rpm} \
		RPM_LOCALEDIRRPM='`dirname $''realpath`'/${@os.path.relpath(d.getVar('datadir', True), d.getVar('bindir', True))}/locale

	for rpm_binary in ${D}/${libdir}/rpm/bin/rpm* ${D}/${libdir}/rpm/bin/debugedit; do
        	create_wrapper $rpm_binary \
			RPM_USRLIBRPM='`dirname $''realpath`'/${@os.path.relpath(d.getVar('libdir', True), d.getVar('bindir', True))}/rpm \
			RPM_ETCRPM='$'{RPM_ETCRPM-'`dirname $''realpath`'/${@os.path.relpath(d.getVar('sysconfdir', True), d.getVar('bindir', True))}/rpm} \
			RPM_LOCALEDIRRPM='`dirname $''realpath`'/${@os.path.relpath(d.getVar('datadir', True), d.getVar('bindir', True))}/locale
	done
}

do_install_append_class-native() {
	add_native_wrapper
}

do_install_append_class-nativesdk() {
	add_native_wrapper
}

BBCLASSEXTEND = "native nativesdk"