7 from optparse import OptionParser
10 usage="%prog [rpmbuild-options] specfile pkg-name"
11 parser=OptionParser(usage=usage)
12 parser.add_option('-t','--target',action='store',dest='target',default=None,
13 help='specify target arch')
14 parser.add_option('-w','--whitelist-rpms',action='store',dest='whitelist',default='',
15 help='comma separated list of rpms to expose in makefile')
16 parser.add_option('-1','--with',action='store',dest='with',default='',
17 help='accept but ignore --with option')
18 parser.add_option('-0','--without',action='store',dest='without',default='',
19 help='accept but ignore --without option')
20 parser.add_option('-d','--define',action='store',dest='define',default='',
21 help='accept but ignore --define option')
22 (options,args) = parser.parse_args()
25 [specfile,package_name]=args
30 ts=rpm.TransactionSet()
31 specobj = ts.parseSpec(specfile)
32 for (fullsource,_,__) in specobj.sources:
33 #print '###fullsource=',fullsource
34 print "%s.tarballs += SOURCES/%s" %(package_name,os.path.basename(fullsource))
35 for suffix in [".tar.gz", ".tgz", ".tar.bz2", ] :
36 #print "# trying %s"%suffix
37 if fullsource.endswith(suffix):
38 sourcename=fullsource.replace(suffix,"")
39 print "%s.source := SOURCES/%s" %(package_name,os.path.basename(sourcename))
42 # Get SRPM name from name of first package
43 package=specobj.packages[0]
44 header0=package.header
45 name=header0.format('%{name}')
46 version=header0.format('%{version}')
47 release=header0.format('%{release}')
48 print "%s.srpm := SRPMS/%s-%s-%s.src.rpm"%(package_name, name, version, release)
50 target = options.target
51 whitelist=[ x for x in options.whitelist.split(',') if x]
52 # Print non-empty packages
54 for package in specobj.packages:
57 name=header.format('%{name}')
58 version=header.format('%{version}')
59 release=header.format('%{release}')
60 arch=target or header.format('%{arch}')
63 if not (name and version and release and arch) : continue
65 # select relevant packages
66 # could not find the magic recipe to do this properly yet
67 # so ugly temporary hack :
68 # when whitelisted, we expose the first package plus the white-listed ones
69 # otherwise we expose everything
71 if not whitelist: relevant=True
73 if counter==1: relevant=True
74 else: relevant=name in whitelist
77 # attach (add) rpm path to package
78 print "%s.rpms += RPMS/%s/%s-%s-%s.%s.rpm"%\
79 (package_name, arch, name, version, release, arch)
81 print "%s.rpmnames += %s"%\
83 # attach path to rpm name
84 print "%s.rpm-path := RPMS/%s/%s-%s-%s.%s.rpm"%\
85 (name,arch, name, version, release, arch)
86 # attach package to rpm name for backward resolution - should be unique
87 print "%s.package := %s"%\
90 for macro in ["release" , "name" , "version" , "taglevel" , ] :
92 try: print "%s.rpm-%s := %s"%(package_name,macro,header0.format(format))
93 except : print "# %s.rpm-%s undefined"%(package_name,macro)
96 print "%s.rpm-arch := %s"%(package_name,target)
98 if __name__ == '__main__':