7 from optparse import OptionParser
11 usage = "%prog [rpmbuild-options] specfile pkg-name"
12 parser = OptionParser(usage=usage)
14 '-t', '--target', action='store', dest='target', default=None,
15 help='specify target arch')
17 '-w', '--whitelist-rpms', action='store', dest='whitelist', default='',
18 help='comma separated list of rpms to expose in makefile')
20 '-1', '--with', action='store', dest='with', default='',
21 help='accept but ignore --with option')
23 '-0', '--without', action='store', dest='without', default='',
24 help='accept but ignore --without option')
26 '-d', '--define', action='store', dest='define', default='',
27 help='accept but ignore --define option')
28 (options, args) = parser.parse_args()
31 specfile, package_name = args
36 transaction_set = rpm.TransactionSet()
37 specobj = transaction_set.parseSpec(specfile)
38 for (fullsource, _, _) in specobj.sources:
39 # print '###fullsource=',fullsource
40 print("%s.tarballs += SOURCES/%s" %
41 (package_name, os.path.basename(fullsource)))
42 for suffix in [".tar.gz", ".tgz", ".tar.bz2", ".tar.xz"]:
43 # print "# trying %s"%suffix
44 if fullsource.endswith(suffix):
45 sourcename = fullsource.replace(suffix, "")
46 print("%s.source := SOURCES/%s" %
47 (package_name, os.path.basename(sourcename)))
50 # Get SRPM name from name of first package
51 package = specobj.packages[0]
52 header0 = package.header
53 name = header0.format('%{name}')
54 version = header0.format('%{version}')
55 release = header0.format('%{release}')
56 print("%s.srpm := SRPMS/%s-%s-%s.src.rpm" %
57 (package_name, name, version, release))
59 target = options.target
60 whitelist = [x for x in options.whitelist.split(',') if x]
61 # Print non-empty packages
63 for package in specobj.packages:
65 header = package.header
66 name = header.format('%{name}')
67 version = header.format('%{version}')
68 release = header.format('%{release}')
69 arch = target or header.format('%{arch}')
72 if not (name and version and release and arch):
75 # select relevant packages
76 # could not find the magic recipe to do this properly yet
77 # so ugly temporary hack :
78 # when whitelisted, we expose the first package plus the white-listed ones
79 # otherwise we expose everything
87 relevant = name in whitelist
90 # attach (add) rpm path to package
91 print("%s.rpms += RPMS/%s/%s-%s-%s.%s.rpm" %
92 (package_name, arch, name, version, release, arch))
94 print("%s.rpmnames += %s" %
96 # attach path to rpm name
97 print("%s.rpm-path := RPMS/%s/%s-%s-%s.%s.rpm" %
98 (name, arch, name, version, release, arch))
99 # attach package to rpm name for backward resolution - should be unique
100 print("%s.package := %s" %
101 (name, package_name))
103 for macro in ["release", "name", "version", "taglevel", ]:
104 format = "%%{%s}" % macro
106 print("%s.rpm-%s := %s" %
107 (package_name, macro, header0.format(format)))
109 print("# %s.rpm-%s undefined" % (package_name, macro))
112 print("%s.rpm-arch := %s" % (package_name, target))
115 if __name__ == '__main__':