Annotation of imach/distributions/gnulinux/UseRPMTools.cmake, revision 1.2

1.1       brouard     1: #
                      2: # - Find tools needed for building RPM Packages
                      3: #   on Linux systems and defines macro that helps to
                      4: #   build source or binary RPM, the MACRO assumes
                      5: #   CMake 2.4.x which includes CPack support.
                      6: #   CPack is used to build tar.gz source tarball
                      7: #   which may be used by a custom user-made spec file.
                      8: #
                      9: # - Define RPMTools_ADD_RPM_TARGETS which defines
                     10: #   two (top-level) CUSTOM targets for building
                     11: #   source and binary RPMs
                     12: #
                     13: # Those CMake macros are provided by the TSP Developer Team
                     14: # https://savannah.nongnu.org/projects/tsp
                     15: #
                     16: 
                     17: IF (WIN32)  
                     18:   MESSAGE(STATUS "RPM tools not available on Win32 systems")
                     19: ENDIF(WIN32)
                     20: 
                     21: IF (UNIX)
                     22:   # Look for RPM builder executable
                     23:   FIND_PROGRAM(RPMTools_RPMBUILD_EXECUTABLE 
                     24:     NAMES rpmbuild
                     25:     PATHS "/usr/bin;/usr/lib/rpm"
                     26:     PATH_SUFFIXES bin
                     27:     DOC "The RPM builder tool")
                     28:   
                     29:   IF (RPMTools_RPMBUILD_EXECUTABLE)
                     30:     MESSAGE(STATUS "Looking for RPMTools... - found rpmuild is ${RPMTools_RPMBUILD_EXECUTABLE}")
                     31:     SET(RPMTools_RPMBUILD_FOUND "YES")
                     32:     GET_FILENAME_COMPONENT(RPMTools_BINARY_DIRS ${RPMTools_RPMBUILD_EXECUTABLE} PATH)
                     33:   ELSE (RPMTools_RPMBUILD_EXECUTABLE) 
                     34:     SET(RPMTools_RPMBUILD_FOUND "NO")
                     35:     MESSAGE(STATUS "Looking for RPMTools... - rpmbuild NOT FOUND")
                     36:   ENDIF (RPMTools_RPMBUILD_EXECUTABLE) 
                     37:   
                     38:   # Detect if CPack was included or not
                     39:   IF (NOT DEFINED "CPACK_PACKAGE_NAME") 
                     40:     MESSAGE(FATAL_ERROR "CPack was not included, you should include CPack before Using RPMTools")
                     41:   ENDIF (NOT DEFINED "CPACK_PACKAGE_NAME")
                     42:   
                     43:   IF (RPMTools_RPMBUILD_FOUND)
                     44:     SET(RPMTools_FOUND TRUE)    
                     45:     #
                     46:     # - first arg  (ARGV0) is RPM name
                     47:     # - second arg (ARGV1) is the RPM spec file path [optional]
                     48:     # - third arg  (ARGV2) is the RPM ROOT DIRECTORY used to build RPMs [optional]
                     49:     #
                     50:     MACRO(RPMTools_ADD_RPM_TARGETS RPMNAME)
                     51: 
                     52:       #
                     53:       # If no spec file is provided create a minimal one
                     54:       #
                     55:       IF ("${ARGV1}" STREQUAL "")
                     56:        SET(SPECFILE_PATH "${CMAKE_BINARY_DIR}/${RPMNAME}.spec")
                     57:       ELSE ("${ARGV1}" STREQUAL "")
                     58:        SET(SPECFILE_PATH "${ARGV1}")
                     59:       ENDIF("${ARGV1}" STREQUAL "")
                     60:       
                     61:       # Verify whether if RPM_ROOTDIR was provided or not
                     62:       IF("${ARGV2}" STREQUAL "") 
                     63:        SET(RPM_ROOTDIR ${CMAKE_BINARY_DIR}/RPM)
                     64:       ELSE ("${ARGV2}" STREQUAL "")
                     65:        SET(RPM_ROOTDIR "${ARGV2}")     
                     66:       ENDIF("${ARGV2}" STREQUAL "")
                     67:       MESSAGE(STATUS "RPMTools:: Using RPM_ROOTDIR=${RPM_ROOTDIR}")
                     68: 
                     69:       # Prepare RPM build tree
                     70:       FILE(MAKE_DIRECTORY ${RPM_ROOTDIR})
                     71:       FILE(MAKE_DIRECTORY ${RPM_ROOTDIR}/tmp)
                     72:       FILE(MAKE_DIRECTORY ${RPM_ROOTDIR}/BUILD)
                     73:       FILE(MAKE_DIRECTORY ${RPM_ROOTDIR}/RPMS)
