--- librpm-tizen-4.11.0.1.tizen20140530.orig/configure.ac
+++ librpm-tizen-4.11.0.1.tizen20140530/configure.ac
@@ -359,6 +359,7 @@
   ],[
     AC_MSG_ERROR([missing required header db.h])
   ])
+  AC_DEFINE(WITH_EXTERNAL_DB, 1, [Use external db?])
   ;;
 * ) # Fall back to internal db if available
   if [ test -x db/dist/configure ]; then
@@ -792,9 +793,12 @@
             [],
             [with_lua=yes])
 
+if test X"$LUA_PKGCONFIG_NAME" = X ; then
+    LUA_PKGCONFIG_NAME=lua
+fi
 AS_IF([test "$with_lua" != no],[
   PKG_CHECK_MODULES([LUA],
-    [lua >= 5.1],
+    [${LUA_PKGCONFIG_NAME} >= 5.1],
     [AC_DEFINE(WITH_LUA, 1, [Build with lua support?])],
     [AC_MSG_ERROR([lua not present (--without-lua to disable)])])
   AC_SUBST(LUA_CFLAGS)
@@ -883,7 +887,7 @@
     usrprefix=$prefix
 fi
 
-RPMCONFIGDIR="`echo ${usrprefix}/lib/rpm`"
+RPMCONFIGDIR="`echo ${libdir}/rpm`"
 AC_SUBST(RPMCONFIGDIR)
 
 AC_SUBST(OBJDUMP)
@@ -896,6 +900,14 @@
 AM_CONDITIONAL([DOXYGEN],[test "$DOXYGEN" != no])
 AM_CONDITIONAL([HACKINGDOCS],[test "$with_hackingdocs" = yes])
 
+AC_ARG_VAR([PYTHON_MODULENAME], [Name of the rpm python module. Defaults to 'rpm'])
+if test X"$PYTHON_MODULENAME" = X ; then
+    PYTHON_MODULENAME="$PACKAGE"
+fi
+AC_DEFINE_UNQUOTED(PYTHON_MODULENAME, ["$PYTHON_MODULENAME"],[python module name])
+AC_SUBST(PYTHON_MODULENAME)
+
+
 AC_PATH_PROG(AUTOM4TE,autom4te,:)
 
 AC_SUBST([dirstamp],[\${am__leading_dot}dirstamp])
@@ -906,6 +918,8 @@
 	misc/Makefile 
 	doc/Makefile
 	python/Makefile
+	python/rpm/__init__.py
+	python/rpm/transaction.py
  	luaext/Makefile
  	tests/Makefile
  	plugins/Makefile
--- librpm-tizen-4.11.0.1.tizen20140530.orig/rpm.am
+++ librpm-tizen-4.11.0.1.tizen20140530/rpm.am
@@ -1,7 +1,7 @@
 # Internal binaries
 ## HACK: It probably should be $(libexecdir)/rpm or $(libdir)/rpm
-rpmlibexecdir = $(prefix)/lib/rpm
+rpmlibexecdir = $(libdir)/rpm
 
 # Host independent config files
 ## HACK: it probably should be $(datadir)/rpm
-rpmconfigdir = $(prefix)/lib/rpm
+rpmconfigdir = $(libdir)/rpm
--- librpm-tizen-4.11.0.1.tizen20140530.orig/.gitignore
+++ librpm-tizen-4.11.0.1.tizen20140530/.gitignore
@@ -76,3 +76,5 @@
 /scripts/macros.python
 /stamp-h1
 /tests/atconfig
+/obs
+/rpmbuild
--- librpm-tizen-4.11.0.1.tizen20140530.orig/.gbp.conf
+++ librpm-tizen-4.11.0.1.tizen20140530/.gbp.conf
@@ -0,0 +1,19 @@
+[DEFAULT]
+upstream-branch = tizen
+upstream-tag = tizen/%(upstreamversion)s
+patch-export = True
+patch-export-ignore-path = (.gbp.conf|.gbs.conf|packaging/.*|debian/.*|.gitignore)
+packaging-dir = packaging
+packaging-tag = tizen-tools/%(upstreamversion)s-%(nowtime)s
+spec-file = packaging/librpm-tizen.spec
+postexport = make all || :
+ignore-branch = true
+
+[git-buildpackage]
+upstream-tag = tizen/%(version)s
+
+[git-dch]
+upstream-tag = tizen/%(version)s
+
+[git-rpm-ch]
+changelog-revision = %(tagname)s
--- librpm-tizen-4.11.0.1.tizen20140530.orig/Makefile.am
+++ librpm-tizen-4.11.0.1.tizen20140530/Makefile.am
@@ -175,7 +175,7 @@
 
 bin_PROGRAMS +=		rpmqpack
 rpmqpack_SOURCES =      rpmqpack.c
-rpmqpack_LDADD =        lib/librpm.la
+rpmqpack_LDADD =        lib/librpm.la @WITH_DB_LIB@
 
 rpmconfig_DATA = rpmrc
 rpmrc: $(top_srcdir)/rpmrc.in
--- librpm-tizen-4.11.0.1.tizen20140530.orig/build/parseSpec.c
+++ librpm-tizen-4.11.0.1.tizen20140530/build/parseSpec.c
@@ -352,9 +352,9 @@
         match = parseExpressionBoolean(spec, s);
 	if (match < 0) {
 	    rpmlog(RPMLOG_ERR,
-			_("%s:%d: bad %%if condition\n"),
+			_("%s:%d: bad %%if condition, continuing nevertheless\n"),
 			ofi->fileName, ofi->lineNum);
-	    return PART_ERROR;
+	    match = 0;
 	}
     } else if (ISMACRO(s, "%else")) {
 	if (! spec->readStack->next) {
--- librpm-tizen-4.11.0.1.tizen20140530.orig/build/parsePreamble.c
+++ librpm-tizen-4.11.0.1.tizen20140530/build/parsePreamble.c
@@ -1035,16 +1035,16 @@
 	    SKIPSPACE(linep);
 	    if (*linep != '\0') {
 		if (findPreambleTag(spec, &tag, &macro, lang)) {
-		    rpmlog(RPMLOG_ERR, _("line %d: Unknown tag: %s\n"),
+		    rpmlog(RPMLOG_INFO, _("line %d: Unknown tag: %s\n"),
 				spec->lineNum, spec->line);
-		    goto exit;
-		}
-		if (handlePreambleTag(spec, pkg, tag, macro, lang)) {
-		    goto exit;
-		}
-		if (spec->BANames && !spec->recursing) {
-		    res = PART_BUILDARCHITECTURES;
-		    goto exit;
+		} else {
+			if (handlePreambleTag(spec, pkg, tag, macro, lang)) {
+			    goto exit;
+			}
+			if (spec->BANames && !spec->recursing) {
+			    res = PART_BUILDARCHITECTURES;
+			    goto exit;
+			}
 		}
 	    }
 	    if ((rc =
--- librpm-tizen-4.11.0.1.tizen20140530.orig/build/parseScript.c
+++ librpm-tizen-4.11.0.1.tizen20140530/build/parseScript.c
@@ -297,10 +297,9 @@
     } else
 #endif
     if (progArgv[0][0] == '<') {
-	rpmlog(RPMLOG_ERR,
+	rpmlog(RPMLOG_INFO,
 		 _("line %d: unsupported internal script: %s\n"),
 		 spec->lineNum, progArgv[0]);
-	goto exit;
     } else {
         (void) addReqProv(pkg->header, RPMTAG_REQUIRENAME,
 		progArgv[0], NULL, (tagflags | RPMSENSE_INTERP), 0);
--- librpm-tizen-4.11.0.1.tizen20140530.orig/build/parseReqs.c
+++ librpm-tizen-4.11.0.1.tizen20140530/build/parseReqs.c
@@ -123,8 +123,9 @@
 	 * the spec's encoding so we only check what we can: plain ascii.
 	 */
 	if (isascii(r[0]) && !(risalnum(r[0]) || r[0] == '_' || r[0] == '/')) {
-	    emsg = _("Dependency tokens must begin with alpha-numeric, '_' or '/'");
-	    goto exit;
+	    rpmlog(RPMLOG_INFO,
+		   _("line %d: Dependency tokens must begin with alpha-numeric, '_' or '/': %s\n"),
+		   spec->lineNum, spec->line);
 	}
 
 	re = r;
--- librpm-tizen-4.11.0.1.tizen20140530.orig/python/rpmsystem-py.h
+++ librpm-tizen-4.11.0.1.tizen20140530/python/rpmsystem-py.h
@@ -8,6 +8,8 @@
 #include <Python.h>
 #include <structmember.h>
 
+#include "config.h"
+
 #if ((PY_MAJOR_VERSION << 8) | (PY_MINOR_VERSION << 0)) < 0x0205
 typedef ssize_t Py_ssize_t;
 typedef Py_ssize_t (*lenfunc)(PyObject *);
--- librpm-tizen-4.11.0.1.tizen20140530.orig/python/rpmds-py.c
+++ librpm-tizen-4.11.0.1.tizen20140530/python/rpmds-py.c
@@ -341,7 +341,7 @@
 
 PyTypeObject rpmds_Type = {
 	PyVarObject_HEAD_INIT(&PyType_Type, 0)
-	"rpm.ds",			/* tp_name */
+	PYTHON_MODULENAME".ds",		/* tp_name */
 	sizeof(rpmdsObject),		/* tp_basicsize */
 	0,				/* tp_itemsize */
 	/* methods */
--- librpm-tizen-4.11.0.1.tizen20140530.orig/python/rpmmi-py.c
+++ librpm-tizen-4.11.0.1.tizen20140530/python/rpmmi-py.c
@@ -164,7 +164,7 @@
 
 PyTypeObject rpmmi_Type = {
 	PyVarObject_HEAD_INIT(&PyType_Type, 0)
-	"rpm.mi",			/* tp_name */
+	PYTHON_MODULENAME".mi",		/* tp_name */
 	sizeof(rpmmiObject),		/* tp_size */
 	0,				/* tp_itemsize */
 	(destructor) rpmmi_dealloc, 	/* tp_dealloc */
--- librpm-tizen-4.11.0.1.tizen20140530.orig/python/rpmfi-py.c
+++ librpm-tizen-4.11.0.1.tizen20140530/python/rpmfi-py.c
@@ -320,7 +320,7 @@
 
 PyTypeObject rpmfi_Type = {
 	PyVarObject_HEAD_INIT(&PyType_Type, 0)
-	"rpm.fi",			/* tp_name */
+	PYTHON_MODULENAME".fi",		/* tp_name */
 	sizeof(rpmfiObject),		/* tp_basicsize */
 	0,				/* tp_itemsize */
 	/* methods */
--- librpm-tizen-4.11.0.1.tizen20140530.orig/python/rpmii-py.c
+++ librpm-tizen-4.11.0.1.tizen20140530/python/rpmii-py.c
@@ -103,7 +103,7 @@
 
 PyTypeObject rpmii_Type = {
 	PyVarObject_HEAD_INIT(&PyType_Type, 0)
-	"rpm.ii",			/* tp_name */
+	PYTHON_MODULENAME".ii",		/* tp_name */
 	sizeof(rpmiiObject),		/* tp_size */
 	0,				/* tp_itemsize */
 	(destructor) rpmii_dealloc, 	/* tp_dealloc */
--- librpm-tizen-4.11.0.1.tizen20140530.orig/python/rpmps-py.c
+++ librpm-tizen-4.11.0.1.tizen20140530/python/rpmps-py.c
@@ -72,7 +72,7 @@
 
 PyTypeObject rpmProblem_Type = {
 	PyVarObject_HEAD_INIT(&PyType_Type, 0)
-	"rpm.prob",			/* tp_name */
+	PYTHON_MODULENAME".prob",		/* tp_name */
 	sizeof(rpmProblemObject),		/* tp_basicsize */
 	0,				/* tp_itemsize */
 	/* methods */
--- librpm-tizen-4.11.0.1.tizen20140530.orig/python/rpmfd-py.c
+++ librpm-tizen-4.11.0.1.tizen20140530/python/rpmfd-py.c
@@ -310,7 +310,7 @@
 
 PyTypeObject rpmfd_Type = {
 	PyVarObject_HEAD_INIT(&PyType_Type, 0)
-	"rpm.fd",			/* tp_name */
+	PYTHON_MODULENAME".fd",		/* tp_name */
 	sizeof(rpmfdObject),		/* tp_size */
 	0,				/* tp_itemsize */
 	/* methods */
--- librpm-tizen-4.11.0.1.tizen20140530.orig/python/rpmkeyring-py.c
+++ librpm-tizen-4.11.0.1.tizen20140530/python/rpmkeyring-py.c
@@ -52,7 +52,7 @@
 
 PyTypeObject rpmPubkey_Type = {
 	PyVarObject_HEAD_INIT(&PyType_Type, 0)
-	"rpm.pubkey",			/* tp_name */
+	PYTHON_MODULENAME".pubkey",	/* tp_name */
 	sizeof(rpmPubkeyObject),	/* tp_size */
 	0,				/* tp_itemsize */
 	(destructor) rpmPubkey_dealloc,/* tp_dealloc */
@@ -133,7 +133,7 @@
 
 PyTypeObject rpmKeyring_Type = {
 	PyVarObject_HEAD_INIT(&PyType_Type, 0)
-	"rpm.keyring",			/* tp_name */
+	PYTHON_MODULENAME".keyring",	/* tp_name */
 	sizeof(rpmKeyringObject),	/* tp_size */
 	0,				/* tp_itemsize */
 	(destructor) rpmKeyring_dealloc,/* tp_dealloc */
--- librpm-tizen-4.11.0.1.tizen20140530.orig/python/rpmte-py.c
+++ librpm-tizen-4.11.0.1.tizen20140530/python/rpmte-py.c
@@ -192,7 +192,7 @@
 static struct PyMethodDef rpmte_methods[] = {
     {"Type",	(PyCFunction)rpmte_TEType,	METH_NOARGS,
 "te.Type() -> Type\n\
-- Return element type (rpm.TR_ADDED | rpm.TR_REMOVED).\n" },
+- Return element type ("PYTHON_MODULENAME".TR_ADDED | "PYTHON_MODULENAME".TR_REMOVED).\n" },
     {"N",	(PyCFunction)rpmte_N,		METH_NOARGS,
 "te.N() -> N\n\
 - Return element name.\n" },
@@ -250,7 +250,7 @@
 
 PyTypeObject rpmte_Type = {
 	PyVarObject_HEAD_INIT(&PyType_Type, 0)
-	"rpm.te",			/* tp_name */
+	PYTHON_MODULENAME".te",		/* tp_name */
 	sizeof(rpmteObject),		/* tp_size */
 	0,				/* tp_itemsize */
 	(destructor)0,		 	/* tp_dealloc */
--- librpm-tizen-4.11.0.1.tizen20140530.orig/python/rpmts-py.c
+++ librpm-tizen-4.11.0.1.tizen20140530/python/rpmts-py.c
@@ -440,7 +440,7 @@
     if (arg == Py_None || rpmKeyringFromPyObject(arg, &keyring)) {
 	return PyBool_FromLong(rpmtsSetKeyring(s->ts, keyring) == 0);
     } else {
-	PyErr_SetString(PyExc_TypeError, "rpm.keyring or None expected");
+	PyErr_SetString(PyExc_TypeError, PYTHON_MODULENAME".keyring or None expected");
 	return NULL;
     }
 }
@@ -872,7 +872,7 @@
 
 PyTypeObject rpmts_Type = {
 	PyVarObject_HEAD_INIT(&PyType_Type, 0)
-	"rpm.ts",			/* tp_name */
+	PYTHON_MODULENAME".ts",		/* tp_name */
 	sizeof(rpmtsObject),		/* tp_size */
 	0,				/* tp_itemsize */
 	(destructor) rpmts_dealloc, 	/* tp_dealloc */
--- librpm-tizen-4.11.0.1.tizen20140530.orig/python/header-py.c
+++ librpm-tizen-4.11.0.1.tizen20140530/python/header-py.c
@@ -393,7 +393,7 @@
     if (obj == NULL) {
 	h = headerNew();
     } else if (CAPSULE_CHECK(obj)) {
-	h = CAPSULE_EXTRACT(obj, "rpm._C_Header");
+	h = CAPSULE_EXTRACT(obj, PYTHON_MODULENAME"._C_Header");
     } else if (hdrObject_Check(obj)) {
 	h = headerCopy(((hdrObject*) obj)->h);
     } else if (PyBytes_Check(obj)) {
@@ -404,7 +404,7 @@
 	Py_END_ALLOW_THREADS;
 	Py_XDECREF(fdo);
     } else {
-    	PyErr_SetString(PyExc_TypeError, "header, blob or file expected");
+    	PyErr_SetString(PyExc_TypeError, "header, blob or file expected!!");
 	return NULL;
     }
 
@@ -684,7 +684,7 @@
 
 PyTypeObject hdr_Type = {
 	PyVarObject_HEAD_INIT(&PyType_Type, 0)
-	"rpm.hdr",			/* tp_name */
+	PYTHON_MODULENAME".hdr",	/* tp_name */
 	sizeof(hdrObject),		/* tp_size */
 	0,				/* tp_itemsize */
 	(destructor) hdr_dealloc, 	/* tp_dealloc */
--- librpm-tizen-4.11.0.1.tizen20140530.orig/python/Makefile.am
+++ librpm-tizen-4.11.0.1.tizen20140530/python/Makefile.am
@@ -5,9 +5,11 @@
 AM_CPPFLAGS = -I$(top_builddir)/include/
 AM_CPPFLAGS += -I$(top_srcdir)/python
 AM_CPPFLAGS += -I@WITH_PYTHON_INCLUDE@
+AM_CPPFLAGS += -I$(top_srcdir)
 
-pkgpyexec_LTLIBRARIES = _rpmmodule.la _rpmbmodule.la _rpmsmodule.la
-pkgpyexec_DATA = rpm/__init__.py rpm/transaction.py
+rpmpyexec_LTLIBRARIES = _rpmmodule.la _rpmbmodule.la _rpmsmodule.la
+rpmpyexec_DATA = rpm/__init__.py rpm/transaction.py
+rpmpyexecdir = @pyexecdir@/@PYTHON_MODULENAME@
 
 _rpmmodule_la_LDFLAGS = -module -avoid-version -shared
 _rpmmodule_la_LIBADD = \
--- librpm-tizen-4.11.0.1.tizen20140530.orig/python/rpmtd-py.c
+++ librpm-tizen-4.11.0.1.tizen20140530/python/rpmtd-py.c
@@ -167,7 +167,7 @@
 
 PyTypeObject rpmtd_Type = {
 	PyVarObject_HEAD_INIT(&PyType_Type, 0)
-	"rpm.td",			/* tp_name */
+	PYTHON_MODULENAME".td",		/* tp_name */
 	sizeof(rpmtdObject),		/* tp_size */
 	0,				/* tp_itemsize */
 	(destructor) rpmtd_dealloc, 	/* tp_dealloc */
@@ -214,7 +214,7 @@
 	*td = &(((rpmtdObject *)obj)->td);
 	return 1;
     } else {
-	PyErr_SetString(PyExc_TypeError, "rpm.td type expected");
+	PyErr_SetString(PyExc_TypeError, PYTHON_MODULENAME".td type expected");
 	return 0;
     }
 }
--- librpm-tizen-4.11.0.1.tizen20140530.orig/python/spec-py.c
+++ librpm-tizen-4.11.0.1.tizen20140530/python/spec-py.c
@@ -31,10 +31,10 @@
 /* Header objects are in another module, some hoop jumping required... */
 static PyObject *makeHeader(Header h)
 {
-    PyObject *rpmmod = PyImport_ImportModuleNoBlock("rpm");
+    PyObject *rpmmod = PyImport_ImportModuleNoBlock(PYTHON_MODULENAME);
     if (rpmmod == NULL) return NULL;
 
-    PyObject *ptr = CAPSULE_BUILD(h, "rpm._C_Header");
+    PyObject *ptr = CAPSULE_BUILD(h, PYTHON_MODULENAME"._C_Header");
     PyObject *hdr = PyObject_CallMethod(rpmmod, "hdr", "(O)", ptr);
     Py_XDECREF(ptr);
     Py_XDECREF(rpmmod);
@@ -62,7 +62,7 @@
 
 PyTypeObject specPkg_Type = {
 	PyVarObject_HEAD_INIT(&PyType_Type, 0)
-	"rpm.specpkg",			/* tp_name */
+	PYTHON_MODULENAME".specpkg",	/* tp_name */
 	sizeof(specPkgObject),		/* tp_size */
 	0,				/* tp_itemsize */
 	0, 				/* tp_dealloc */
@@ -263,7 +263,7 @@
 
 PyTypeObject spec_Type = {
     PyVarObject_HEAD_INIT(&PyType_Type, 0)
-    "rpm.spec",               /*tp_name*/
+    PYTHON_MODULENAME".spec",  /*tp_name*/
     sizeof(specObject),        /*tp_basicsize*/
     0,                         /*tp_itemsize*/
     (destructor) spec_dealloc, /*tp_dealloc*/
--- librpm-tizen-4.11.0.1.tizen20140530.orig/python/setup.py.in
+++ librpm-tizen-4.11.0.1.tizen20140530/python/setup.py.in
@@ -20,7 +20,7 @@
 
 cflags = ['-std=c99']
 
-rpmmod = Extension('rpm._rpm',
+rpmmod = Extension('@PYTHON_MODULENAME@._rpm',
                    sources = mksources([
                                 'header', 'rpmds', 'rpmfd', 'rpmfi', 'rpmii',
                                 'rpmkeyring', 'rpmmacro', 'rpmmi', 'rpmps',
@@ -31,21 +31,21 @@
                    extra_compile_args = cflags
                   )
 
-rpmbuild_mod = Extension('rpm._rpmb',
+rpmbuild_mod = Extension('@PYTHON_MODULENAME@._rpmb',
                    sources = mksources(['rpmbmodule', 'spec']),
                    include_dirs = pkgconfig('--cflags'),
                    libraries = pkgconfig('--libs') + ['rpmbuild'],
                    extra_compile_args = cflags
                   )
 
-rpmsign_mod = Extension('rpm._rpms',
+rpmsign_mod = Extension('@PYTHON_MODULENAME@._rpms',
                    sources = mksources(['rpmbmodule']),
                    include_dirs = pkgconfig('--cflags'),
                    libraries = pkgconfig('--libs') + ['rpmsign'],
                    extra_compile_args = cflags
                   )
 
-setup(name='@PACKAGE_NAME@-python',
+setup(name='@PACKAGE_NAME@',
       version='@VERSION@',
       description='Python bindings for @PACKAGE_NAME@',
       maintainer_email='@PACKAGE_BUGREPORT@',
--- librpm-tizen-4.11.0.1.tizen20140530.orig/python/rpm/__init__.py.in
+++ librpm-tizen-4.11.0.1.tizen20140530/python/rpm/__init__.py.in
@@ -0,0 +1,84 @@
+r"""RPM Module
+
+This module enables you to manipulate rpms and the rpm database.
+
+"""
+
+import warnings
+import os
+from @PYTHON_MODULENAME@._rpm import *
+from @PYTHON_MODULENAME@.transaction import *
+import @PYTHON_MODULENAME@._rpm as _rpm
+_RPMVSF_NODIGESTS = _rpm._RPMVSF_NODIGESTS
+_RPMVSF_NOHEADER = _rpm._RPMVSF_NOHEADER
+_RPMVSF_NOPAYLOAD = _rpm._RPMVSF_NOPAYLOAD
+_RPMVSF_NOSIGNATURES = _rpm._RPMVSF_NOSIGNATURES
+
+__version__ = _rpm.__version__
+__version_info__ = tuple(__version__.split('.'))
+
+# try to import build bits but dont require it
+try:
+    from @PYTHON_MODULENAME@._rpmb import *
+except ImportError:
+    pass
+
+# try to import signing bits but dont require it
+try:
+    from @PYTHON_MODULENAME@._rpms import *
+except ImportError:
+    pass
+
+# backwards compatibility + give the same class both ways
+ts = TransactionSet
+
+def headerLoad(*args, **kwds):
+    warnings.warn("Use rpm.hdr() instead.", DeprecationWarning, stacklevel=2)
+    return hdr(*args, **kwds)
+
+def _doHeaderListFromFD(rpm_fd, retrofit):
+    hlist = []
+    while 1:
+        try:
+            h = hdr(rpm_fd)
+            if retrofit:
+                h.convert(HEADERCONV_RETROFIT_V3)
+            hlist.append(h)
+        except _rpm.error:
+            break
+
+    return hlist
+
+def readHeaderListFromFD(file_desc, retrofit = True):
+    if not isinstance(file_desc, fd):
+        file_desc = fd(file_desc)
+    return _doHeaderListFromFD(file_desc, retrofit)
+        
+def readHeaderListFromFile(path, retrofit = True):
+    f = fd(path)
+    hlist = _doHeaderListFromFD(f, retrofit)
+    f.close()
+    return hlist
+    
+def readHeaderFromFD(file_desc):
+    if not isinstance(file_desc, fd):
+        file_desc = fd(file_desc)
+    try:
+        offset = file_desc.tell()
+        h = hdr(file_desc)
+    except (_rpm.error, IOError):
+        offset = None
+        h = None
+
+    return (h, offset)
+
+def signalsCaught(siglist):
+    caught = []
+    for sig in siglist:
+        if signalCaught(sig):
+            caught.append(sig)
+
+    return caught
+
+def dsSingle(TagN, N, EVR = "", Flags = RPMSENSE_ANY):
+    return ds((N, EVR, Flags), TagN)
--- librpm-tizen-4.11.0.1.tizen20140530.orig/python/rpm/transaction.py.in
+++ librpm-tizen-4.11.0.1.tizen20140530/python/rpm/transaction.py.in
@@ -0,0 +1,156 @@
+#!/usr/bin/python
+
+import @PYTHON_MODULENAME@ as rpm
+from @PYTHON_MODULENAME@._rpm import ts as TransactionSetCore
+
+# TODO: migrate relevant documentation from C-side
+class TransactionSet(TransactionSetCore):
+    _probFilter = 0
+
+    def _wrapSetGet(self, attr, val):
+        oval = getattr(self, attr)
+        setattr(self, attr, val)
+        return oval
+        
+    def setVSFlags(self, flags):
+        return self._wrapSetGet('_vsflags', flags)
+
+    def getVSFlags(self):
+        return self._vsflags
+
+    def setColor(self, color):
+        return self._wrapSetGet('_color', color)
+
+    def setPrefColor(self, color):
+        return self._wrapSetGet('_prefcolor', color)
+
+    def setFlags(self, flags):
+        return self._wrapSetGet('_flags', flags)
+
+    def setProbFilter(self, ignoreSet):
+        return self._wrapSetGet('_probFilter', ignoreSet)
+
+    def parseSpec(self, specfile):
+        import _rpmb
+        return _rpmb.spec(specfile)
+
+    def getKeys(self):
+        keys = []
+        for te in self:
+            keys.append(te.Key())
+        # Backwards compatibility goo - WTH does this return a *tuple* ?!
+        if not keys:
+            return None
+        else:
+            return tuple(keys)
+
+    def addInstall(self, item, key, how="u"):
+        if isinstance(item, basestring):
+            f = file(item)
+            header = self.hdrFromFdno(f)
+            f.close()
+        elif isinstance(item, file):
+            header = self.hdrFromFdno(item)
+        else:
+            header = item
+
+        if not how in ['u', 'i']:
+            raise ValueError('how argument must be "u" or "i"')
+        upgrade = (how == "u")
+
+        if not TransactionSetCore.addInstall(self, header, key, upgrade):
+            raise rpm.error("adding package to transaction failed")
+
+    def addErase(self, item):
+        hdrs = []
+        if isinstance(item, rpm.hdr):
+            hdrs = [item]
+        elif isinstance(item, rpm.mi):
+            hdrs = item
+        elif isinstance(item, int):
+            hdrs = self.dbMatch(rpm.RPMDBI_PACKAGES, item)
+        elif isinstance(item, basestring):
+            hdrs = self.dbMatch(rpm.RPMDBI_LABEL, item)
+        else:
+            raise TypeError("invalid type %s" % type(item))
+
+        for h in hdrs:
+            if not TransactionSetCore.addErase(self, h):
+                raise rpm.error("package not installed")
+
+        # garbage collection should take care but just in case...
+        if isinstance(hdrs, rpm.mi):
+            del hdrs
+
+    def run(self, callback, data):
+        rc = TransactionSetCore.run(self, callback, data, self._probFilter)
+
+        # crazy backwards compatibility goo: None for ok, list of problems
+        # if transaction didnt complete and empty list if it completed
+        # with errors
+        if rc == 0:
+            return None
+
+        res = []
+        if rc > 0:
+            for prob in self.problems():
+                item = ("%s" % prob, (prob.type, prob._str, prob._num))
+                res.append(item)
+        return res
+
+    def check(self, *args, **kwds):
+        TransactionSetCore.check(self, *args, **kwds)
+
+        # compatibility: munge problem strings into dependency tuples of doom
+        res = []
+        for p in self.problems():
+            # is it anything we need to care about?
+            if p.type == rpm.RPMPROB_CONFLICT:
+                sense = rpm.RPMDEP_SENSE_CONFLICTS
+            elif p.type == rpm.RPMPROB_REQUIRES:
+                sense = rpm.RPMDEP_SENSE_REQUIRES
+            else:
+                continue
+
+            # strip arch, split to name, version, release
+            nevr = p.altNEVR.rsplit('.', 1)[0]
+            n, v, r = nevr.rsplit('-', 2)
+
+            # extract the dependency information
+            needs = p._str.split()
+            needname = needs[0]
+            needflags = rpm.RPMSENSE_ANY
+            if len(needs) == 3:
+                needop = needs[1]
+                if needop.find('<') >= 0: needflags |= rpm.RPMSENSE_LESS
+                if needop.find('=') >= 0: needflags |= rpm.RPMSENSE_EQUAL
+                if needop.find('>') >= 0: needflags |= rpm.RPMSENSE_GREATER
+                needver = needs[2]
+            else:
+                needver = ""
+
+            res.append(((n, v, r),(needname,needver),needflags,sense,p.key))
+
+        return res
+
+    def hdrCheck(self, blob):
+        res, msg = TransactionSetCore.hdrCheck(self, blob)
+        # generate backwards compatibly broken exceptions
+        if res == rpm.RPMRC_NOKEY:
+            raise rpm.error("public key not available")
+        elif res == rpm.RPMRC_NOTTRUSTED:
+            raise rpm.error("public key not trusted")
+        elif res != rpm.RPMRC_OK:
+            raise rpm.error(msg)
+
+    def hdrFromFdno(self, fd):
+        res, h = TransactionSetCore.hdrFromFdno(self, fd)
+        # generate backwards compatibly broken exceptions
+        if res == rpm.RPMRC_NOKEY:
+            raise rpm.error("public key not available")
+        elif res == rpm.RPMRC_NOTTRUSTED:
+            raise rpm.error("public key not trusted")
+        elif res != rpm.RPMRC_OK:
+            raise rpm.error("error reading package header")
+
+        return h
--- librpm-tizen-4.11.0.1.tizen20140530.orig/rpmio/rpmlua.c
+++ librpm-tizen-4.11.0.1.tizen20140530/rpmio/rpmlua.c
@@ -7,14 +7,22 @@
 #include <lposix.h>
 #include <lrexlib.h>
 
+/* replaced in 5.1 */
 #ifndef lua_open
 #define lua_open()	luaL_newstate()
 #endif
 
+/* defined as lua_objlen in 5.1 */
 #ifndef lua_strlen
 #define lua_strlen(L,i)	lua_rawlen(L, (i))
 #endif
 
+/* deprecated in 5.1, defined as lua_objlen in 5.1 */
+#ifndef luaL_getn
+#define luaL_getn(L,i)	((int)lua_rawlen(L, i))
+#endif
+
+/* define added in 5.2 */
 #ifndef lua_pushglobaltable
 #define lua_pushglobaltable(L)	lua_pushvalue(L, LUA_GLOBALSINDEX)
 #endif
@@ -72,7 +80,7 @@
 	{"posix", luaopen_posix},
 	{"rex", luaopen_rex},
 	{"rpm", luaopen_rpm},
-	{"os",	luaopen_rpm_os},
+	/*{"os",	luaopen_rpm_os},*/
 	{NULL, NULL},
     };
     
@@ -86,6 +94,12 @@
 	lua_call(L, 1, 0);
 	lua_settop(L, 0);
     }
+    /* Disable os and io standard libraries */
+    lua_pushnil (L);
+    lua_setglobal(L, "os");
+    lua_pushnil (L);
+    lua_setglobal(L, "io");
+
 #ifndef LUA_GLOBALSINDEX
     lua_pushglobaltable(L);
 #endif
@@ -524,7 +538,7 @@
 	lua_pop(L, 1);
 	ret = -1;
     } else if (lua_pcall(L, 0, 0, 0) != 0) {
-	rpmlog(RPMLOG_ERR, _("lua script failed: %s\n"),
+	rpmlog(RPMLOG_WARNING, _("lua script failed: %s\n"),
 		 lua_tostring(L, -1));
 	lua_pop(L, 1);
 	ret = -1;
--- librpm-tizen-4.11.0.1.tizen20140530.orig/rpmio/macro.c
+++ librpm-tizen-4.11.0.1.tizen20140530/rpmio/macro.c
@@ -472,6 +472,9 @@
     int rc = 0;
     int c;
 
+    rpmlog(RPMLOG_WARNING, _("Refusing to run shell code: %s\n"), cmd);
+    mbAppendStr(mb, "UNEXPANDEDSHELLSCRIPT");
+#if 0
     rc = expandThis(mb, cmd, clen, &buf);
     if (rc)
 	goto exit;
@@ -493,6 +496,7 @@
 
 exit:
     _free(buf);
+#endif
     return rc;
 }
 
@@ -1229,6 +1233,7 @@
 	}
 
 #ifdef	WITH_LUA
+#define LUA_FAILURE_OUTPUT "1"
 	if (STREQ("lua", f, fn)) {
 		rpmlua lua = NULL; /* Global state. */
 		const char *ls = s+sizeof("{lua:")-1;
@@ -1238,9 +1243,14 @@
 		memcpy(scriptbuf, ls, lse-ls);
 		scriptbuf[lse-ls] = '\0';
 		rpmluaPushPrintBuffer(lua);
-		if (rpmluaRunScript(lua, scriptbuf, NULL) == -1)
-		    rc = 1;
-		printbuf = rpmluaPopPrintBuffer(lua);
+		if (rpmluaRunScript(lua, scriptbuf, NULL) == -1) {
+			printbuf = rpmluaPopPrintBuffer(lua);
+			rpmlog(RPMLOG_WARNING, _("lua: using fallback output '%s'\n"), LUA_FAILURE_OUTPUT);
+			printbuf = (char *)xcalloc(1, sizeof(LUA_FAILURE_OUTPUT));
+			strcpy(printbuf, LUA_FAILURE_OUTPUT);
+		} else {
+			printbuf = rpmluaPopPrintBuffer(lua);
+		}
 		if (printbuf) {
 		    mbAppendStr(mb, printbuf);
 		    free(printbuf);
--- librpm-tizen-4.11.0.1.tizen20140530.orig/lib/backend/dbconfig.c
+++ librpm-tizen-4.11.0.1.tizen20140530/lib/backend/dbconfig.c
@@ -71,8 +71,10 @@
 	NULL, NULL },
  { "lockdbfd",	0,POPT_ARG_NONE,	&staticdbi.dbi_lockdbfd, 0,
 	NULL, NULL },
+#ifndef WITH_EXTERNAL_DB
  { "nofsync",	0,POPT_BIT_SET,		&staticdbi.dbi_oflags, DB_NOFSYNC,
 	NULL, NULL },
+#endif
 
     POPT_TABLEEND
 };
--- librpm-tizen-4.11.0.1.tizen20140530.orig/luaext/lposix.c
+++ librpm-tizen-4.11.0.1.tizen20140530/luaext/lposix.c
@@ -58,6 +58,15 @@
 
 typedef int (*Selector)(lua_State *L, int i, const void *data);
 
+/* implemented as luaL_typerror until lua 5.1, dropped in 5.2
+ * (C) 1994-2012 Lua.org, PUC-Rio. MIT license
+ */
+static int typerror (lua_State *L, int narg, const char *tname) {
+	const char *msg = lua_pushfstring(L, "%s expected, got %s",
+					  tname, luaL_typename(L, narg));
+	return luaL_argerror(L, narg, msg);
+}
+
 static int doselection(lua_State *L, int i, const char *const S[], Selector F, const void *data)
 {
 	if (lua_isnone(L, i))
@@ -139,7 +148,7 @@
 		return (p==NULL) ? -1 : p->pw_uid;
 	}
 	else
-		return luaL_typerror(L, i, "string or number");
+		return typerror(L, i, "string or number");
 }
 
 static gid_t mygetgid(lua_State *L, int i)
@@ -154,7 +163,7 @@
 		return (g==NULL) ? -1 : g->gr_gid;
 	}
 	else
-		return luaL_typerror(L, i, "string or number");
+		return typerror(L, i, "string or number");
 }
 
 
@@ -573,7 +582,7 @@
 	else if (lua_isstring(L, 1))
 		p = getpwnam(lua_tostring(L, 1));
 	else
-		luaL_typerror(L, 1, "string or number");
+		typerror(L, 1, "string or number");
 	if (p==NULL)
 		lua_pushnil(L);
 	else
@@ -590,7 +599,7 @@
 	else if (lua_isstring(L, 1))
 		g = getgrnam(lua_tostring(L, 1));
 	else
-		luaL_typerror(L, 1, "string or number");
+		typerror(L, 1, "string or number");
 	if (g==NULL)
 		lua_pushnil(L);
 	else
@@ -709,10 +718,10 @@
 	luaL_buffinit(L, &b);
 	for (s=luaL_optstring(L, 1, "%s %n %r %v %m"); *s; s++)
 		if (*s!='%')
-			luaL_putchar(&b, *s);
+			luaL_addchar(&b, *s);
 		else switch (*++s)
 		{
-			case '%': luaL_putchar(&b, *s); break;
+			case '%': luaL_addchar(&b, *s); break;
 			case 'm': luaL_addstring(&b,u.machine); break;
 			case 'n': luaL_addstring(&b,u.nodename); break;
 			case 'r': luaL_addstring(&b,u.release); break;
@@ -813,7 +822,7 @@
 static const luaL_Reg R[] =
 {
 	{"access",		Paccess},
-	{"chdir",		Pchdir},
+/*	{"chdir",		Pchdir},
 	{"chmod",		Pchmod},
 	{"chown",		Pchown},
 	{"ctermid",		Pctermid},
@@ -851,7 +860,7 @@
 	{"utime",		Putime},
 	{"wait",		Pwait},
 	{"setenv",		Psetenv},
-	{"unsetenv",		Punsetenv},
+	{"unsetenv",		Punsetenv},*/
 	{NULL,			NULL}
 };
 
--- librpm-tizen-4.11.0.1.tizen20140530.orig/debian/compat
+++ librpm-tizen-4.11.0.1.tizen20140530/debian/compat
@@ -0,0 +1 @@
+7
--- librpm-tizen-4.11.0.1.tizen20140530.orig/debian/control
+++ librpm-tizen-4.11.0.1.tizen20140530/debian/control
@@ -0,0 +1,47 @@
+Source: librpm-tizen
+Section: vcs
+Priority: optional
+Build-Depends: debhelper,
+               dpkg-dev,
+               dh-autoreconf,
+               libtool,
+               autoconf,
+               automake,
+               autotools-dev,
+               autopoint,
+               zlib1g-dev,
+               libpopt-dev,
+               libxml2-dev,
+               libreadline-dev,
+               libsqlite3-dev,
+               python-all-dev,
+               pkg-config,
+               libnspr4-dev,
+               libnss3-dev,
+               liblzma-dev,
+               libmagic-dev,
+               libelf-dev,
+               libdw-dev,
+               libdb-dev,
+               liblua5.1-dev
+Maintainer: Markus Lehtonen <markus.lehtonen@linux.intel.com>
+Standards-Version: 3.9.3
+Homepage: http://rpm.org/
+X-Python-Version: >= 2.6
+
+Package: librpm-tizen
+Architecture: any
+Depends: ${shlibs:Depends}, ${misc:Depends}, ${python:Depends}
+Description:  The RPM libraries for git-buildpackage
+ RPM Package Manager is the main tool for managing the software packages
+ of Tizen.
+ .
+ RPM can be used to install and remove software packages. With rpm, it
+ is easy to update packages.  RPM keeps track of all these manipulations
+ in a central database.»·This way it is possible to get an overview of
+ all installed packages.  RPM also supports database queries.
+ .
+ This is a special stripped-down version of RPM, only intended to be used by the
+ git-buildpackage tool. Doesn't interfere with the RPM libraries of the host system.
+ This package only contains rpmlib and rpm-python.
+
--- librpm-tizen-4.11.0.1.tizen20140530.orig/debian/rules
+++ librpm-tizen-4.11.0.1.tizen20140530/debian/rules
@@ -0,0 +1,33 @@
+#!/usr/bin/make -f
+
+python_mod_name := rpm_tizen
+
+CPPFLAGS += $(shell pkg-config --cflags nss)
+
+%:
+	dh $@ --with python2,autoreconf,autotools_dev
+
+override_dh_auto_configure:
+	dh_auto_configure -- --disable-dependency-tracking \
+			--libdir=/usr/lib/librpm-tizen \
+			--with-lua \
+			--without-acl \
+			--without-cap \
+			--enable-shared \
+			--enable-python \
+			--with-external-db \
+			--build=${DEB_BUILD_GNU_CPU}-tizen-linux \
+			PYTHON_MODULENAME=$(python_mod_name) \
+			LUA_PKGCONFIG_NAME=lua5.1 \
+			CPPFLAGS="$(CPPFLAGS)"
+
+override_dh_auto_install:
+	dh_auto_install --destdir=debian/tmp
+	# Install extra sources
+	install -m644 packaging/rpm-tizen_macros debian/tmp/usr/lib/librpm-tizen/rpm/tizen_macros
+	install -d debian/tmp/usr/lib/librpm-tizen/rpm/tizen
+	ln -s ../tizen_macros debian/tmp/usr/lib/librpm-tizen/rpm/tizen/macros
+
+override_dh_python2:
+	dh_python2 --no-guessing-versions
+
--- librpm-tizen-4.11.0.1.tizen20140530.orig/debian/librpm-tizen.install
+++ librpm-tizen-4.11.0.1.tizen20140530/debian/librpm-tizen.install
@@ -0,0 +1,4 @@
+usr/lib*/*/*.so.*
+usr/lib*/*/rpm/*
+usr/lib/python*/dist-packages/*/*.so
+usr/lib/python*/dist-packages/*/*.py*
--- librpm-tizen-4.11.0.1.tizen20140530.orig/debian/changelog
+++ librpm-tizen-4.11.0.1.tizen20140530/debian/changelog
@@ -0,0 +1,59 @@
+librpm-tizen (4.11.0.1.tizen20140530-tizen20140723) unstable; urgency=low
+
+  * Rebase on latest Tizen 3.0
+
+ -- Markus Lehtonen <markus.lehtonen@linux.intel.com>  Wed, 23 Jul 2014 19:50:46 +0300
+
+librpm-tizen (4.11.0.1.tizen20130618-tizen20140306) unstable; urgency=low
+
+  [ Markus Lehtonen ]
+  * Fix build against Lua 5.2
+
+ -- Markus Lehtonen <markus.lehtonen@linux.intel.com>  Thu, 06 Mar 2014 12:43:43 +0200
+
+librpm-tizen (4.11.0.1.tizen20130618-tizen20131001) unstable; urgency=low
+
+  * Ignore bad expressions in %if conditionals
+  * lua: Enable Lua
+  * lua: fall through failed lua scripts
+
+ -- Markus Lehtonen <markus.lehtonen@linux.intel.com>  Tue, 01 Oct 2013 12:12:43 +0300
+
+librpm-tizen (4.11.0.1.tizen20130618-tizen20130821) unstable; urgency=low
+
+  [ Zhang Qiang ]
+  * fix segmentation fault error while parsing spec
+
+  [ Markus Lehtonen ]
+  * Prevent execution of arbitrary scripts
+  * Bump the log level of "unexpanded script" msg
+
+ -- Markus Lehtonen <markus.lehtonen@linux.intel.com>  Wed, 21 Aug 2013 14:31:24 +0300
+
+librpm-tizen (4.11.0.1.tizen20130618-tizen20130619) unstable; urgency=low
+
+  * Version bump to latest from Tizen 3.0
+
+ -- Markus Lehtonen <markus.lehtonen@linux.intel.com>  Tue, 18 Jun 2013 14:07:13 +0300
+
+librpm-tizen (4.11.0.1.tizen20130304-tizen20130307) unstable; urgency=low
+
+  * Version bump to latest from Tizen
+
+ -- Markus Lehtonen <markus.lehtonen@linux.intel.com>  Thu, 07 Mar 2013 09:27:00 +0200
+
+librpm-tizen (4.10.91.tizen20121215-tizen20130226) unstable; urgency=low
+
+  * Enable lua
+  * Add a provide tag to make gbs depend on new changes
+  * Install Tizen macros
+  * Ignore unknown internal scripts
+
+ -- Markus Lehtonen <markus.lehtonen@linux.intel.com>  Wed, 27 Feb 2013 10:12:00 +0200
+
+librpm-tizen (4.10.91.tizen20121215-tizen20130226) unstable; urgency=low
+
+  * Initial packaging
+
+ -- Markus Lehtonen <markus.lehtonen@linux.intel.com>  Tue, 17 Dec 2012 13:22:00 +0200
+
--- librpm-tizen-4.11.0.1.tizen20140530.orig/packaging/librpm-tizen.changes
+++ librpm-tizen-4.11.0.1.tizen20140530/packaging/librpm-tizen.changes
@@ -0,0 +1,42 @@
+* Wed Jul 23 2014 Markus Lehtonen <markus.lehtonen@linux.intel.com> tizen-tools/4.11.0.1.tizen20140530-20140723
+- Rebase on latest Tizen 3.0
+- packaging: enable lua 5.2 for openSUSE
+- rpm-packaging: enable customized autoreq
+
+* Thu Mar 06 2014 Markus Lehtonen <markus.lehtonen@linux.intel.com> tizen-tools/4.11.0.1.tizen20130618-20140306
+- Fix build against Lua 5.2
+
+* Tue Oct 01 2013 Markus Lehtonen <markus.lehtonen@linux.intel.com> 4.11.0.1.tizen20130618
+- lua: fall through failed lua scripts
+- lua: Enable Lua
+- Ignore bad expressions in %if conditionals
+
+* Wed Aug 21 2013 Markus Lehtonen <markus.lehtonen@linux.intel.com> 4.11.0.1.tizen20130618
+- fix segmentation fault error while parsing spec
+- Bump the log level of "unexpanded script" msg
+- Prevent execution of arbitrary scripts
+
+* Tue Jun 18 2013 Markus Lehtonen <markus.lehtonen@linux.intel.com> 4.11.0.1.tizen20130618
+- Version bump to latest from Tizen 3.0
+
+* Thu Mar 07 2013 Markus Lehtonen <markus.lehtonen@linux.intel.com> 4.11.0.1.tizen20130304
+- Version bump to latest from Tizen
+
+* Wed Feb 27 2013 Markus Lehtonen <markus.lehtonen@linux.intel.com> 4.10.91.tizen20121215
+- Enable lua
+- update package Provide info
+- Add a provide tag to make gbs depend on new changes
+- packaging: fix Makefile
+- Install Tizen macros
+
+* Mon Feb 25 2013 Markus Lehtonen <markus.lehtonen@linux.intel.com> 4.10.91.tizen20121215
+- packaging: Disable autoreq, too
+- Ignore unknown internal scripts
+
+* Thu Feb 22 2013 Qiang Zhang <qiang.z.zhang@intel.com> 4.10.91.tizen20121215
+- packaging: fix build for CentOS
+
+* Thu Feb 21 2013 Markus Lehtonen <markus.lehtonen@linux.intel.com> 4.10.91.tizen20121215
+- packaging: Drop bdb sources
+- packaging: fix build for Fedora (18)
+- packaging: disable autoprov
--- librpm-tizen-4.11.0.1.tizen20140530.orig/packaging/librpm-tizen.spec
+++ librpm-tizen-4.11.0.1.tizen20140530/packaging/librpm-tizen.spec
@@ -0,0 +1,160 @@
+# Use custom autoreq script for filtering out all librpm* stuff
+# (basically everything that the package would auto-provide) in order to make
+# the package installable
+%define _use_internal_dependency_generator 0
+%define __find_requires bash -c "/usr/lib/rpm/find-requires | grep -v librpm"
+
+%define rpmlibdir %{_prefix}/lib
+%define rpmhome %{rpmlibdir}/rpm
+
+Name:           librpm-tizen
+Summary:        The RPM libraries for git-buildpackage
+License:        GPL-2.0+
+Group:          Development/Tools/Building
+Version:        4.11.0.1.tizen20170704
+Release:        0
+Url:            http://www.rpm.org
+BuildRequires:  binutils
+BuildRequires:  bzip2
+BuildRequires:  file-devel
+BuildRequires:  findutils
+BuildRequires:  gcc
+BuildRequires:  glibc-devel
+BuildRequires:  gzip
+BuildRequires:  libtool
+%if 0%{?suse_version}
+BuildRequires:  pkgconfig(lua)
+%else
+BuildRequires:  lua-devel
+%endif
+BuildRequires:  make
+BuildRequires:  patch
+%if 0%{?fedora} || 0%{?centos_ver} || 0%{?centos_version}
+BuildRequires:  popt-devel
+%else
+BuildRequires:  pkgconfig(popt)
+%endif
+BuildRequires:  pkgconfig(zlib)
+BuildRequires:  pkgconfig(nss)
+BuildRequires:  pkg-config
+%if 0%{?centos_ver} || 0%{?centos_version}
+BuildRequires:  python-devel
+%else
+BuildRequires:  pkgconfig(python) >= 2.6
+%endif
+# Disable security
+%if 0
+BuildRequires:  uthash-devel
+BuildRequires:  pkgconfig(libxml-2.0)
+BuildRequires:  pkgconfig(libsmack)
+%endif
+%if 0%{?suse_version}
+BuildRequires:  fdupes
+%endif
+%if 0%{?fedora} || 0%{?centos_ver} >= 7
+BuildRequires:  libdb-devel
+%else
+BuildRequires:  db-devel
+%endif
+
+Source4:       rpm-tizen_macros
+Source8:       rpmconfigcheck
+Source13:      find-docs.sh
+Source22:      device-sec-policy
+Source23:      find-provides.ksyms
+Source1001:    rpm.manifest
+Source0:        rpm-%{version}.tar.gz
+AutoProv:       No
+
+Provides:       rpm-tizen = %{version}-tizen20140723
+#
+# avoid bootstrapping problem
+%define _binary_payload w9.bzdio
+#
+# Python module name
+%define python_mod_name rpm_tizen
+
+%description
+RPM Package Manager is the main tool for managing the software packages
+of Tizen.
+
+RPM can be used to install and remove software packages. With rpm, it
+is easy to update packages.  RPM keeps track of all these manipulations
+in a central database.	This way it is possible to get an overview of
+all installed packages.  RPM also supports database queries.
+
+This is a special stripped-down version of RPM, only intended to be used by the
+git-buildpackage tool. This package doesn't interfere with the RPM libraries of
+the host system and it only contains rpmlib and rpm-python.
+
+%prep
+%setup -q -n rpm-%{version}
+cp %{SOURCE1001} .
+rm -rf sqlite
+if [ -s %{_sysconfdir}/rpm/tizen_macros ]; then
+    cp -a %{_sysconfdir}/rpm/tizen_macros %{SOURCE4}
+fi
+cp -a %{SOURCE4} tizen_macros
+rm -f m4/libtool.m4
+rm -f m4/lt*.m4
+
+%build
+CPPFLAGS="$CPPFLAGS `pkg-config --cflags nss`"
+export CPPFLAGS
+export CFLAGS="%{optflags} -ffunction-sections"
+export LDFLAGS="${LDFLAGS} -Wl,-Bsymbolic-functions -ffunction-sections"
+%ifarch armv5tel
+export CFLAGS="-g -O0 -fno-strict-aliasing -ffunction-sections"
+%endif
+
+autoreconf -i -f
+%configure \
+    --libdir=%{_libdir}/%{name} \
+    --disable-dependency-tracking \
+    --with-lua \
+    --without-acl \
+    --without-cap \
+    --enable-shared \
+    --enable-python \
+    --without-msm \
+    --with-external-db \
+    PYTHON_MODULENAME=%{python_mod_name}
+
+make %{?_smp_mflags}
+
+%install
+# Install into a temporary location
+make install DESTDIR="`pwd`/tmp_install"
+
+# And only copy the files that we want
+install -d %{buildroot}%{_libdir}/%{name}
+install -d %{buildroot}%{python_sitearch}
+cp -ax tmp_install/%{_libdir}/%{name}  %{buildroot}%{_libdir}/
+cp -ax tmp_install/%{python_sitearch}/%{python_mod_name} %{buildroot}%{python_sitearch}/
+
+# Install extra sources
+install -m644 %{SOURCE4} %{buildroot}%{_libdir}/%{name}/rpm/tizen_macros
+install -d %{buildroot}%{_libdir}/%{name}/rpm/tizen
+ln -s ../tizen_macros %{buildroot}%{_libdir}/%{name}/rpm/tizen/macros
+
+# Delete unwanted development files etc.
+find %{buildroot} -name "*.la" | xargs rm -f --
+find %{buildroot}/%{_libdir}/%{name} -name "*.so" | xargs rm -f --
+rm -rf "%{buildroot}%{_libdir}/%{name}/pkgconfig"
+rm -rf "%{buildroot}%{_libdir}/%{name}/rpm-plugins"
+
+# Compile python modules (Fedora does this automatically) and find duplicates
+%if 0%{?suse_version}
+%py_compile %{buildroot}/%{python_sitearch}/%{python_mod_name}/
+%py_compile -O %{buildroot}/%{python_sitearch}/%{python_mod_name}/
+
+%fdupes %{buildroot}/%{python_sitearch}/
+%endif
+
+%files
+%defattr(-,root,root,-)
+%dir %{_libdir}/%{name}
+%dir %{python_sitearch}/%{python_mod_name}/
+%{_libdir}/%{name}/*.so.*
+%{_libdir}/%{name}/rpm
+%{python_sitearch}/%{python_mod_name}/*
