My goal is to come up with a spec file that defines subpackages dynamically.
Currently, I have a macro defined in the spec file so that I can call it with different parameters to generate different %package sections. Eg.
%define create_pkg(n:)\ %package -n subpackage-%1\ Summary: Subpackage %1\ ...\ %{nil}
%create_pkg sub1 %create_pkg sub2 %create_pkg sub3
However, I can only hard-code the parameters (sub1, sub2, sub3) of the create_pkg macro in the specfile. Is there a way to make the specfile read a separate file, which would contain the names o开发者_JS百科f the subpackages I want? eg. subpackages.txt would have the following:
sub1 sub2 sub3
and the spec file would read subpackages.txt and call %create_pkg with the names read from the txt file.
Answering my own question. If the rpm has lua script build-in (it's a build time option I think), then you can use lua scripts in the file
1) define the sub packages in a separate file, eg. targets.txt:
%define build_targets sub1 sub2 sub3
2) include targets.txt at the beginning of the spec file:
%include targets.txt
3) use lua script to iterate through the targets in the preamble section:
%{lua:
for target in string.gmatch(rpm.expand("%{build_targets}"), "[%w_-]+")
do
print("%package "..target.."\n")
print("Summary: subpackage "..target.."\n")
...
print("%description "..target.."\n")
end
then the %package directive for the sub packages will be dynamically generated.
精彩评论