0

I only want files copied into an RPM spec file under a certain condition like:

%install 
if [ %{test}=="true" ]; 
then
    cp %{topdirectory}/file1.txt $RPM_BUILD_ROOT/home/user1
fi

%files
if [ %{test}=="true" ]; 
then
   %attr(0644, user1,user1) /home/user1/file1.txt
fi

When I execute rpmbuild I pass in a flag to define what "test" is, like:

rpmbuild --define="test true" --bb --quiet myspecfile.spec

However, I get an error message that looks like:

error: File must begin with "/": if
error: File must begin with "/": [
error: File must begin with "/": false=="true"
error: File must begin with "/": ]; 
error: File must begin with "/": then
error: File must begin with "/": fi

I'm not really sure what this error message means, but it clearly does not like me putting an if statement near the %files macro or the %install macro. How do I change my if statement to make rpmbuild happy?

1 Answer 1

1

Spec has its own syntax for conditionals, you need to use something like this:

%if %{test} == "true"
%attr(0644, user1,user1) /home/user1/file1.txt
%endif

You can read more about spec syntax here.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .