If condition inside the %Files section on a SPEC file

后端 未结 4 1650
故里飘歌
故里飘歌 2021-01-13 08:14

I\'m kinda a new to writing spec files and building RPM\'s. Currently I have one RPM that is supposed to deploy some files in 1 of 2 possible directories that will vary with

4条回答
  •  心在旅途
    2021-01-13 08:34

    I had a similar situation where additional files were included in the RPM in case of a DEBUG build over and above all files in the RELEASE build.

    The trick is to pass a list of files to %files alongwith a regular list of files below it:

    %install
    # Create a temporary file containing the list of files
    EXTRA_FILES=$RPM_BUILD_ROOT/ExtraFiles.list
    touch %{EXTRA_FILES}
    
    # If building in DEBUG mode, then include additional test binaries in the package
    %if %{build_mode} == "DEBUG"
    # %{build_mode} is a variable that is passed to the spec file when invoked by the build script
    # Like: rpmbuild --define "build_mode DEBUG"
    echo path/to/file1 > %{EXTRA_FILES}
    echo path/to/file2 >> %{EXTRA_FILES}
    %endif
    
    %files -f %{EXTRA_FILES}
    path/to/release/file1
    path/to/release/file2
    

    In your case, you can leverage the %if conditional in the %install section, use the OS as a spec variable passed to rpmbuild (or detect it in the RPM spec itself) and then pass the file containing the list to %files

提交回复
热议问题