1.2     ! brouard    74:  #     FILE(MAKE_DIRECTORY ${RPM_ROOTDIR}/SOURCES)
1.1       brouard    75:       FILE(MAKE_DIRECTORY ${RPM_ROOTDIR}/SPECS)
                     76:       FILE(MAKE_DIRECTORY ${RPM_ROOTDIR}/SRPMS)
                     77: 
                     78:       #
                     79:       # We check whether if the provided spec file is
                     80:       # to be configure or not.
                     81:       # 
                     82:       IF ("${ARGV1}" STREQUAL "")
                     83:        SET(SPECFILE_PATH "${RPM_ROOTDIR}/SPECS/${RPMNAME}.spec")
                     84:        SET(SPECFILE_NAME "${RPMNAME}.spec")
                     85:        MESSAGE(STATUS "No Spec file given generate a minimal one --> ${RPM_ROOTDIR}/SPECS/${RPMNAME}.spec")
                     86:        FILE(WRITE ${RPM_ROOTDIR}/SPECS/${RPMNAME}.spec
                     87:          "# -*- rpm-spec -*-
                     88: Summary:        ${RPMNAME}
                     89: Name:           ${RPMNAME}
                     90: Version:        ${PACKAGE_VERSION}
                     91: Release:        1
1.2     ! brouard    92: License:        GPLv2+ with exceptions
        !            93: Group:          Applications/Sciences
        !            94: URL:            http://euroreves.ined.fr/imach
1.1       brouard    95: Source:         ${CPACK_SOURCE_PACKAGE_FILE_NAME}.tar.gz
                     96: BuildRoot:      %{_tmppath}/%{name}-%{version}-%{release}-root
                     97: BuildRequires: cmake
                     98: 
1.2     ! brouard    99: %define prefix /usr/local/${RPMNAME}-%{version}
1.1       brouard   100: %define rpmprefix $RPM_BUILD_ROOT%{prefix}
                    101: %define srcdirname %{name}-%{version}-Source
                    102: 
                    103: %description
                    104: ${RPMNAME} : No description for now
                    105: 
                    106: %prep
                    107: %setup -q -n %{srcdirname}
                    108: 
                    109: %build
                    110: cd ..
                    111: rm -rf build_tree
                    112: mkdir build_tree
                    113: cd build_tree
                    114: cmake -DCMAKE_INSTALL_PREFIX=%{rpmprefix} ../%{srcdirname}
                    115: make
                    116:   
                    117: %install 
                    118: cd ../build_tree
                    119: make install
                    120: 
                    121: %clean
                    122: rm -rf %{srcdirname}
                    123: rm -rf build_tree
                    124: 
                    125: %files
                    126: %defattr(-,root,root,-)
                    127: %dir %{prefix}
                    128: %{prefix}/*
                    129: 
                    130: %changelog
                    131: * Wed Feb 28 2007 Erk <eric.noulard@gmail.com>
                    132:   Generated by CMake UseRPMTools macros"
                    133:        )
                    134: 
                    135:       ELSE ("${ARGV1}" STREQUAL "")
                    136:        SET(SPECFILE_PATH "${ARGV1}")
                    137:        
                    138:        GET_FILENAME_COMPONENT(SPECFILE_EXT ${SPECFILE_PATH} EXT)      
                    139:        IF ("${SPECFILE_EXT}" STREQUAL ".spec")
                    140:          # This is a 'ready-to-use' spec file which does not need to be CONFIGURED
                    141:          GET_FILENAME_COMPONENT(SPECFILE_NAME ${SPECFILE_PATH} NAME)
                    142:          MESSAGE(STATUS "Simple copy spec file <${SPECFILE_PATH}> --> <${RPM_ROOTDIR}/SPECS/${SPECFILE_NAME}>")
                    143:          CONFIGURE_FILE(
                    144:            ${SPECFILE_PATH} 
                    145:            ${RPM_ROOTDIR}/SPECS/${SPECFILE_NAME}
                    146:            COPYONLY)
                    147:        ELSE ("${SPECFILE_EXT}" STREQUAL ".spec")
                    148:          # This is a to-be-configured spec file
                    149:          GET_FILENAME_COMPONENT(SPECFILE_NAME ${SPECFILE_PATH} NAME_WE)
                    150:          SET(SPECFILE_NAME "${SPECFILE_NAME}.spec")
                    151:          MESSAGE(STATUS "Configuring spec file <${SPECFILE_PATH}> --> <${RPM_ROOTDIR}/SPECS/${SPECFILE_NAME}>")
                    152:          CONFIGURE_FILE(
                    153:            ${SPECFILE_PATH} 
                    154:            ${RPM_ROOTDIR}/SPECS/${SPECFILE_NAME}
                    155:            @ONLY)
                    156:        ENDIF ("${SPECFILE_EXT}" STREQUAL ".spec")
                    157:       ENDIF("${ARGV1}" STREQUAL "")
                    158:             
                    159:       ADD_CUSTOM_TARGET(${RPMNAME}_srpm
                    160:        COMMAND cpack -G TGZ --config CPackSourceConfig.cmake
                    161:        COMMAND ${CMAKE_COMMAND} -E copy ${CPACK_SOURCE_PACKAGE_FILE_NAME}.tar.gz ${RPM_ROOTDIR}/SOURCES    
                    162:        COMMAND ${RPMTools_RPMBUILD_EXECUTABLE} -bs --define=\"_topdir ${RPM_ROOTDIR}\" --buildroot=${RPM_ROOTDIR}/tmp ${RPM_ROOTDIR}/SPECS/${SPECFILE_NAME} 
                    163:        )
                    164:       
                    165:       ADD_CUSTOM_TARGET(${RPMNAME}_rpm
                    166:        COMMAND cpack -G TGZ --config CPackSourceConfig.cmake
                    167:        COMMAND ${CMAKE_COMMAND} -E copy ${CPACK_SOURCE_PACKAGE_FILE_NAME}.tar.gz ${RPM_ROOTDIR}/SOURCES    
                    168:        COMMAND ${RPMTools_RPMBUILD_EXECUTABLE} -bb --define=\"_topdir ${RPM_ROOTDIR}\" --buildroot=${RPM_ROOTDIR}/tmp ${RPM_ROOTDIR}/SPECS/${SPECFILE_NAME} 
                    169:        )  
                    170:     ENDMACRO(RPMTools_ADD_RPM_TARGETS)
                    171: 
                    172:   ELSE (RPMTools_RPMBUILD_FOUND)
                    173:     SET(RPMTools FALSE)
                    174:   ENDIF (RPMTools_RPMBUILD_FOUND)  
                    175:   
                    176: ENDIF (UNIX)
                    177:   

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>