Non puoi selezionare più di 25 argomenti Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.
 
 
 
 
 
 

348 righe
17 KiB

  1. ## Debian Source Package Generator
  2. #
  3. # Copyright (c) 2010 Daniel Pfeifer <daniel@pfeifer-mail.de>
  4. # Many modifications by Rosen Diankov <rosen.diankov@gmail.com>
  5. #
  6. # Creates source debian files and manages library dependencies
  7. #
  8. # Features:
  9. #
  10. # - Automatically generates symbols and run-time dependencies from the build dependencies
  11. # - Custom copy of source directory via CPACK_DEBIAN_PACKAGE_SOURCE_COPY
  12. # - Simultaneous output of multiple debian source packages for each distribution
  13. # - Can specificy distribution-specific dependencies by suffixing DEPENDS with _${DISTRO_NAME}, for example: CPACK_DEBIAN_PACKAGE_DEPENDS_LUCID, CPACK_COMPONENT_MYCOMP0_DEPENDS_LUCID
  14. #
  15. # Usage:
  16. #
  17. # set(CPACK_DEBIAN_BUILD_DEPENDS debhelper cmake)
  18. # set(CPACK_DEBIAN_PACKAGE_PRIORITY optional)
  19. # set(CPACK_DEBIAN_PACKAGE_SECTION devel)
  20. # set(CPACK_DEBIAN_CMAKE_OPTIONS "-DMYOPTION=myvalue")
  21. # set(CPACK_DEBIAN_PACKAGE_DEPENDS mycomp0 mycomp1 some_ubuntu_package)
  22. # set(CPACK_DEBIAN_PACKAGE_DEPENDS_UBUNTU_LUCID mycomp0 mycomp1 lucid_specific_package)
  23. # set(CPACK_DEBIAN_PACKAGE_NAME mypackage)
  24. # set(CPACK_DEBIAN_PACKAGE_REMOVE_SOURCE_FILES unnecessary_file unnecessary_dir/file0)
  25. # set(CPACK_DEBIAN_PACKAGE_SOURCE_COPY svn export --force) # if using subversion
  26. # set(CPACK_DEBIAN_DISTRIBUTION_NAME ubuntu)
  27. # set(CPACK_DEBIAN_DISTRIBUTION_RELEASES karmic lucid maverick natty)
  28. # set(CPACK_DEBIAN_CHANGELOG " * Extra change log lines")
  29. # set(CPACK_DEBIAN_PACKAGE_SUGGESTS "ipython")
  30. # set(CPACK_COMPONENT_X_RECOMMENDS "recommended-package")
  31. ##
  32. find_program(DEBUILD_EXECUTABLE debuild)
  33. find_program(DPUT_EXECUTABLE dput)
  34. if(NOT DEBUILD_EXECUTABLE OR NOT DPUT_EXECUTABLE)
  35. return()
  36. endif(NOT DEBUILD_EXECUTABLE OR NOT DPUT_EXECUTABLE)
  37. # DEBIAN/control
  38. # debian policy enforce lower case for package name
  39. # Package: (mandatory)
  40. IF(NOT CPACK_DEBIAN_PACKAGE_NAME)
  41. STRING(TOLOWER "${CPACK_PACKAGE_NAME}" CPACK_DEBIAN_PACKAGE_NAME)
  42. ENDIF(NOT CPACK_DEBIAN_PACKAGE_NAME)
  43. # Section: (recommended)
  44. IF(NOT CPACK_DEBIAN_PACKAGE_SECTION)
  45. SET(CPACK_DEBIAN_PACKAGE_SECTION "devel")
  46. ENDIF(NOT CPACK_DEBIAN_PACKAGE_SECTION)
  47. # Priority: (recommended)
  48. IF(NOT CPACK_DEBIAN_PACKAGE_PRIORITY)
  49. SET(CPACK_DEBIAN_PACKAGE_PRIORITY "optional")
  50. ENDIF(NOT CPACK_DEBIAN_PACKAGE_PRIORITY)
  51. file(STRINGS ${CPACK_PACKAGE_DESCRIPTION_FILE} DESC_LINES)
  52. foreach(LINE ${DESC_LINES})
  53. set(DEB_LONG_DESCRIPTION "${DEB_LONG_DESCRIPTION} ${LINE}\n")
  54. endforeach(LINE ${DESC_LINES})
  55. file(REMOVE_RECURSE "${CMAKE_BINARY_DIR}/Debian")
  56. file(MAKE_DIRECTORY "${CMAKE_BINARY_DIR}/Debian")
  57. set(DEBIAN_SOURCE_ORIG_DIR "${CMAKE_BINARY_DIR}/Debian/${CPACK_DEBIAN_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION}")
  58. if( CPACK_DEBIAN_PACKAGE_SOURCE_COPY )
  59. execute_process(COMMAND ${CPACK_DEBIAN_PACKAGE_SOURCE_COPY} "${CMAKE_SOURCE_DIR}" "${DEBIAN_SOURCE_ORIG_DIR}.orig")
  60. else()
  61. execute_process(COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_SOURCE_DIR} "${DEBIAN_SOURCE_ORIG_DIR}.orig")
  62. execute_process(COMMAND ${CMAKE_COMMAND} -E remove_directory "${DEBIAN_SOURCE_ORIG_DIR}.orig/.git")
  63. execute_process(COMMAND ${CMAKE_COMMAND} -E remove_directory "${DEBIAN_SOURCE_ORIG_DIR}.orig/.svn")
  64. endif()
  65. # remove unnecessary folders
  66. foreach(REMOVE_DIR ${CPACK_DEBIAN_PACKAGE_REMOVE_SOURCE_FILES})
  67. file(REMOVE_RECURSE ${DEBIAN_SOURCE_ORIG_DIR}.orig/${REMOVE_DIR})
  68. endforeach()
  69. # create the original source tar
  70. execute_process(COMMAND ${CMAKE_COMMAND} -E tar czf "${CPACK_DEBIAN_PACKAGE_NAME}_${CPACK_PACKAGE_VERSION}.orig.tar.gz" "${CPACK_DEBIAN_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION}.orig" WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/Debian)
  71. set(DEB_SOURCE_CHANGES)
  72. foreach(RELEASE ${CPACK_DEBIAN_DISTRIBUTION_RELEASES})
  73. set(DEBIAN_SOURCE_DIR "${DEBIAN_SOURCE_ORIG_DIR}-${CPACK_DEBIAN_DISTRIBUTION_NAME}1~${RELEASE}1")
  74. set(RELEASE_PACKAGE_VERSION "${CPACK_PACKAGE_VERSION}-${CPACK_DEBIAN_DISTRIBUTION_NAME}1~${RELEASE}1")
  75. string(TOUPPER ${RELEASE} RELEASE_UPPER)
  76. string(TOUPPER ${CPACK_DEBIAN_DISTRIBUTION_NAME} DISTRIBUTION_NAME_UPPER)
  77. file(MAKE_DIRECTORY ${DEBIAN_SOURCE_DIR}/debian)
  78. ##############################################################################
  79. # debian/control
  80. set(DEBIAN_CONTROL ${DEBIAN_SOURCE_DIR}/debian/control)
  81. file(WRITE ${DEBIAN_CONTROL}
  82. "Source: ${CPACK_DEBIAN_PACKAGE_NAME}\n"
  83. "Section: ${CPACK_DEBIAN_PACKAGE_SECTION}\n"
  84. "Priority: ${CPACK_DEBIAN_PACKAGE_PRIORITY}\n"
  85. "DM-Upload-Allowed: yes\n"
  86. "Maintainer: ${CPACK_PACKAGE_CONTACT}\n"
  87. "Build-Depends: "
  88. )
  89. if( CPACK_DEBIAN_BUILD_DEPENDS_${DISTRIBUTION_NAME_UPPER}_${RELEASE_UPPER} )
  90. foreach(DEP ${CPACK_DEBIAN_BUILD_DEPENDS_${DISTRIBUTION_NAME_UPPER}_${RELEASE_UPPER}})
  91. file(APPEND ${DEBIAN_CONTROL} "${DEP}, ")
  92. endforeach(DEP ${CPACK_DEBIAN_BUILD_DEPENDS_${DISTRIBUTION_NAME_UPPER}_${RELEASE_UPPER}})
  93. else( CPACK_DEBIAN_BUILD_DEPENDS_${DISTRIBUTION_NAME_UPPER}_${RELEASE_UPPER} )
  94. if( CPACK_DEBIAN_BUILD_DEPENDS_${DISTRIBUTION_NAME_UPPER} )
  95. foreach(DEP ${CPACK_DEBIAN_BUILD_DEPENDS_${DISTRIBUTION_NAME_UPPER}})
  96. file(APPEND ${DEBIAN_CONTROL} "${DEP}, ")
  97. endforeach(DEP ${CPACK_DEBIAN_BUILD_DEPENDS_${DISTRIBUTION_NAME_UPPER}})
  98. else( CPACK_DEBIAN_BUILD_DEPENDS_${DISTRIBUTION_NAME_UPPER} )
  99. foreach(DEP ${CPACK_DEBIAN_BUILD_DEPENDS})
  100. file(APPEND ${DEBIAN_CONTROL} "${DEP}, ")
  101. endforeach(DEP ${CPACK_DEBIAN_BUILD_DEPENDS})
  102. endif( CPACK_DEBIAN_BUILD_DEPENDS_${DISTRIBUTION_NAME_UPPER} )
  103. endif( CPACK_DEBIAN_BUILD_DEPENDS_${DISTRIBUTION_NAME_UPPER}_${RELEASE_UPPER} )
  104. file(APPEND ${DEBIAN_CONTROL} "\n"
  105. "Standards-Version: 3.8.4\n"
  106. "Homepage: ${CPACK_PACKAGE_VENDOR}\n"
  107. "\n"
  108. "Package: ${CPACK_DEBIAN_PACKAGE_NAME}\n"
  109. "Architecture: any\n"
  110. "Depends: "
  111. )
  112. if( CPACK_DEBIAN_PACKAGE_DEPENDS_${DISTRIBUTION_NAME_UPPER}_${RELEASE_UPPER} )
  113. foreach(DEP ${CPACK_DEBIAN_PACKAGE_DEPENDS_${DISTRIBUTION_NAME_UPPER}_${RELEASE_UPPER}})
  114. file(APPEND ${DEBIAN_CONTROL} "${DEP}, ")
  115. endforeach(DEP ${CPACK_DEBIAN_PACKAGE_DEPENDS_${DISTRIBUTION_NAME_UPPER}_${RELEASE_UPPER}})
  116. else( CPACK_DEBIAN_PACKAGE_DEPENDS_${DISTRIBUTION_NAME_UPPER}_${RELEASE_UPPER} )
  117. if( CPACK_DEBIAN_PACKAGE_DEPENDS_${DISTRIBUTION_NAME_UPPER} )
  118. foreach(DEP ${CPACK_DEBIAN_PACKAGE_DEPENDS_${DISTRIBUTION_NAME_UPPER}})
  119. file(APPEND ${DEBIAN_CONTROL} "${DEP}, ")
  120. endforeach(DEP ${CPACK_DEBIAN_PACKAGE_DEPENDS_${DISTRIBUTION_NAME_UPPER}})
  121. else( CPACK_DEBIAN_PACKAGE_DEPENDS_${DISTRIBUTION_NAME_UPPER} )
  122. foreach(DEP ${CPACK_DEBIAN_PACKAGE_DEPENDS})
  123. file(APPEND ${DEBIAN_CONTROL} "${DEP}, ")
  124. endforeach(DEP ${CPACK_DEBIAN_PACKAGE_DEPENDS})
  125. endif( CPACK_DEBIAN_PACKAGE_DEPENDS_${DISTRIBUTION_NAME_UPPER} )
  126. endif( CPACK_DEBIAN_PACKAGE_DEPENDS_${DISTRIBUTION_NAME_UPPER}_${RELEASE_UPPER} )
  127. file(APPEND ${DEBIAN_CONTROL} "\nRecommends: ")
  128. if( CPACK_DEBIAN_PACKAGE_RECOMMENDS_${DISTRIBUTION_NAME_UPPER}_${RELEASE_UPPER} )
  129. foreach(DEP ${CPACK_DEBIAN_PACKAGE_RECOMMENDS_${DISTRIBUTION_NAME_UPPER}_${RELEASE_UPPER}})
  130. file(APPEND ${DEBIAN_CONTROL} "${DEP}, ")
  131. endforeach(DEP ${CPACK_DEBIAN_PACKAGE_RECOMMENDS_${DISTRIBUTION_NAME_UPPER}_${RELEASE_UPPER}})
  132. else( CPACK_DEBIAN_PACKAGE_RECOMMENDS_${DISTRIBUTION_NAME_UPPER}_${RELEASE_UPPER} )
  133. if( CPACK_DEBIAN_PACKAGE_RECOMMENDS_${DISTRIBUTION_NAME_UPPER} )
  134. foreach(DEP ${CPACK_DEBIAN_PACKAGE_RECOMMENDS_${DISTRIBUTION_NAME_UPPER}})
  135. file(APPEND ${DEBIAN_CONTROL} "${DEP}, ")
  136. endforeach(DEP ${CPACK_DEBIAN_PACKAGE_RECOMMENDS_${DISTRIBUTION_NAME_UPPER}})
  137. else( CPACK_DEBIAN_PACKAGE_RECOMMENDS_${DISTRIBUTION_NAME_UPPER} )
  138. foreach(DEP ${CPACK_DEBIAN_PACKAGE_RECOMMENDS})
  139. file(APPEND ${DEBIAN_CONTROL} "${DEP}, ")
  140. endforeach(DEP ${CPACK_DEBIAN_PACKAGE_RECOMMENDS})
  141. endif( CPACK_DEBIAN_PACKAGE_RECOMMENDS_${DISTRIBUTION_NAME_UPPER} )
  142. endif( CPACK_DEBIAN_PACKAGE_RECOMMENDS_${DISTRIBUTION_NAME_UPPER}_${RELEASE_UPPER} )
  143. file(APPEND ${DEBIAN_CONTROL} "\nSuggests: ")
  144. if( CPACK_DEBIAN_PACKAGE_SUGGESTS_${DISTRIBUTION_NAME_UPPER}_${RELEASE_UPPER} )
  145. foreach(DEP ${CPACK_DEBIAN_PACKAGE_SUGGESTS_${DISTRIBUTION_NAME_UPPER}_${RELEASE_UPPER}})
  146. file(APPEND ${DEBIAN_CONTROL} "${DEP}, ")
  147. endforeach(DEP ${CPACK_DEBIAN_PACKAGE_SUGGESTS_${DISTRIBUTION_NAME_UPPER}_${RELEASE_UPPER}})
  148. else( CPACK_DEBIAN_PACKAGE_SUGGESTS_${DISTRIBUTION_NAME_UPPER}_${RELEASE_UPPER} )
  149. if( CPACK_DEBIAN_PACKAGE_SUGGESTS_${DISTRIBUTION_NAME_UPPER} )
  150. foreach(DEP ${CPACK_DEBIAN_PACKAGE_SUGGESTS_${DISTRIBUTION_NAME_UPPER}})
  151. file(APPEND ${DEBIAN_CONTROL} "${DEP}, ")
  152. endforeach(DEP ${CPACK_DEBIAN_PACKAGE_SUGGESTS_${DISTRIBUTION_NAME_UPPER}})
  153. else( CPACK_DEBIAN_PACKAGE_SUGGESTS_${DISTRIBUTION_NAME_UPPER} )
  154. foreach(DEP ${CPACK_DEBIAN_PACKAGE_SUGGESTS})
  155. file(APPEND ${DEBIAN_CONTROL} "${DEP}, ")
  156. endforeach(DEP ${CPACK_DEBIAN_PACKAGE_SUGGESTS})
  157. endif( CPACK_DEBIAN_PACKAGE_SUGGESTS_${DISTRIBUTION_NAME_UPPER} )
  158. endif( CPACK_DEBIAN_PACKAGE_SUGGESTS_${DISTRIBUTION_NAME_UPPER}_${RELEASE_UPPER} )
  159. file(APPEND ${DEBIAN_CONTROL} "\n"
  160. "Description: ${CPACK_PACKAGE_DISPLAY_NAME} ${CPACK_PACKAGE_DESCRIPTION_SUMMARY}\n"
  161. "${DEB_LONG_DESCRIPTION}"
  162. )
  163. foreach(COMPONENT ${CPACK_COMPONENTS_ALL})
  164. string(TOUPPER ${COMPONENT} UPPER_COMPONENT)
  165. set(DEPENDS "\${shlibs:Depends}")
  166. if( CPACK_COMPONENT_${UPPER_COMPONENT}_DEPENDS_${DISTRIBUTION_NAME_UPPER}_${RELEASE_UPPER} )
  167. foreach(DEP ${CPACK_COMPONENT_${UPPER_COMPONENT}_DEPENDS_${DISTRIBUTION_NAME_UPPER}_${RELEASE_UPPER}})
  168. set(DEPENDS "${DEPENDS}, ${DEP}")
  169. endforeach(DEP ${CPACK_COMPONENT_${UPPER_COMPONENT}_DEPENDS_${DISTRIBUTION_NAME_UPPER}_${RELEASE_UPPER}})
  170. else( CPACK_COMPONENT_${UPPER_COMPONENT}_DEPENDS_${DISTRIBUTION_NAME_UPPER}_${RELEASE_UPPER} )
  171. if( CPACK_COMPONENT_${UPPER_COMPONENT}_DEPENDS_${DISTRIBUTION_NAME_UPPER} )
  172. foreach(DEP ${CPACK_COMPONENT_${UPPER_COMPONENT}_DEPENDS_${DISTRIBUTION_NAME_UPPER}})
  173. set(DEPENDS "${DEPENDS}, ${DEP}")
  174. endforeach(DEP ${CPACK_COMPONENT_${UPPER_COMPONENT}_DEPENDS_${DISTRIBUTION_NAME_UPPER}})
  175. else( CPACK_COMPONENT_${UPPER_COMPONENT}_DEPENDS_${DISTRIBUTION_NAME_UPPER} )
  176. foreach(DEP ${CPACK_COMPONENT_${UPPER_COMPONENT}_DEPENDS})
  177. set(DEPENDS "${DEPENDS}, ${DEP}")
  178. endforeach(DEP ${CPACK_COMPONENT_${UPPER_COMPONENT}_DEPENDS})
  179. endif( CPACK_COMPONENT_${UPPER_COMPONENT}_DEPENDS_${DISTRIBUTION_NAME_UPPER} )
  180. endif( CPACK_COMPONENT_${UPPER_COMPONENT}_DEPENDS_${DISTRIBUTION_NAME_UPPER}_${RELEASE_UPPER} )
  181. set(RECOMMENDS)
  182. if( CPACK_COMPONENT_${UPPER_COMPONENT}_RECOMMENDS_${DISTRIBUTION_NAME_UPPER}_${RELEASE_UPPER} )
  183. foreach(DEP ${CPACK_COMPONENT_${UPPER_COMPONENT}_RECOMMENDS_${DISTRIBUTION_NAME_UPPER}_${RELEASE_UPPER}})
  184. set(RECOMMENDS "${RECOMMENDS} ${DEP}, ")
  185. endforeach(DEP ${CPACK_COMPONENT_${UPPER_COMPONENT}_RECOMMENDS_${DISTRIBUTION_NAME_UPPER}_${RELEASE_UPPER}})
  186. else( CPACK_COMPONENT_${UPPER_COMPONENT}_RECOMMENDS_${DISTRIBUTION_NAME_UPPER}_${RELEASE_UPPER} )
  187. if( CPACK_COMPONENT_${UPPER_COMPONENT}_RECOMMENDS_${DISTRIBUTION_NAME_UPPER} )
  188. foreach(DEP ${CPACK_COMPONENT_${UPPER_COMPONENT}_RECOMMENDS_${DISTRIBUTION_NAME_UPPER}})
  189. set(RECOMMENDS "${RECOMMENDS} ${DEP}, ")
  190. endforeach(DEP ${CPACK_COMPONENT_${UPPER_COMPONENT}_RECOMMENDS_${DISTRIBUTION_NAME_UPPER}})
  191. else( CPACK_COMPONENT_${UPPER_COMPONENT}_RECOMMENDS_${DISTRIBUTION_NAME_UPPER} )
  192. foreach(DEP ${CPACK_COMPONENT_${UPPER_COMPONENT}_RECOMMENDS})
  193. set(RECOMMENDS "${RECOMMENDS} ${DEP}, ")
  194. endforeach(DEP ${CPACK_COMPONENT_${UPPER_COMPONENT}_RECOMMENDS})
  195. endif( CPACK_COMPONENT_${UPPER_COMPONENT}_RECOMMENDS_${DISTRIBUTION_NAME_UPPER} )
  196. endif( CPACK_COMPONENT_${UPPER_COMPONENT}_RECOMMENDS_${DISTRIBUTION_NAME_UPPER}_${RELEASE_UPPER} )
  197. set(SUGGESTS)
  198. if( CPACK_COMPONENT_${UPPER_COMPONENT}_SUGGESTS_${DISTRIBUTION_NAME_UPPER}_${RELEASE_UPPER} )
  199. foreach(DEP ${CPACK_COMPONENT_${UPPER_COMPONENT}_SUGGESTS_${DISTRIBUTION_NAME_UPPER}_${RELEASE_UPPER}})
  200. set(SUGGESTS "${SUGGESTS} ${DEP}, ")
  201. endforeach(DEP ${CPACK_COMPONENT_${UPPER_COMPONENT}_SUGGESTS_${DISTRIBUTION_NAME_UPPER}_${RELEASE_UPPER}})
  202. else( CPACK_COMPONENT_${UPPER_COMPONENT}_SUGGESTS_${DISTRIBUTION_NAME_UPPER}_${RELEASE_UPPER} )
  203. if( CPACK_COMPONENT_${UPPER_COMPONENT}_SUGGESTS_${DISTRIBUTION_NAME_UPPER} )
  204. foreach(DEP ${CPACK_COMPONENT_${UPPER_COMPONENT}_SUGGESTS_${DISTRIBUTION_NAME_UPPER}})
  205. set(SUGGESTS "${SUGGESTS} ${DEP}, ")
  206. endforeach(DEP ${CPACK_COMPONENT_${UPPER_COMPONENT}_SUGGESTS_${DISTRIBUTION_NAME_UPPER}})
  207. else( CPACK_COMPONENT_${UPPER_COMPONENT}_SUGGESTS_${DISTRIBUTION_NAME_UPPER} )
  208. foreach(DEP ${CPACK_COMPONENT_${UPPER_COMPONENT}_SUGGESTS})
  209. set(SUGGESTS "${SUGGESTS} ${DEP}, ")
  210. endforeach(DEP ${CPACK_COMPONENT_${UPPER_COMPONENT}_SUGGESTS})
  211. endif( CPACK_COMPONENT_${UPPER_COMPONENT}_SUGGESTS_${DISTRIBUTION_NAME_UPPER} )
  212. endif( CPACK_COMPONENT_${UPPER_COMPONENT}_SUGGESTS_${DISTRIBUTION_NAME_UPPER}_${RELEASE_UPPER} )
  213. file(APPEND ${DEBIAN_CONTROL} "\n"
  214. "Package: ${COMPONENT}\n"
  215. "Architecture: any\n"
  216. "Depends: ${DEPENDS}\n"
  217. "Recommends: ${RECOMMENDS}\n"
  218. "Suggests: ${SUGGESTS}\n"
  219. "Description: ${CPACK_PACKAGE_DISPLAY_NAME} ${CPACK_COMPONENT_${UPPER_COMPONENT}_DISPLAY_NAME}\n"
  220. "${DEB_LONG_DESCRIPTION}"
  221. " .\n"
  222. " ${CPACK_COMPONENT_${UPPER_COMPONENT}_DESCRIPTION}\n"
  223. )
  224. endforeach(COMPONENT ${CPACK_COMPONENTS_ALL})
  225. ##############################################################################
  226. # debian/copyright
  227. set(DEBIAN_COPYRIGHT ${DEBIAN_SOURCE_DIR}/debian/copyright)
  228. execute_process(COMMAND ${CMAKE_COMMAND} -E
  229. copy ${CPACK_RESOURCE_FILE_LICENSE} ${DEBIAN_COPYRIGHT}
  230. )
  231. ##############################################################################
  232. # debian/rules
  233. set(DEBIAN_RULES ${DEBIAN_SOURCE_DIR}/debian/rules)
  234. file(WRITE ${DEBIAN_RULES}
  235. "#!/usr/bin/make -f\n"
  236. "\n"
  237. "BUILDDIR = build_dir\n"
  238. "\n"
  239. "build:\n"
  240. " mkdir $(BUILDDIR)\n"
  241. " cd $(BUILDDIR); cmake -DCMAKE_BUILD_TYPE=Release ${CPACK_DEBIAN_CMAKE_OPTIONS} -DCMAKE_INSTALL_PREFIX=/usr ..\n"
  242. " $(MAKE) -C $(BUILDDIR) preinstall\n"
  243. " touch build\n"
  244. "\n"
  245. "binary: binary-indep binary-arch\n"
  246. "\n"
  247. "binary-indep: build\n"
  248. "\n"
  249. "binary-arch: build\n"
  250. " cd $(BUILDDIR); cmake -DCOMPONENT=Unspecified -DCMAKE_INSTALL_PREFIX=../debian/tmp/usr -P cmake_install.cmake\n"
  251. " mkdir -p debian/tmp/DEBIAN\n"
  252. " dpkg-gensymbols -p${CPACK_DEBIAN_PACKAGE_NAME}\n"
  253. )
  254. foreach(COMPONENT ${CPACK_COMPONENTS_ALL})
  255. set(PATH debian/${COMPONENT})
  256. file(APPEND ${DEBIAN_RULES}
  257. " cd $(BUILDDIR); cmake -DCOMPONENT=${COMPONENT} -DCMAKE_INSTALL_PREFIX=../${PATH}/usr -P cmake_install.cmake\n"
  258. " mkdir -p ${PATH}/DEBIAN\n"
  259. " dpkg-gensymbols -p${COMPONENT} -P${PATH}\n"
  260. )
  261. endforeach(COMPONENT ${CPACK_COMPONENTS_ALL})
  262. file(APPEND ${DEBIAN_RULES}
  263. " dh_shlibdeps\n"
  264. " dh_strip\n" # for reducing size
  265. " dpkg-gencontrol -p${CPACK_DEBIAN_PACKAGE_NAME}\n"
  266. " dpkg --build debian/tmp ..\n"
  267. )
  268. foreach(COMPONENT ${CPACK_COMPONENTS_ALL})
  269. set(PATH debian/${COMPONENT})
  270. file(APPEND ${DEBIAN_RULES}
  271. " dpkg-gencontrol -p${COMPONENT} -P${PATH} -Tdebian/${COMPONENT}.substvars\n"
  272. " dpkg --build ${PATH} ..\n"
  273. )
  274. endforeach(COMPONENT ${CPACK_COMPONENTS_ALL})
  275. file(APPEND ${DEBIAN_RULES}
  276. "\n"
  277. "clean:\n"
  278. " rm -f build\n"
  279. " rm -rf $(BUILDDIR)\n"
  280. "\n"
  281. ".PHONY: binary binary-arch binary-indep clean\n"
  282. )
  283. execute_process(COMMAND chmod +x ${DEBIAN_RULES})
  284. ##############################################################################
  285. # debian/compat
  286. file(WRITE ${DEBIAN_SOURCE_DIR}/debian/compat "7")
  287. ##############################################################################
  288. # debian/source/format
  289. file(WRITE ${DEBIAN_SOURCE_DIR}/debian/source/format "3.0 (quilt)")
  290. ##############################################################################
  291. # debian/changelog
  292. set(DEBIAN_CHANGELOG ${DEBIAN_SOURCE_DIR}/debian/changelog)
  293. execute_process(COMMAND date -R OUTPUT_VARIABLE DATE_TIME)
  294. file(WRITE ${DEBIAN_CHANGELOG}
  295. "${CPACK_DEBIAN_PACKAGE_NAME} (${RELEASE_PACKAGE_VERSION}) ${RELEASE}; urgency=medium\n\n"
  296. " * Package built with CMake\n\n"
  297. "${CPACK_DEBIAN_CHANGELOG}"
  298. " -- ${CPACK_PACKAGE_CONTACT} ${DATE_TIME}"
  299. )
  300. ##############################################################################
  301. # debuild -S
  302. if( DEB_SOURCE_CHANGES )
  303. set(DEBUILD_OPTIONS "-sd")
  304. else()
  305. set(DEBUILD_OPTIONS "-sa")
  306. endif()
  307. set(SOURCE_CHANGES_FILE "${CPACK_DEBIAN_PACKAGE_NAME}_${RELEASE_PACKAGE_VERSION}_source.changes")
  308. set(DEB_SOURCE_CHANGES ${DEB_SOURCE_CHANGES} "${SOURCE_CHANGES_FILE}")
  309. add_custom_command(OUTPUT "${SOURCE_CHANGES_FILE}" COMMAND ${DEBUILD_EXECUTABLE} -S ${DEBUILD_OPTIONS} WORKING_DIRECTORY ${DEBIAN_SOURCE_DIR})
  310. endforeach(RELEASE ${CPACK_DEBIAN_DISTRIBUTION_RELEASES})
  311. ##############################################################################
  312. # dput ppa:your-lp-id/ppa <source.changes>
  313. add_custom_target(dput ${DPUT_EXECUTABLE} ${DPUT_HOST} ${DEB_SOURCE_CHANGES} DEPENDS ${DEB_SOURCE_CHANGES} WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/Debian)