CPack/RPM prevent component attributes leakage

Fixes mantis bug report with id 15169. Some
component specific attributes were leaking
to next component. Leakage handling was
implemented in different locations but there
were still attributes that leaked. Patch
encapsulates generator into function so all
current leaks are fixed and no future leaks
can occur.
This commit is contained in:
Domen Vrankar 2015-03-16 22:17:17 +01:00
parent ffc1b94510
commit be089724e9
1 changed files with 662 additions and 693 deletions

View File

@ -494,14 +494,15 @@ if(NOT UNIX)
message(FATAL_ERROR "CPackRPM.cmake may only be used under UNIX.") message(FATAL_ERROR "CPackRPM.cmake may only be used under UNIX.")
endif() endif()
# rpmbuild is the basic command for building RPM package function(cpack_rpm_generate_package)
# it may be a simple (symbolic) link to rpm command. # rpmbuild is the basic command for building RPM package
find_program(RPMBUILD_EXECUTABLE rpmbuild) # it may be a simple (symbolic) link to rpm command.
find_program(RPMBUILD_EXECUTABLE rpmbuild)
# Check version of the rpmbuild tool this would be easier to # Check version of the rpmbuild tool this would be easier to
# track bugs with users and CPackRPM debug mode. # track bugs with users and CPackRPM debug mode.
# We may use RPM version in order to check for available version dependent features # We may use RPM version in order to check for available version dependent features
if(RPMBUILD_EXECUTABLE) if(RPMBUILD_EXECUTABLE)
execute_process(COMMAND ${RPMBUILD_EXECUTABLE} --version execute_process(COMMAND ${RPMBUILD_EXECUTABLE} --version
OUTPUT_VARIABLE _TMP_VERSION OUTPUT_VARIABLE _TMP_VERSION
ERROR_QUIET ERROR_QUIET
@ -512,16 +513,16 @@ if(RPMBUILD_EXECUTABLE)
if(CPACK_RPM_PACKAGE_DEBUG) if(CPACK_RPM_PACKAGE_DEBUG)
message("CPackRPM:Debug: rpmbuild version is <${RPMBUILD_EXECUTABLE_VERSION}>") message("CPackRPM:Debug: rpmbuild version is <${RPMBUILD_EXECUTABLE_VERSION}>")
endif() endif()
endif() endif()
if(NOT RPMBUILD_EXECUTABLE) if(NOT RPMBUILD_EXECUTABLE)
message(FATAL_ERROR "RPM package requires rpmbuild executable") message(FATAL_ERROR "RPM package requires rpmbuild executable")
endif() endif()
# Display lsb_release output if DEBUG mode enable # Display lsb_release output if DEBUG mode enable
# This will help to diagnose problem with CPackRPM # This will help to diagnose problem with CPackRPM
# because we will know on which kind of Linux we are # because we will know on which kind of Linux we are
if(CPACK_RPM_PACKAGE_DEBUG) if(CPACK_RPM_PACKAGE_DEBUG)
find_program(LSB_RELEASE_EXECUTABLE lsb_release) find_program(LSB_RELEASE_EXECUTABLE lsb_release)
if(LSB_RELEASE_EXECUTABLE) if(LSB_RELEASE_EXECUTABLE)
execute_process(COMMAND ${LSB_RELEASE_EXECUTABLE} -a execute_process(COMMAND ${LSB_RELEASE_EXECUTABLE} -a
@ -535,193 +536,173 @@ if(CPACK_RPM_PACKAGE_DEBUG)
set(LSB_RELEASE_OUTPUT "lsb_release not installed/found!") set(LSB_RELEASE_OUTPUT "lsb_release not installed/found!")
endif() endif()
message("CPackRPM:Debug: LSB_RELEASE = ${LSB_RELEASE_OUTPUT}") message("CPackRPM:Debug: LSB_RELEASE = ${LSB_RELEASE_OUTPUT}")
endif() endif()
# We may use RPM version in the future in order # We may use RPM version in the future in order
# to shut down warning about space in buildtree # to shut down warning about space in buildtree
# some recent RPM version should support space in different places. # some recent RPM version should support space in different places.
# not checked [yet]. # not checked [yet].
if(CPACK_TOPLEVEL_DIRECTORY MATCHES ".* .*") if(CPACK_TOPLEVEL_DIRECTORY MATCHES ".* .*")
message(FATAL_ERROR "${RPMBUILD_EXECUTABLE} can't handle paths with spaces, use a build directory without spaces for building RPMs.") message(FATAL_ERROR "${RPMBUILD_EXECUTABLE} can't handle paths with spaces, use a build directory without spaces for building RPMs.")
endif() endif()
# If rpmbuild is found # If rpmbuild is found
# we try to discover alien since we may be on non RPM distro like Debian. # we try to discover alien since we may be on non RPM distro like Debian.
# In this case we may try to to use more advanced features # In this case we may try to to use more advanced features
# like generating RPM directly from DEB using alien. # like generating RPM directly from DEB using alien.
# FIXME feature not finished (yet) # FIXME feature not finished (yet)
find_program(ALIEN_EXECUTABLE alien) find_program(ALIEN_EXECUTABLE alien)
if(ALIEN_EXECUTABLE) if(ALIEN_EXECUTABLE)
message(STATUS "alien found, we may be on a Debian based distro.") message(STATUS "alien found, we may be on a Debian based distro.")
endif() endif()
# Are we packaging components ? # Are we packaging components ?
if(CPACK_RPM_PACKAGE_COMPONENT) if(CPACK_RPM_PACKAGE_COMPONENT)
set(CPACK_RPM_PACKAGE_COMPONENT_PART_NAME "-${CPACK_RPM_PACKAGE_COMPONENT}") set(CPACK_RPM_PACKAGE_COMPONENT_PART_NAME "-${CPACK_RPM_PACKAGE_COMPONENT}")
string(TOUPPER ${CPACK_RPM_PACKAGE_COMPONENT} CPACK_RPM_PACKAGE_COMPONENT_UPPER) string(TOUPPER ${CPACK_RPM_PACKAGE_COMPONENT} CPACK_RPM_PACKAGE_COMPONENT_UPPER)
else() else()
set(CPACK_RPM_PACKAGE_COMPONENT_PART_NAME "") set(CPACK_RPM_PACKAGE_COMPONENT_PART_NAME "")
endif() endif()
set(WDIR "${CPACK_TOPLEVEL_DIRECTORY}/${CPACK_PACKAGE_FILE_NAME}${CPACK_RPM_PACKAGE_COMPONENT_PART_PATH}") set(WDIR "${CPACK_TOPLEVEL_DIRECTORY}/${CPACK_PACKAGE_FILE_NAME}${CPACK_RPM_PACKAGE_COMPONENT_PART_PATH}")
# #
# Use user-defined RPM specific variables value # Use user-defined RPM specific variables value
# or generate reasonable default value from # or generate reasonable default value from
# CPACK_xxx generic values. # CPACK_xxx generic values.
# The variables comes from the needed (mandatory or not) # The variables comes from the needed (mandatory or not)
# values found in the RPM specification file aka ".spec" file. # values found in the RPM specification file aka ".spec" file.
# The variables which may/should be defined are: # The variables which may/should be defined are:
# #
# CPACK_RPM_PACKAGE_SUMMARY (mandatory) # CPACK_RPM_PACKAGE_SUMMARY (mandatory)
# CPACK_RPM_PACKAGE_SUMMARY_ is used only locally so that it can be unset each time before use otherwise #Check for component summary first.
# component packaging could leak variable content between components #If not set, it will use regular package summary logic.
unset(CPACK_RPM_PACKAGE_SUMMARY_) if(CPACK_RPM_PACKAGE_COMPONENT)
if(CPACK_RPM_PACKAGE_SUMMARY)
set(CPACK_RPM_PACKAGE_SUMMARY_ ${CPACK_RPM_PACKAGE_SUMMARY})
unset(CPACK_RPM_PACKAGE_SUMMARY)
endif()
#Check for component summary first.
#If not set, it will use regular package summary logic.
if(CPACK_RPM_PACKAGE_COMPONENT)
if(CPACK_RPM_${CPACK_RPM_PACKAGE_COMPONENT}_PACKAGE_SUMMARY) if(CPACK_RPM_${CPACK_RPM_PACKAGE_COMPONENT}_PACKAGE_SUMMARY)
set(CPACK_RPM_PACKAGE_SUMMARY ${CPACK_RPM_${CPACK_RPM_PACKAGE_COMPONENT}_PACKAGE_SUMMARY}) set(CPACK_RPM_PACKAGE_SUMMARY ${CPACK_RPM_${CPACK_RPM_PACKAGE_COMPONENT}_PACKAGE_SUMMARY})
endif() endif()
endif() endif()
if(NOT CPACK_RPM_PACKAGE_SUMMARY) if(NOT CPACK_RPM_PACKAGE_SUMMARY)
if(CPACK_RPM_PACKAGE_SUMMARY_) if(CPACK_PACKAGE_DESCRIPTION_SUMMARY)
set(CPACK_RPM_PACKAGE_SUMMARY ${CPACK_RPM_PACKAGE_SUMMARY_})
elseif(CPACK_PACKAGE_DESCRIPTION_SUMMARY)
set(CPACK_RPM_PACKAGE_SUMMARY ${CPACK_PACKAGE_DESCRIPTION_SUMMARY}) set(CPACK_RPM_PACKAGE_SUMMARY ${CPACK_PACKAGE_DESCRIPTION_SUMMARY})
else() else()
# if neither var is defined lets use the name as summary # if neither var is defined lets use the name as summary
string(TOLOWER "${CPACK_PACKAGE_NAME}" CPACK_RPM_PACKAGE_SUMMARY) string(TOLOWER "${CPACK_PACKAGE_NAME}" CPACK_RPM_PACKAGE_SUMMARY)
endif() endif()
endif() endif()
# CPACK_RPM_PACKAGE_NAME (mandatory) # CPACK_RPM_PACKAGE_NAME (mandatory)
if(NOT CPACK_RPM_PACKAGE_NAME) if(NOT CPACK_RPM_PACKAGE_NAME)
string(TOLOWER "${CPACK_PACKAGE_NAME}" CPACK_RPM_PACKAGE_NAME) string(TOLOWER "${CPACK_PACKAGE_NAME}" CPACK_RPM_PACKAGE_NAME)
endif() endif()
# CPACK_RPM_PACKAGE_VERSION (mandatory) # CPACK_RPM_PACKAGE_VERSION (mandatory)
if(NOT CPACK_RPM_PACKAGE_VERSION) if(NOT CPACK_RPM_PACKAGE_VERSION)
if(NOT CPACK_PACKAGE_VERSION) if(NOT CPACK_PACKAGE_VERSION)
message(FATAL_ERROR "RPM package requires a package version") message(FATAL_ERROR "RPM package requires a package version")
endif() endif()
set(CPACK_RPM_PACKAGE_VERSION ${CPACK_PACKAGE_VERSION}) set(CPACK_RPM_PACKAGE_VERSION ${CPACK_PACKAGE_VERSION})
endif() endif()
# Replace '-' in version with '_' # Replace '-' in version with '_'
# '-' character is an Illegal RPM version character # '-' character is an Illegal RPM version character
# it is illegal because it is used to separate # it is illegal because it is used to separate
# RPM "Version" from RPM "Release" # RPM "Version" from RPM "Release"
string(REPLACE "-" "_" CPACK_RPM_PACKAGE_VERSION ${CPACK_RPM_PACKAGE_VERSION}) string(REPLACE "-" "_" CPACK_RPM_PACKAGE_VERSION ${CPACK_RPM_PACKAGE_VERSION})
# CPACK_RPM_PACKAGE_ARCHITECTURE (mandatory) # CPACK_RPM_PACKAGE_ARCHITECTURE (mandatory)
if(NOT CPACK_RPM_PACKAGE_ARCHITECTURE) if(NOT CPACK_RPM_PACKAGE_ARCHITECTURE)
execute_process(COMMAND uname "-m" execute_process(COMMAND uname "-m"
OUTPUT_VARIABLE CPACK_RPM_PACKAGE_ARCHITECTURE OUTPUT_VARIABLE CPACK_RPM_PACKAGE_ARCHITECTURE
OUTPUT_STRIP_TRAILING_WHITESPACE) OUTPUT_STRIP_TRAILING_WHITESPACE)
else() else()
if(CPACK_RPM_PACKAGE_DEBUG) if(CPACK_RPM_PACKAGE_DEBUG)
message("CPackRPM:Debug: using user-specified build arch = ${CPACK_RPM_PACKAGE_ARCHITECTURE}") message("CPackRPM:Debug: using user-specified build arch = ${CPACK_RPM_PACKAGE_ARCHITECTURE}")
endif() endif()
endif() endif()
set(_CPACK_RPM_PACKAGE_ARCHITECTURE ${CPACK_RPM_PACKAGE_ARCHITECTURE}) set(_CPACK_RPM_PACKAGE_ARCHITECTURE ${CPACK_RPM_PACKAGE_ARCHITECTURE})
#prefer component architecture #prefer component architecture
if(CPACK_RPM_PACKAGE_COMPONENT) if(CPACK_RPM_PACKAGE_COMPONENT)
if(CPACK_RPM_${CPACK_RPM_PACKAGE_COMPONENT}_PACKAGE_ARCHITECTURE) if(CPACK_RPM_${CPACK_RPM_PACKAGE_COMPONENT}_PACKAGE_ARCHITECTURE)
set(_CPACK_RPM_PACKAGE_ARCHITECTURE ${CPACK_RPM_${CPACK_RPM_PACKAGE_COMPONENT}_PACKAGE_ARCHITECTURE}) set(_CPACK_RPM_PACKAGE_ARCHITECTURE ${CPACK_RPM_${CPACK_RPM_PACKAGE_COMPONENT}_PACKAGE_ARCHITECTURE})
if(CPACK_RPM_PACKAGE_DEBUG) if(CPACK_RPM_PACKAGE_DEBUG)
message("CPackRPM:Debug: using component build arch = ${_CPACK_RPM_PACKAGE_ARCHITECTURE}") message("CPackRPM:Debug: using component build arch = ${_CPACK_RPM_PACKAGE_ARCHITECTURE}")
endif() endif()
endif() endif()
endif() endif()
if(${_CPACK_RPM_PACKAGE_ARCHITECTURE} STREQUAL "noarch") if(${_CPACK_RPM_PACKAGE_ARCHITECTURE} STREQUAL "noarch")
set(TMP_RPM_BUILDARCH "Buildarch: ${_CPACK_RPM_PACKAGE_ARCHITECTURE}") set(TMP_RPM_BUILDARCH "Buildarch: ${_CPACK_RPM_PACKAGE_ARCHITECTURE}")
else() else()
set(TMP_RPM_BUILDARCH "") set(TMP_RPM_BUILDARCH "")
endif() endif()
# CPACK_RPM_PACKAGE_RELEASE # CPACK_RPM_PACKAGE_RELEASE
# The RPM release is the numbering of the RPM package ITSELF # The RPM release is the numbering of the RPM package ITSELF
# this is the version of the PACKAGING and NOT the version # this is the version of the PACKAGING and NOT the version
# of the CONTENT of the package. # of the CONTENT of the package.
# You may well need to generate a new RPM package release # You may well need to generate a new RPM package release
# without changing the version of the packaged software. # without changing the version of the packaged software.
# This is the case when the packaging is buggy (not) the software :=) # This is the case when the packaging is buggy (not) the software :=)
# If not set, 1 is a good candidate # If not set, 1 is a good candidate
if(NOT CPACK_RPM_PACKAGE_RELEASE) if(NOT CPACK_RPM_PACKAGE_RELEASE)
set(CPACK_RPM_PACKAGE_RELEASE 1) set(CPACK_RPM_PACKAGE_RELEASE 1)
endif() endif()
# CPACK_RPM_PACKAGE_LICENSE # CPACK_RPM_PACKAGE_LICENSE
if(NOT CPACK_RPM_PACKAGE_LICENSE) if(NOT CPACK_RPM_PACKAGE_LICENSE)
set(CPACK_RPM_PACKAGE_LICENSE "unknown") set(CPACK_RPM_PACKAGE_LICENSE "unknown")
endif() endif()
# CPACK_RPM_PACKAGE_GROUP # CPACK_RPM_PACKAGE_GROUP
if(NOT CPACK_RPM_PACKAGE_GROUP) if(NOT CPACK_RPM_PACKAGE_GROUP)
set(CPACK_RPM_PACKAGE_GROUP "unknown") set(CPACK_RPM_PACKAGE_GROUP "unknown")
endif() endif()
# CPACK_RPM_PACKAGE_VENDOR # CPACK_RPM_PACKAGE_VENDOR
if(NOT CPACK_RPM_PACKAGE_VENDOR) if(NOT CPACK_RPM_PACKAGE_VENDOR)
if(CPACK_PACKAGE_VENDOR) if(CPACK_PACKAGE_VENDOR)
set(CPACK_RPM_PACKAGE_VENDOR "${CPACK_PACKAGE_VENDOR}") set(CPACK_RPM_PACKAGE_VENDOR "${CPACK_PACKAGE_VENDOR}")
else() else()
set(CPACK_RPM_PACKAGE_VENDOR "unknown") set(CPACK_RPM_PACKAGE_VENDOR "unknown")
endif() endif()
endif() endif()
# CPACK_RPM_PACKAGE_SOURCE # CPACK_RPM_PACKAGE_SOURCE
# The name of the source tarball in case we generate a source RPM # The name of the source tarball in case we generate a source RPM
# CPACK_RPM_PACKAGE_DESCRIPTION # CPACK_RPM_PACKAGE_DESCRIPTION
# The variable content may be either # The variable content may be either
# - explicitly given by the user or # - explicitly given by the user or
# - filled with the content of CPACK_PACKAGE_DESCRIPTION_FILE # - filled with the content of CPACK_PACKAGE_DESCRIPTION_FILE
# if it is defined # if it is defined
# - set to a default value # - set to a default value
# #
# CPACK_RPM_PACKAGE_DESCRIPTION_ is used only locally so that it can be unset each time before use otherwise #Check for a component description first.
# component packaging could leak variable content between components #If not set, it will use regular package description logic.
unset(CPACK_RPM_PACKAGE_DESCRIPTION_) if(CPACK_RPM_PACKAGE_COMPONENT)
if(CPACK_RPM_PACKAGE_DESCRIPTION)
set(CPACK_RPM_PACKAGE_DESCRIPTION_ ${CPACK_RPM_PACKAGE_DESCRIPTION})
unset(CPACK_RPM_PACKAGE_DESCRIPTION)
endif()
#Check for a component description first.
#If not set, it will use regular package description logic.
if(CPACK_RPM_PACKAGE_COMPONENT)
if(CPACK_RPM_${CPACK_RPM_PACKAGE_COMPONENT}_PACKAGE_DESCRIPTION) if(CPACK_RPM_${CPACK_RPM_PACKAGE_COMPONENT}_PACKAGE_DESCRIPTION)
set(CPACK_RPM_PACKAGE_DESCRIPTION ${CPACK_RPM_${CPACK_RPM_PACKAGE_COMPONENT}_PACKAGE_DESCRIPTION}) set(CPACK_RPM_PACKAGE_DESCRIPTION ${CPACK_RPM_${CPACK_RPM_PACKAGE_COMPONENT}_PACKAGE_DESCRIPTION})
elseif(CPACK_COMPONENT_${CPACK_RPM_PACKAGE_COMPONENT_UPPER}_DESCRIPTION) elseif(CPACK_COMPONENT_${CPACK_RPM_PACKAGE_COMPONENT_UPPER}_DESCRIPTION)
set(CPACK_RPM_PACKAGE_DESCRIPTION ${CPACK_COMPONENT_${CPACK_RPM_PACKAGE_COMPONENT_UPPER}_DESCRIPTION}) set(CPACK_RPM_PACKAGE_DESCRIPTION ${CPACK_COMPONENT_${CPACK_RPM_PACKAGE_COMPONENT_UPPER}_DESCRIPTION})
endif() endif()
endif() endif()
if(NOT CPACK_RPM_PACKAGE_DESCRIPTION) if(NOT CPACK_RPM_PACKAGE_DESCRIPTION)
if(CPACK_RPM_PACKAGE_DESCRIPTION_) if(CPACK_PACKAGE_DESCRIPTION_FILE)
set(CPACK_RPM_PACKAGE_DESCRIPTION ${CPACK_RPM_PACKAGE_DESCRIPTION_})
elseif(CPACK_PACKAGE_DESCRIPTION_FILE)
file(READ ${CPACK_PACKAGE_DESCRIPTION_FILE} CPACK_RPM_PACKAGE_DESCRIPTION) file(READ ${CPACK_PACKAGE_DESCRIPTION_FILE} CPACK_RPM_PACKAGE_DESCRIPTION)
else () else ()
set(CPACK_RPM_PACKAGE_DESCRIPTION "no package description available") set(CPACK_RPM_PACKAGE_DESCRIPTION "no package description available")
endif () endif ()
endif () endif ()
# CPACK_RPM_COMPRESSION_TYPE # CPACK_RPM_COMPRESSION_TYPE
# #
if (CPACK_RPM_COMPRESSION_TYPE) if (CPACK_RPM_COMPRESSION_TYPE)
if(CPACK_RPM_PACKAGE_DEBUG) if(CPACK_RPM_PACKAGE_DEBUG)
message("CPackRPM:Debug: User Specified RPM compression type: ${CPACK_RPM_COMPRESSION_TYPE}") message("CPackRPM:Debug: User Specified RPM compression type: ${CPACK_RPM_COMPRESSION_TYPE}")
endif() endif()
@ -737,16 +718,14 @@ if (CPACK_RPM_COMPRESSION_TYPE)
if(CPACK_RPM_COMPRESSION_TYPE STREQUAL "gzip") if(CPACK_RPM_COMPRESSION_TYPE STREQUAL "gzip")
set(CPACK_RPM_COMPRESSION_TYPE_TMP "%define _binary_payload w9.gzdio") set(CPACK_RPM_COMPRESSION_TYPE_TMP "%define _binary_payload w9.gzdio")
endif() endif()
else() else()
set(CPACK_RPM_COMPRESSION_TYPE_TMP "") set(CPACK_RPM_COMPRESSION_TYPE_TMP "")
endif() endif()
if(CPACK_PACKAGE_RELOCATABLE) if(CPACK_PACKAGE_RELOCATABLE)
set(CPACK_RPM_PACKAGE_RELOCATABLE TRUE) set(CPACK_RPM_PACKAGE_RELOCATABLE TRUE)
endif() endif()
if(CPACK_RPM_PACKAGE_RELOCATABLE) if(CPACK_RPM_PACKAGE_RELOCATABLE)
unset(TMP_RPM_PREFIXES)
if(CPACK_RPM_PACKAGE_DEBUG) if(CPACK_RPM_PACKAGE_DEBUG)
message("CPackRPM:Debug: Trying to build a relocatable package") message("CPackRPM:Debug: Trying to build a relocatable package")
endif() endif()
@ -756,13 +735,13 @@ if(CPACK_RPM_PACKAGE_RELOCATABLE)
set(CPACK_RPM_PACKAGE_PREFIX ${CPACK_PACKAGING_INSTALL_PREFIX}) # kept for back compatibility (provided external RPM spec files) set(CPACK_RPM_PACKAGE_PREFIX ${CPACK_PACKAGING_INSTALL_PREFIX}) # kept for back compatibility (provided external RPM spec files)
cpack_rpm_prepare_relocation_paths() cpack_rpm_prepare_relocation_paths()
endif() endif()
endif() endif()
# Check if additional fields for RPM spec header are given # Check if additional fields for RPM spec header are given
# There may be some COMPONENT specific variables as well # There may be some COMPONENT specific variables as well
# If component specific var is not provided we use the global one # If component specific var is not provided we use the global one
# for each component # for each component
foreach(_RPM_SPEC_HEADER URL REQUIRES SUGGESTS PROVIDES OBSOLETES PREFIX CONFLICTS AUTOPROV AUTOREQ AUTOREQPROV REQUIRES_PRE REQUIRES_POST REQUIRES_PREUN REQUIRES_POSTUN) foreach(_RPM_SPEC_HEADER URL REQUIRES SUGGESTS PROVIDES OBSOLETES PREFIX CONFLICTS AUTOPROV AUTOREQ AUTOREQPROV REQUIRES_PRE REQUIRES_POST REQUIRES_PREUN REQUIRES_POSTUN)
if(CPACK_RPM_PACKAGE_DEBUG) if(CPACK_RPM_PACKAGE_DEBUG)
message("CPackRPM:Debug: processing ${_RPM_SPEC_HEADER}") message("CPackRPM:Debug: processing ${_RPM_SPEC_HEADER}")
endif() endif()
@ -790,8 +769,6 @@ foreach(_RPM_SPEC_HEADER URL REQUIRES SUGGESTS PROVIDES OBSOLETES PREFIX CONFLIC
endif() endif()
endif() endif()
# Do not forget to unset previously set header (from previous component)
unset(TMP_RPM_${_RPM_SPEC_HEADER})
# Treat the RPM Spec keyword iff it has been properly defined # Treat the RPM Spec keyword iff it has been properly defined
if(DEFINED CPACK_RPM_PACKAGE_${_RPM_SPEC_HEADER}_TMP) if(DEFINED CPACK_RPM_PACKAGE_${_RPM_SPEC_HEADER}_TMP)
# Transform NAME --> Name e.g. PROVIDES --> Provides # Transform NAME --> Name e.g. PROVIDES --> Provides
@ -814,25 +791,25 @@ foreach(_RPM_SPEC_HEADER URL REQUIRES SUGGESTS PROVIDES OBSOLETES PREFIX CONFLIC
set(TMP_RPM_${_RPM_SPEC_HEADER} "${_PACKAGE_HEADER_NAME}: ${CPACK_RPM_PACKAGE_${_RPM_SPEC_HEADER}_TMP}") set(TMP_RPM_${_RPM_SPEC_HEADER} "${_PACKAGE_HEADER_NAME}: ${CPACK_RPM_PACKAGE_${_RPM_SPEC_HEADER}_TMP}")
unset(CPACK_RPM_PACKAGE_${_RPM_SPEC_HEADER}_TMP) unset(CPACK_RPM_PACKAGE_${_RPM_SPEC_HEADER}_TMP)
endif() endif()
endforeach() endforeach()
# CPACK_RPM_SPEC_INSTALL_POST # CPACK_RPM_SPEC_INSTALL_POST
# May be used to define a RPM post intallation script # May be used to define a RPM post intallation script
# for example setting it to "/bin/true" may prevent # for example setting it to "/bin/true" may prevent
# rpmbuild from stripping binaries. # rpmbuild from stripping binaries.
if(CPACK_RPM_SPEC_INSTALL_POST) if(CPACK_RPM_SPEC_INSTALL_POST)
if(CPACK_RPM_PACKAGE_DEBUG) if(CPACK_RPM_PACKAGE_DEBUG)
message("CPackRPM:Debug: User defined CPACK_RPM_SPEC_INSTALL_POST = ${CPACK_RPM_SPEC_INSTALL_POST}") message("CPackRPM:Debug: User defined CPACK_RPM_SPEC_INSTALL_POST = ${CPACK_RPM_SPEC_INSTALL_POST}")
endif() endif()
set(TMP_RPM_SPEC_INSTALL_POST "%define __spec_install_post ${CPACK_RPM_SPEC_INSTALL_POST}") set(TMP_RPM_SPEC_INSTALL_POST "%define __spec_install_post ${CPACK_RPM_SPEC_INSTALL_POST}")
endif() endif()
# CPACK_RPM_POST_INSTALL_SCRIPT_FILE (or CPACK_RPM_<COMPONENT>_POST_INSTALL_SCRIPT_FILE) # CPACK_RPM_POST_INSTALL_SCRIPT_FILE (or CPACK_RPM_<COMPONENT>_POST_INSTALL_SCRIPT_FILE)
# CPACK_RPM_POST_UNINSTALL_SCRIPT_FILE (or CPACK_RPM_<COMPONENT>_POST_UNINSTALL_SCRIPT_FILE) # CPACK_RPM_POST_UNINSTALL_SCRIPT_FILE (or CPACK_RPM_<COMPONENT>_POST_UNINSTALL_SCRIPT_FILE)
# May be used to embed a post (un)installation script in the spec file. # May be used to embed a post (un)installation script in the spec file.
# The refered script file(s) will be read and directly # The refered script file(s) will be read and directly
# put after the %post or %postun section # put after the %post or %postun section
if(CPACK_RPM_PACKAGE_COMPONENT) if(CPACK_RPM_PACKAGE_COMPONENT)
if(CPACK_RPM_${CPACK_RPM_PACKAGE_COMPONENT}_POST_INSTALL_SCRIPT_FILE) if(CPACK_RPM_${CPACK_RPM_PACKAGE_COMPONENT}_POST_INSTALL_SCRIPT_FILE)
set(CPACK_RPM_POST_INSTALL_READ_FILE ${CPACK_RPM_${CPACK_RPM_PACKAGE_COMPONENT}_POST_INSTALL_SCRIPT_FILE}) set(CPACK_RPM_POST_INSTALL_READ_FILE ${CPACK_RPM_${CPACK_RPM_PACKAGE_COMPONENT}_POST_INSTALL_SCRIPT_FILE})
else() else()
@ -843,43 +820,43 @@ if(CPACK_RPM_PACKAGE_COMPONENT)
else() else()
set(CPACK_RPM_POST_UNINSTALL_READ_FILE ${CPACK_RPM_POST_UNINSTALL_SCRIPT_FILE}) set(CPACK_RPM_POST_UNINSTALL_READ_FILE ${CPACK_RPM_POST_UNINSTALL_SCRIPT_FILE})
endif() endif()
else() else()
set(CPACK_RPM_POST_INSTALL_READ_FILE ${CPACK_RPM_POST_INSTALL_SCRIPT_FILE}) set(CPACK_RPM_POST_INSTALL_READ_FILE ${CPACK_RPM_POST_INSTALL_SCRIPT_FILE})
set(CPACK_RPM_POST_UNINSTALL_READ_FILE ${CPACK_RPM_POST_UNINSTALL_SCRIPT_FILE}) set(CPACK_RPM_POST_UNINSTALL_READ_FILE ${CPACK_RPM_POST_UNINSTALL_SCRIPT_FILE})
endif() endif()
# Handle post-install file if it has been specified # Handle post-install file if it has been specified
if(CPACK_RPM_POST_INSTALL_READ_FILE) if(CPACK_RPM_POST_INSTALL_READ_FILE)
if(EXISTS ${CPACK_RPM_POST_INSTALL_READ_FILE}) if(EXISTS ${CPACK_RPM_POST_INSTALL_READ_FILE})
file(READ ${CPACK_RPM_POST_INSTALL_READ_FILE} CPACK_RPM_SPEC_POSTINSTALL) file(READ ${CPACK_RPM_POST_INSTALL_READ_FILE} CPACK_RPM_SPEC_POSTINSTALL)
else() else()
message("CPackRPM:Warning: CPACK_RPM_POST_INSTALL_SCRIPT_FILE <${CPACK_RPM_POST_INSTALL_READ_FILE}> does not exists - ignoring") message("CPackRPM:Warning: CPACK_RPM_POST_INSTALL_SCRIPT_FILE <${CPACK_RPM_POST_INSTALL_READ_FILE}> does not exists - ignoring")
endif() endif()
else() else()
# reset SPEC var value if no post install file has been specified # reset SPEC var value if no post install file has been specified
# (either globally or component-wise) # (either globally or component-wise)
set(CPACK_RPM_SPEC_POSTINSTALL "") set(CPACK_RPM_SPEC_POSTINSTALL "")
endif() endif()
# Handle post-uninstall file if it has been specified # Handle post-uninstall file if it has been specified
if(CPACK_RPM_POST_UNINSTALL_READ_FILE) if(CPACK_RPM_POST_UNINSTALL_READ_FILE)
if(EXISTS ${CPACK_RPM_POST_UNINSTALL_READ_FILE}) if(EXISTS ${CPACK_RPM_POST_UNINSTALL_READ_FILE})
file(READ ${CPACK_RPM_POST_UNINSTALL_READ_FILE} CPACK_RPM_SPEC_POSTUNINSTALL) file(READ ${CPACK_RPM_POST_UNINSTALL_READ_FILE} CPACK_RPM_SPEC_POSTUNINSTALL)
else() else()
message("CPackRPM:Warning: CPACK_RPM_POST_UNINSTALL_SCRIPT_FILE <${CPACK_RPM_POST_UNINSTALL_READ_FILE}> does not exists - ignoring") message("CPackRPM:Warning: CPACK_RPM_POST_UNINSTALL_SCRIPT_FILE <${CPACK_RPM_POST_UNINSTALL_READ_FILE}> does not exists - ignoring")
endif() endif()
else() else()
# reset SPEC var value if no post uninstall file has been specified # reset SPEC var value if no post uninstall file has been specified
# (either globally or component-wise) # (either globally or component-wise)
set(CPACK_RPM_SPEC_POSTUNINSTALL "") set(CPACK_RPM_SPEC_POSTUNINSTALL "")
endif() endif()
# CPACK_RPM_PRE_INSTALL_SCRIPT_FILE (or CPACK_RPM_<COMPONENT>_PRE_INSTALL_SCRIPT_FILE) # CPACK_RPM_PRE_INSTALL_SCRIPT_FILE (or CPACK_RPM_<COMPONENT>_PRE_INSTALL_SCRIPT_FILE)
# CPACK_RPM_PRE_UNINSTALL_SCRIPT_FILE (or CPACK_RPM_<COMPONENT>_PRE_UNINSTALL_SCRIPT_FILE) # CPACK_RPM_PRE_UNINSTALL_SCRIPT_FILE (or CPACK_RPM_<COMPONENT>_PRE_UNINSTALL_SCRIPT_FILE)
# May be used to embed a pre (un)installation script in the spec file. # May be used to embed a pre (un)installation script in the spec file.
# The refered script file(s) will be read and directly # The refered script file(s) will be read and directly
# put after the %pre or %preun section # put after the %pre or %preun section
if(CPACK_RPM_PACKAGE_COMPONENT) if(CPACK_RPM_PACKAGE_COMPONENT)
if(CPACK_RPM_${CPACK_RPM_PACKAGE_COMPONENT}_PRE_INSTALL_SCRIPT_FILE) if(CPACK_RPM_${CPACK_RPM_PACKAGE_COMPONENT}_PRE_INSTALL_SCRIPT_FILE)
set(CPACK_RPM_PRE_INSTALL_READ_FILE ${CPACK_RPM_${CPACK_RPM_PACKAGE_COMPONENT}_PRE_INSTALL_SCRIPT_FILE}) set(CPACK_RPM_PRE_INSTALL_READ_FILE ${CPACK_RPM_${CPACK_RPM_PACKAGE_COMPONENT}_PRE_INSTALL_SCRIPT_FILE})
else() else()
@ -890,81 +867,81 @@ if(CPACK_RPM_PACKAGE_COMPONENT)
else() else()
set(CPACK_RPM_PRE_UNINSTALL_READ_FILE ${CPACK_RPM_PRE_UNINSTALL_SCRIPT_FILE}) set(CPACK_RPM_PRE_UNINSTALL_READ_FILE ${CPACK_RPM_PRE_UNINSTALL_SCRIPT_FILE})
endif() endif()
else() else()
set(CPACK_RPM_PRE_INSTALL_READ_FILE ${CPACK_RPM_PRE_INSTALL_SCRIPT_FILE}) set(CPACK_RPM_PRE_INSTALL_READ_FILE ${CPACK_RPM_PRE_INSTALL_SCRIPT_FILE})
set(CPACK_RPM_PRE_UNINSTALL_READ_FILE ${CPACK_RPM_PRE_UNINSTALL_SCRIPT_FILE}) set(CPACK_RPM_PRE_UNINSTALL_READ_FILE ${CPACK_RPM_PRE_UNINSTALL_SCRIPT_FILE})
endif() endif()
# Handle pre-install file if it has been specified # Handle pre-install file if it has been specified
if(CPACK_RPM_PRE_INSTALL_READ_FILE) if(CPACK_RPM_PRE_INSTALL_READ_FILE)
if(EXISTS ${CPACK_RPM_PRE_INSTALL_READ_FILE}) if(EXISTS ${CPACK_RPM_PRE_INSTALL_READ_FILE})
file(READ ${CPACK_RPM_PRE_INSTALL_READ_FILE} CPACK_RPM_SPEC_PREINSTALL) file(READ ${CPACK_RPM_PRE_INSTALL_READ_FILE} CPACK_RPM_SPEC_PREINSTALL)
else() else()
message("CPackRPM:Warning: CPACK_RPM_PRE_INSTALL_SCRIPT_FILE <${CPACK_RPM_PRE_INSTALL_READ_FILE}> does not exists - ignoring") message("CPackRPM:Warning: CPACK_RPM_PRE_INSTALL_SCRIPT_FILE <${CPACK_RPM_PRE_INSTALL_READ_FILE}> does not exists - ignoring")
endif() endif()
else() else()
# reset SPEC var value if no pre-install file has been specified # reset SPEC var value if no pre-install file has been specified
# (either globally or component-wise) # (either globally or component-wise)
set(CPACK_RPM_SPEC_PREINSTALL "") set(CPACK_RPM_SPEC_PREINSTALL "")
endif() endif()
# Handle pre-uninstall file if it has been specified # Handle pre-uninstall file if it has been specified
if(CPACK_RPM_PRE_UNINSTALL_READ_FILE) if(CPACK_RPM_PRE_UNINSTALL_READ_FILE)
if(EXISTS ${CPACK_RPM_PRE_UNINSTALL_READ_FILE}) if(EXISTS ${CPACK_RPM_PRE_UNINSTALL_READ_FILE})
file(READ ${CPACK_RPM_PRE_UNINSTALL_READ_FILE} CPACK_RPM_SPEC_PREUNINSTALL) file(READ ${CPACK_RPM_PRE_UNINSTALL_READ_FILE} CPACK_RPM_SPEC_PREUNINSTALL)
else() else()
message("CPackRPM:Warning: CPACK_RPM_PRE_UNINSTALL_SCRIPT_FILE <${CPACK_RPM_PRE_UNINSTALL_READ_FILE}> does not exists - ignoring") message("CPackRPM:Warning: CPACK_RPM_PRE_UNINSTALL_SCRIPT_FILE <${CPACK_RPM_PRE_UNINSTALL_READ_FILE}> does not exists - ignoring")
endif() endif()
else() else()
# reset SPEC var value if no pre-uninstall file has been specified # reset SPEC var value if no pre-uninstall file has been specified
# (either globally or component-wise) # (either globally or component-wise)
set(CPACK_RPM_SPEC_PREUNINSTALL "") set(CPACK_RPM_SPEC_PREUNINSTALL "")
endif() endif()
# CPACK_RPM_CHANGELOG_FILE # CPACK_RPM_CHANGELOG_FILE
# May be used to embed a changelog in the spec file. # May be used to embed a changelog in the spec file.
# The refered file will be read and directly put after the %changelog section # The refered file will be read and directly put after the %changelog section
if(CPACK_RPM_CHANGELOG_FILE) if(CPACK_RPM_CHANGELOG_FILE)
if(EXISTS ${CPACK_RPM_CHANGELOG_FILE}) if(EXISTS ${CPACK_RPM_CHANGELOG_FILE})
file(READ ${CPACK_RPM_CHANGELOG_FILE} CPACK_RPM_SPEC_CHANGELOG) file(READ ${CPACK_RPM_CHANGELOG_FILE} CPACK_RPM_SPEC_CHANGELOG)
else() else()
message(SEND_ERROR "CPackRPM:Warning: CPACK_RPM_CHANGELOG_FILE <${CPACK_RPM_CHANGELOG_FILE}> does not exists - ignoring") message(SEND_ERROR "CPackRPM:Warning: CPACK_RPM_CHANGELOG_FILE <${CPACK_RPM_CHANGELOG_FILE}> does not exists - ignoring")
endif() endif()
else() else()
set(CPACK_RPM_SPEC_CHANGELOG "* Sun Jul 4 2010 Eric Noulard <eric.noulard@gmail.com> - ${CPACK_RPM_PACKAGE_VERSION}-${CPACK_RPM_PACKAGE_RELEASE}\n Generated by CPack RPM (no Changelog file were provided)") set(CPACK_RPM_SPEC_CHANGELOG "* Sun Jul 4 2010 Eric Noulard <eric.noulard@gmail.com> - ${CPACK_RPM_PACKAGE_VERSION}-${CPACK_RPM_PACKAGE_RELEASE}\n Generated by CPack RPM (no Changelog file were provided)")
endif() endif()
# CPACK_RPM_SPEC_MORE_DEFINE # CPACK_RPM_SPEC_MORE_DEFINE
# This is a generated spec rpm file spaceholder # This is a generated spec rpm file spaceholder
if(CPACK_RPM_SPEC_MORE_DEFINE) if(CPACK_RPM_SPEC_MORE_DEFINE)
if(CPACK_RPM_PACKAGE_DEBUG) if(CPACK_RPM_PACKAGE_DEBUG)
message("CPackRPM:Debug: User defined more define spec line specified:\n ${CPACK_RPM_SPEC_MORE_DEFINE}") message("CPackRPM:Debug: User defined more define spec line specified:\n ${CPACK_RPM_SPEC_MORE_DEFINE}")
endif() endif()
endif() endif()
# Now we may create the RPM build tree structure # Now we may create the RPM build tree structure
set(CPACK_RPM_ROOTDIR "${CPACK_TOPLEVEL_DIRECTORY}") set(CPACK_RPM_ROOTDIR "${CPACK_TOPLEVEL_DIRECTORY}")
message(STATUS "CPackRPM:Debug: Using CPACK_RPM_ROOTDIR=${CPACK_RPM_ROOTDIR}") message(STATUS "CPackRPM:Debug: Using CPACK_RPM_ROOTDIR=${CPACK_RPM_ROOTDIR}")
# Prepare RPM build tree # Prepare RPM build tree
file(MAKE_DIRECTORY ${CPACK_RPM_ROOTDIR}) file(MAKE_DIRECTORY ${CPACK_RPM_ROOTDIR})
file(MAKE_DIRECTORY ${CPACK_RPM_ROOTDIR}/tmp) file(MAKE_DIRECTORY ${CPACK_RPM_ROOTDIR}/tmp)
file(MAKE_DIRECTORY ${CPACK_RPM_ROOTDIR}/BUILD) file(MAKE_DIRECTORY ${CPACK_RPM_ROOTDIR}/BUILD)
file(MAKE_DIRECTORY ${CPACK_RPM_ROOTDIR}/RPMS) file(MAKE_DIRECTORY ${CPACK_RPM_ROOTDIR}/RPMS)
file(MAKE_DIRECTORY ${CPACK_RPM_ROOTDIR}/SOURCES) file(MAKE_DIRECTORY ${CPACK_RPM_ROOTDIR}/SOURCES)
file(MAKE_DIRECTORY ${CPACK_RPM_ROOTDIR}/SPECS) file(MAKE_DIRECTORY ${CPACK_RPM_ROOTDIR}/SPECS)
file(MAKE_DIRECTORY ${CPACK_RPM_ROOTDIR}/SRPMS) file(MAKE_DIRECTORY ${CPACK_RPM_ROOTDIR}/SRPMS)
#set(CPACK_RPM_FILE_NAME "${CPACK_RPM_PACKAGE_NAME}-${CPACK_RPM_PACKAGE_VERSION}-${CPACK_RPM_PACKAGE_RELEASE}-${_CPACK_RPM_PACKAGE_ARCHITECTURE}.rpm") #set(CPACK_RPM_FILE_NAME "${CPACK_RPM_PACKAGE_NAME}-${CPACK_RPM_PACKAGE_VERSION}-${CPACK_RPM_PACKAGE_RELEASE}-${_CPACK_RPM_PACKAGE_ARCHITECTURE}.rpm")
set(CPACK_RPM_FILE_NAME "${CPACK_OUTPUT_FILE_NAME}") set(CPACK_RPM_FILE_NAME "${CPACK_OUTPUT_FILE_NAME}")
# it seems rpmbuild can't handle spaces in the path # it seems rpmbuild can't handle spaces in the path
# neither escaping (as below) nor putting quotes around the path seem to help # neither escaping (as below) nor putting quotes around the path seem to help
#string(REGEX REPLACE " " "\\\\ " CPACK_RPM_DIRECTORY "${CPACK_TOPLEVEL_DIRECTORY}") #string(REGEX REPLACE " " "\\\\ " CPACK_RPM_DIRECTORY "${CPACK_TOPLEVEL_DIRECTORY}")
set(CPACK_RPM_DIRECTORY "${CPACK_TOPLEVEL_DIRECTORY}") set(CPACK_RPM_DIRECTORY "${CPACK_TOPLEVEL_DIRECTORY}")
# if we are creating a relocatable package, omit parent directories of # if we are creating a relocatable package, omit parent directories of
# CPACK_RPM_PACKAGE_PREFIX. This is achieved by building a "filter list" # CPACK_RPM_PACKAGE_PREFIX. This is achieved by building a "filter list"
# which is passed to the find command that generates the content-list # which is passed to the find command that generates the content-list
if(CPACK_RPM_PACKAGE_RELOCATABLE) if(CPACK_RPM_PACKAGE_RELOCATABLE)
# get a list of the elements in CPACK_RPM_PACKAGE_PREFIXES that are # get a list of the elements in CPACK_RPM_PACKAGE_PREFIXES that are
# destinct parent paths of other relocation paths and remove the # destinct parent paths of other relocation paths and remove the
# final element (so the install-prefix dir itself is not omitted # final element (so the install-prefix dir itself is not omitted
@ -991,51 +968,51 @@ if(CPACK_RPM_PACKAGE_RELOCATABLE)
endforeach() endforeach()
endif() endif()
endforeach() endforeach()
endif() endif()
if (CPACK_RPM_PACKAGE_DEBUG) if (CPACK_RPM_PACKAGE_DEBUG)
message("CPackRPM:Debug: Initial list of path to OMIT in RPM: ${_RPM_DIRS_TO_OMIT}") message("CPackRPM:Debug: Initial list of path to OMIT in RPM: ${_RPM_DIRS_TO_OMIT}")
endif() endif()
if (NOT DEFINED CPACK_RPM_EXCLUDE_FROM_AUTO_FILELIST) if (NOT DEFINED CPACK_RPM_EXCLUDE_FROM_AUTO_FILELIST)
set(CPACK_RPM_EXCLUDE_FROM_AUTO_FILELIST /etc /etc/init.d /usr /usr/share /usr/share/doc /usr/bin /usr/lib /usr/lib64 /usr/include) set(CPACK_RPM_EXCLUDE_FROM_AUTO_FILELIST /etc /etc/init.d /usr /usr/share /usr/share/doc /usr/bin /usr/lib /usr/lib64 /usr/include)
if (CPACK_RPM_EXCLUDE_FROM_AUTO_FILELIST_ADDITION) if (CPACK_RPM_EXCLUDE_FROM_AUTO_FILELIST_ADDITION)
message("CPackRPM:Debug: Adding ${CPACK_RPM_EXCLUDE_FROM_AUTO_FILELIST_ADDITION} to builtin omit list.") message("CPackRPM:Debug: Adding ${CPACK_RPM_EXCLUDE_FROM_AUTO_FILELIST_ADDITION} to builtin omit list.")
list(APPEND CPACK_RPM_EXCLUDE_FROM_AUTO_FILELIST "${CPACK_RPM_EXCLUDE_FROM_AUTO_FILELIST_ADDITION}") list(APPEND CPACK_RPM_EXCLUDE_FROM_AUTO_FILELIST "${CPACK_RPM_EXCLUDE_FROM_AUTO_FILELIST_ADDITION}")
endif() endif()
endif() endif()
if(CPACK_RPM_EXCLUDE_FROM_AUTO_FILELIST) if(CPACK_RPM_EXCLUDE_FROM_AUTO_FILELIST)
if (CPACK_RPM_PACKAGE_DEBUG) if (CPACK_RPM_PACKAGE_DEBUG)
message("CPackRPM:Debug: CPACK_RPM_EXCLUDE_FROM_AUTO_FILELIST= ${CPACK_RPM_EXCLUDE_FROM_AUTO_FILELIST}") message("CPackRPM:Debug: CPACK_RPM_EXCLUDE_FROM_AUTO_FILELIST= ${CPACK_RPM_EXCLUDE_FROM_AUTO_FILELIST}")
endif() endif()
foreach(_DIR ${CPACK_RPM_EXCLUDE_FROM_AUTO_FILELIST}) foreach(_DIR ${CPACK_RPM_EXCLUDE_FROM_AUTO_FILELIST})
list(APPEND _RPM_DIRS_TO_OMIT "-o;-path;.${_DIR}") list(APPEND _RPM_DIRS_TO_OMIT "-o;-path;.${_DIR}")
endforeach() endforeach()
endif() endif()
if (CPACK_RPM_PACKAGE_DEBUG) if (CPACK_RPM_PACKAGE_DEBUG)
message("CPackRPM:Debug: Final list of path to OMIT in RPM: ${_RPM_DIRS_TO_OMIT}") message("CPackRPM:Debug: Final list of path to OMIT in RPM: ${_RPM_DIRS_TO_OMIT}")
endif() endif()
# Use files tree to construct files command (spec file) # Use files tree to construct files command (spec file)
# We should not forget to include symlinks (thus -o -type l) # We should not forget to include symlinks (thus -o -type l)
# We should include directory as well (thus -type d) # We should include directory as well (thus -type d)
# but not the main local dir "." (thus -a -not -name ".") # but not the main local dir "." (thus -a -not -name ".")
# We must remove the './' due to the local search and escape the # We must remove the './' due to the local search and escape the
# file name by enclosing it between double quotes (thus the sed) # file name by enclosing it between double quotes (thus the sed)
# Then we must authorize any man pages extension (adding * at the end) # Then we must authorize any man pages extension (adding * at the end)
# because rpmbuild may automatically compress those files # because rpmbuild may automatically compress those files
execute_process(COMMAND find . -type f -o -type l -o (-type d -a -not ( -name "." ${_RPM_DIRS_TO_OMIT} ) ) execute_process(COMMAND find . -type f -o -type l -o (-type d -a -not ( -name "." ${_RPM_DIRS_TO_OMIT} ) )
COMMAND sed s:.*/man.*/.*:&*: COMMAND sed s:.*/man.*/.*:&*:
COMMAND sed s/\\.\\\(.*\\\)/\"\\1\"/ COMMAND sed s/\\.\\\(.*\\\)/\"\\1\"/
WORKING_DIRECTORY "${WDIR}" WORKING_DIRECTORY "${WDIR}"
OUTPUT_VARIABLE CPACK_RPM_INSTALL_FILES) OUTPUT_VARIABLE CPACK_RPM_INSTALL_FILES)
# In component case, put CPACK_ABSOLUTE_DESTINATION_FILES_<COMPONENT> # In component case, put CPACK_ABSOLUTE_DESTINATION_FILES_<COMPONENT>
# into CPACK_ABSOLUTE_DESTINATION_FILES_INTERNAL # into CPACK_ABSOLUTE_DESTINATION_FILES_INTERNAL
# otherwise, put CPACK_ABSOLUTE_DESTINATION_FILES # otherwise, put CPACK_ABSOLUTE_DESTINATION_FILES
# This must be done BEFORE the CPACK_ABSOLUTE_DESTINATION_FILES_INTERNAL handling # This must be done BEFORE the CPACK_ABSOLUTE_DESTINATION_FILES_INTERNAL handling
if(CPACK_RPM_PACKAGE_COMPONENT) if(CPACK_RPM_PACKAGE_COMPONENT)
if(CPACK_ABSOLUTE_DESTINATION_FILES) if(CPACK_ABSOLUTE_DESTINATION_FILES)
set(COMPONENT_FILES_TAG "CPACK_ABSOLUTE_DESTINATION_FILES_${CPACK_RPM_PACKAGE_COMPONENT}") set(COMPONENT_FILES_TAG "CPACK_ABSOLUTE_DESTINATION_FILES_${CPACK_RPM_PACKAGE_COMPONENT}")
set(CPACK_ABSOLUTE_DESTINATION_FILES_INTERNAL "${${COMPONENT_FILES_TAG}}") set(CPACK_ABSOLUTE_DESTINATION_FILES_INTERNAL "${${COMPONENT_FILES_TAG}}")
@ -1044,14 +1021,14 @@ if(CPACK_RPM_PACKAGE_COMPONENT)
message("CPackRPM:Debug: in component = ${CPACK_RPM_PACKAGE_COMPONENT}") message("CPackRPM:Debug: in component = ${CPACK_RPM_PACKAGE_COMPONENT}")
endif() endif()
endif() endif()
else() else()
if(CPACK_ABSOLUTE_DESTINATION_FILES) if(CPACK_ABSOLUTE_DESTINATION_FILES)
set(CPACK_ABSOLUTE_DESTINATION_FILES_INTERNAL "${CPACK_ABSOLUTE_DESTINATION_FILES}") set(CPACK_ABSOLUTE_DESTINATION_FILES_INTERNAL "${CPACK_ABSOLUTE_DESTINATION_FILES}")
endif() endif()
endif() endif()
# In component case, set CPACK_RPM_USER_FILELIST_INTERNAL with CPACK_RPM_<COMPONENT>_USER_FILELIST. # In component case, set CPACK_RPM_USER_FILELIST_INTERNAL with CPACK_RPM_<COMPONENT>_USER_FILELIST.
if(CPACK_RPM_PACKAGE_COMPONENT) if(CPACK_RPM_PACKAGE_COMPONENT)
if(CPACK_RPM_${CPACK_RPM_PACKAGE_COMPONENT}_USER_FILELIST) if(CPACK_RPM_${CPACK_RPM_PACKAGE_COMPONENT}_USER_FILELIST)
set(CPACK_RPM_USER_FILELIST_INTERNAL ${CPACK_RPM_${CPACK_RPM_PACKAGE_COMPONENT}_USER_FILELIST}) set(CPACK_RPM_USER_FILELIST_INTERNAL ${CPACK_RPM_${CPACK_RPM_PACKAGE_COMPONENT}_USER_FILELIST})
if(CPACK_RPM_PACKAGE_DEBUG) if(CPACK_RPM_PACKAGE_DEBUG)
@ -1061,19 +1038,19 @@ if(CPACK_RPM_PACKAGE_COMPONENT)
else() else()
set(CPACK_RPM_USER_FILELIST_INTERNAL "") set(CPACK_RPM_USER_FILELIST_INTERNAL "")
endif() endif()
else() else()
if(CPACK_RPM_USER_FILELIST) if(CPACK_RPM_USER_FILELIST)
set(CPACK_RPM_USER_FILELIST_INTERNAL "${CPACK_RPM_USER_FILELIST}") set(CPACK_RPM_USER_FILELIST_INTERNAL "${CPACK_RPM_USER_FILELIST}")
else() else()
set(CPACK_RPM_USER_FILELIST_INTERNAL "") set(CPACK_RPM_USER_FILELIST_INTERNAL "")
endif() endif()
endif() endif()
# Handle user specified file line list in CPACK_RPM_USER_FILELIST_INTERNAL # Handle user specified file line list in CPACK_RPM_USER_FILELIST_INTERNAL
# Remove those files from CPACK_ABSOLUTE_DESTINATION_FILES_INTERNAL # Remove those files from CPACK_ABSOLUTE_DESTINATION_FILES_INTERNAL
# or CPACK_RPM_INSTALL_FILES, # or CPACK_RPM_INSTALL_FILES,
# hence it must be done before these auto-generated lists are processed. # hence it must be done before these auto-generated lists are processed.
if(CPACK_RPM_USER_FILELIST_INTERNAL) if(CPACK_RPM_USER_FILELIST_INTERNAL)
if(CPACK_RPM_PACKAGE_DEBUG) if(CPACK_RPM_PACKAGE_DEBUG)
message("CPackRPM:Debug: Handling User Filelist: <${CPACK_RPM_USER_FILELIST_INTERNAL}>") message("CPackRPM:Debug: Handling User Filelist: <${CPACK_RPM_USER_FILELIST_INTERNAL}>")
endif() endif()
@ -1113,11 +1090,11 @@ if(CPACK_RPM_USER_FILELIST_INTERNAL)
foreach(F IN LISTS CPACK_RPM_INSTALL_FILES_LIST) foreach(F IN LISTS CPACK_RPM_INSTALL_FILES_LIST)
set(CPACK_RPM_INSTALL_FILES "${CPACK_RPM_INSTALL_FILES}\"${F}\"\n") set(CPACK_RPM_INSTALL_FILES "${CPACK_RPM_INSTALL_FILES}\"${F}\"\n")
endforeach() endforeach()
else() else()
set(CPACK_RPM_USER_INSTALL_FILES "") set(CPACK_RPM_USER_INSTALL_FILES "")
endif() endif()
if (CPACK_ABSOLUTE_DESTINATION_FILES_INTERNAL) if (CPACK_ABSOLUTE_DESTINATION_FILES_INTERNAL)
if(CPACK_RPM_PACKAGE_DEBUG) if(CPACK_RPM_PACKAGE_DEBUG)
message("CPackRPM:Debug: Handling Absolute Destination Files: ${CPACK_ABSOLUTE_DESTINATION_FILES_INTERNAL}") message("CPackRPM:Debug: Handling Absolute Destination Files: ${CPACK_ABSOLUTE_DESTINATION_FILES_INTERNAL}")
endif() endif()
@ -1143,35 +1120,36 @@ if (CPACK_ABSOLUTE_DESTINATION_FILES_INTERNAL)
message("CPackRPM:Debug: CPACK_RPM_ABSOLUTE_INSTALL_FILES=${CPACK_RPM_ABSOLUTE_INSTALL_FILES}") message("CPackRPM:Debug: CPACK_RPM_ABSOLUTE_INSTALL_FILES=${CPACK_RPM_ABSOLUTE_INSTALL_FILES}")
message("CPackRPM:Debug: CPACK_RPM_INSTALL_FILES=${CPACK_RPM_INSTALL_FILES}") message("CPackRPM:Debug: CPACK_RPM_INSTALL_FILES=${CPACK_RPM_INSTALL_FILES}")
endif() endif()
else() else()
# reset vars in order to avoid leakage of value(s) from one component to another # reset vars in order to avoid leakage of value(s) from one component to another
set(CPACK_RPM_ABSOLUTE_INSTALL_FILES "") set(CPACK_RPM_ABSOLUTE_INSTALL_FILES "")
endif() endif()
# Prepend directories in ${CPACK_RPM_INSTALL_FILES} with %dir
# This is necessary to avoid duplicate files since rpmbuild do # Prepend directories in ${CPACK_RPM_INSTALL_FILES} with %dir
# recursion on its own when encountering a pathname which is a directory # This is necessary to avoid duplicate files since rpmbuild do
# which is not flagged as %dir # recursion on its own when encountering a pathname which is a directory
string(STRIP "${CPACK_RPM_INSTALL_FILES}" CPACK_RPM_INSTALL_FILES_LIST) # which is not flagged as %dir
string(REPLACE "\n" ";" CPACK_RPM_INSTALL_FILES_LIST string(STRIP "${CPACK_RPM_INSTALL_FILES}" CPACK_RPM_INSTALL_FILES_LIST)
string(REPLACE "\n" ";" CPACK_RPM_INSTALL_FILES_LIST
"${CPACK_RPM_INSTALL_FILES_LIST}") "${CPACK_RPM_INSTALL_FILES_LIST}")
string(REPLACE "\"" "" CPACK_RPM_INSTALL_FILES_LIST string(REPLACE "\"" "" CPACK_RPM_INSTALL_FILES_LIST
"${CPACK_RPM_INSTALL_FILES_LIST}") "${CPACK_RPM_INSTALL_FILES_LIST}")
set(CPACK_RPM_INSTALL_FILES "") set(CPACK_RPM_INSTALL_FILES "")
foreach(F IN LISTS CPACK_RPM_INSTALL_FILES_LIST) foreach(F IN LISTS CPACK_RPM_INSTALL_FILES_LIST)
if(IS_DIRECTORY "${WDIR}/${F}") if(IS_DIRECTORY "${WDIR}/${F}")
set(CPACK_RPM_INSTALL_FILES "${CPACK_RPM_INSTALL_FILES}%dir \"${F}\"\n") set(CPACK_RPM_INSTALL_FILES "${CPACK_RPM_INSTALL_FILES}%dir \"${F}\"\n")
else() else()
set(CPACK_RPM_INSTALL_FILES "${CPACK_RPM_INSTALL_FILES}\"${F}\"\n") set(CPACK_RPM_INSTALL_FILES "${CPACK_RPM_INSTALL_FILES}\"${F}\"\n")
endif() endif()
endforeach() endforeach()
set(CPACK_RPM_INSTALL_FILES_LIST "") set(CPACK_RPM_INSTALL_FILES_LIST "")
# The name of the final spec file to be used by rpmbuild # The name of the final spec file to be used by rpmbuild
set(CPACK_RPM_BINARY_SPECFILE "${CPACK_RPM_ROOTDIR}/SPECS/${CPACK_RPM_PACKAGE_NAME}${CPACK_RPM_PACKAGE_COMPONENT_PART_NAME}.spec") set(CPACK_RPM_BINARY_SPECFILE "${CPACK_RPM_ROOTDIR}/SPECS/${CPACK_RPM_PACKAGE_NAME}${CPACK_RPM_PACKAGE_COMPONENT_PART_NAME}.spec")
# Print out some debug information if we were asked for that # Print out some debug information if we were asked for that
if(CPACK_RPM_PACKAGE_DEBUG) if(CPACK_RPM_PACKAGE_DEBUG)
message("CPackRPM:Debug: CPACK_TOPLEVEL_DIRECTORY = ${CPACK_TOPLEVEL_DIRECTORY}") message("CPackRPM:Debug: CPACK_TOPLEVEL_DIRECTORY = ${CPACK_TOPLEVEL_DIRECTORY}")
message("CPackRPM:Debug: CPACK_TOPLEVEL_TAG = ${CPACK_TOPLEVEL_TAG}") message("CPackRPM:Debug: CPACK_TOPLEVEL_TAG = ${CPACK_TOPLEVEL_TAG}")
message("CPackRPM:Debug: CPACK_TEMPORARY_DIRECTORY = ${CPACK_TEMPORARY_DIRECTORY}") message("CPackRPM:Debug: CPACK_TEMPORARY_DIRECTORY = ${CPACK_TEMPORARY_DIRECTORY}")
@ -1181,21 +1159,21 @@ if(CPACK_RPM_PACKAGE_DEBUG)
message("CPackRPM:Debug: CPACK_RPM_BINARY_SPECFILE = ${CPACK_RPM_BINARY_SPECFILE}") message("CPackRPM:Debug: CPACK_RPM_BINARY_SPECFILE = ${CPACK_RPM_BINARY_SPECFILE}")
message("CPackRPM:Debug: CPACK_PACKAGE_INSTALL_DIRECTORY = ${CPACK_PACKAGE_INSTALL_DIRECTORY}") message("CPackRPM:Debug: CPACK_PACKAGE_INSTALL_DIRECTORY = ${CPACK_PACKAGE_INSTALL_DIRECTORY}")
message("CPackRPM:Debug: CPACK_TEMPORARY_PACKAGE_FILE_NAME = ${CPACK_TEMPORARY_PACKAGE_FILE_NAME}") message("CPackRPM:Debug: CPACK_TEMPORARY_PACKAGE_FILE_NAME = ${CPACK_TEMPORARY_PACKAGE_FILE_NAME}")
endif() endif()
# #
# USER generated/provided spec file handling. # USER generated/provided spec file handling.
# #
# We can have a component specific spec file. # We can have a component specific spec file.
if(CPACK_RPM_PACKAGE_COMPONENT AND CPACK_RPM_${CPACK_RPM_PACKAGE_COMPONENT}_USER_BINARY_SPECFILE) if(CPACK_RPM_PACKAGE_COMPONENT AND CPACK_RPM_${CPACK_RPM_PACKAGE_COMPONENT}_USER_BINARY_SPECFILE)
set(CPACK_RPM_USER_BINARY_SPECFILE ${CPACK_RPM_${CPACK_RPM_PACKAGE_COMPONENT}_USER_BINARY_SPECFILE}) set(CPACK_RPM_USER_BINARY_SPECFILE ${CPACK_RPM_${CPACK_RPM_PACKAGE_COMPONENT}_USER_BINARY_SPECFILE})
endif() endif()
# We should generate a USER spec file template: # We should generate a USER spec file template:
# - either because the user asked for it : CPACK_RPM_GENERATE_USER_BINARY_SPECFILE_TEMPLATE # - either because the user asked for it : CPACK_RPM_GENERATE_USER_BINARY_SPECFILE_TEMPLATE
# - or the user did not provide one : NOT CPACK_RPM_USER_BINARY_SPECFILE # - or the user did not provide one : NOT CPACK_RPM_USER_BINARY_SPECFILE
if(CPACK_RPM_GENERATE_USER_BINARY_SPECFILE_TEMPLATE OR NOT CPACK_RPM_USER_BINARY_SPECFILE) if(CPACK_RPM_GENERATE_USER_BINARY_SPECFILE_TEMPLATE OR NOT CPACK_RPM_USER_BINARY_SPECFILE)
file(WRITE ${CPACK_RPM_BINARY_SPECFILE}.in file(WRITE ${CPACK_RPM_BINARY_SPECFILE}.in
"# -*- rpm-spec -*- "# -*- rpm-spec -*-
BuildRoot: \@CPACK_RPM_DIRECTORY\@/\@CPACK_PACKAGE_FILE_NAME\@\@CPACK_RPM_PACKAGE_COMPONENT_PART_PATH\@ BuildRoot: \@CPACK_RPM_DIRECTORY\@/\@CPACK_PACKAGE_FILE_NAME\@\@CPACK_RPM_PACKAGE_COMPONENT_PART_PATH\@
@ -1277,23 +1255,23 @@ mv \"\@CPACK_TOPLEVEL_DIRECTORY\@/tmpBBroot\" $RPM_BUILD_ROOT
if(CPACK_RPM_GENERATE_USER_BINARY_SPECFILE_TEMPLATE) if(CPACK_RPM_GENERATE_USER_BINARY_SPECFILE_TEMPLATE)
message(FATAL_ERROR "CPackRPM: STOP here Generated USER binary spec file templare is: ${CPACK_RPM_BINARY_SPECFILE}.in") message(FATAL_ERROR "CPackRPM: STOP here Generated USER binary spec file templare is: ${CPACK_RPM_BINARY_SPECFILE}.in")
endif() endif()
endif() endif()
# After that we may either use a user provided spec file # After that we may either use a user provided spec file
# or generate one using appropriate variables value. # or generate one using appropriate variables value.
if(CPACK_RPM_USER_BINARY_SPECFILE) if(CPACK_RPM_USER_BINARY_SPECFILE)
# User may have specified SPECFILE just use it # User may have specified SPECFILE just use it
message("CPackRPM: Will use USER specified spec file: ${CPACK_RPM_USER_BINARY_SPECFILE}") message("CPackRPM: Will use USER specified spec file: ${CPACK_RPM_USER_BINARY_SPECFILE}")
# The user provided file is processed for @var replacement # The user provided file is processed for @var replacement
configure_file(${CPACK_RPM_USER_BINARY_SPECFILE} ${CPACK_RPM_BINARY_SPECFILE} @ONLY) configure_file(${CPACK_RPM_USER_BINARY_SPECFILE} ${CPACK_RPM_BINARY_SPECFILE} @ONLY)
else() else()
# No User specified spec file, will use the generated spec file # No User specified spec file, will use the generated spec file
message("CPackRPM: Will use GENERATED spec file: ${CPACK_RPM_BINARY_SPECFILE}") message("CPackRPM: Will use GENERATED spec file: ${CPACK_RPM_BINARY_SPECFILE}")
# Note the just created file is processed for @var replacement # Note the just created file is processed for @var replacement
configure_file(${CPACK_RPM_BINARY_SPECFILE}.in ${CPACK_RPM_BINARY_SPECFILE} @ONLY) configure_file(${CPACK_RPM_BINARY_SPECFILE}.in ${CPACK_RPM_BINARY_SPECFILE} @ONLY)
endif() endif()
if(RPMBUILD_EXECUTABLE) if(RPMBUILD_EXECUTABLE)
# Now call rpmbuild using the SPECFILE # Now call rpmbuild using the SPECFILE
execute_process( execute_process(
COMMAND "${RPMBUILD_EXECUTABLE}" -bb COMMAND "${RPMBUILD_EXECUTABLE}" -bb
@ -1314,20 +1292,11 @@ if(RPMBUILD_EXECUTABLE)
message("CPackRPM:Debug: - ${CPACK_TOPLEVEL_DIRECTORY}/rpmbuild${CPACK_RPM_PACKAGE_COMPONENT_PART_NAME}.out") message("CPackRPM:Debug: - ${CPACK_TOPLEVEL_DIRECTORY}/rpmbuild${CPACK_RPM_PACKAGE_COMPONENT_PART_NAME}.out")
message("CPackRPM:Debug: *** ${RPMBUILDERR} ***") message("CPackRPM:Debug: *** ${RPMBUILDERR} ***")
endif() endif()
else() else()
if(ALIEN_EXECUTABLE) if(ALIEN_EXECUTABLE)
message(FATAL_ERROR "RPM packaging through alien not done (yet)") message(FATAL_ERROR "RPM packaging through alien not done (yet)")
endif() endif()
endif() endif()
endfunction()
# reset variables from temporary variables cpack_rpm_generate_package()
if(CPACK_RPM_PACKAGE_SUMMARY_)
set(CPACK_RPM_PACKAGE_SUMMARY ${CPACK_RPM_PACKAGE_SUMMARY_})
else()
unset(CPACK_RPM_PACKAGE_SUMMARY)
endif()
if(CPACK_RPM_PACKAGE_DESCRIPTION_)
set(CPACK_RPM_PACKAGE_DESCRIPTION ${CPACK_RPM_PACKAGE_DESCRIPTION_})
else()
unset(CPACK_RPM_PACKAGE_DESCRIPTION)
endif()