Collection of DPF-based plugins for packaging
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

330 lines
12KB

  1. # ===========================================================================
  2. # https://www.gnu.org/software/autoconf-archive/ax_dist_rpm.html
  3. # ===========================================================================
  4. #
  5. # SYNOPSIS
  6. #
  7. # AX_DIST_RPM([SPEC])
  8. #
  9. # DESCRIPTION
  10. #
  11. # Adds support for a rpm dist target.
  12. #
  13. # You will need to create a spec template with everything except the files
  14. # and the Changelog. Use @PACKAGE@ and @VERSION@ to refer to the package
  15. # name and version respectively. The files and ChangeLog will be filled
  16. # in automatically. For instance:
  17. #
  18. # Summary: Foobar
  19. # Name: @PACKAGE@
  20. # Version: @VERSION@
  21. # Release: 0
  22. # License: GPL
  23. # Group: Productivity/Networking
  24. # Source0: http://somewhere/Foobar/%{name}-%{version}.tar.gz
  25. # URL: http://somewhere
  26. # BuildRoot: %{_tmppath}/%{name}-root
  27. # Prefix: %{_prefix}
  28. #
  29. # %description
  30. # Foobar does something
  31. #
  32. # %prep
  33. # %setup
  34. #
  35. # %build
  36. # %configure
  37. # make
  38. #
  39. # %install
  40. # %makeinstall
  41. #
  42. # %clean
  43. # rm -rf $RPM_BUILD_ROOT
  44. #
  45. # %files
  46. # %defattr(-,root,root)
  47. #
  48. # %doc AUTHORS BUGS COPYING INSTALL NEWS README
  49. #
  50. # %changelog
  51. #
  52. # Make sure ax_upload.am is added to aminclude.am and you have 'include
  53. # aminclude.am' in your toplevel Makefile.am
  54. #
  55. # LICENSE
  56. #
  57. # Copyright (c) 2009 Tom Howard <tomhoward@users.sf.net>
  58. #
  59. # Copying and distribution of this file, with or without modification, are
  60. # permitted in any medium without royalty provided the copyright notice
  61. # and this notice are preserved. This file is offered as-is, without any
  62. # warranty.
  63. #serial 22
  64. AC_DEFUN([AX_DIST_RPM],
  65. [
  66. AC_REQUIRE([AX_INSTALL_FILES])
  67. AC_MSG_NOTICE([adding rpm support])
  68. AM_CONDITIONAL([ax_dist_rpm_enable_upload],[test "x$USING_AX_UPLOAD" != "x"])
  69. AM_CONDITIONAL([ax_dist_rpm_using_ax_extra_dist],[test "x$USING_AX_EXTRA_DIST" != "x"])
  70. ax_dist_rpm_enabled=false
  71. if test "x$AX_HAVE_INSTALL_FILES" = "xtrue"; then
  72. AC_MSG_CHECKING([rpm spec template])
  73. if test -f "$srcdir/$1.in"; then
  74. AC_MSG_RESULT([$1.in])
  75. AX_RPM_SPEC_FILE="$1";
  76. AC_SUBST(AX_RPM_SPEC_FILE)
  77. AC_CONFIG_FILES([$1])
  78. AC_ARG_VAR(EDITOR, [default text editor])
  79. if test "x$EDITOR" = "x"; then
  80. AC_CHECK_PROGS(EDITOR,[vim vi emacs])
  81. fi
  82. AC_ARG_VAR(RPM, [rpm executable to use])
  83. if test "x$RPM" = "x"; then
  84. AC_CHECK_PROGS(RPM,[rpmbuild rpm echo])
  85. fi
  86. if test "x$RPM" != "x"; then
  87. AC_ARG_VAR(PLATFORM_SUFFIX, [A short name for your platform that will be added to the name of the binary RPMs you may choose to create (by running make rpm). e.g. rh71 for RedHat 7.1, lsb1.3 for a LSB 1.3 compliant system (SuSE 8.2 or RedHat 9), osx103 for OS X 10.3.x, etc])
  88. AC_MSG_CHECKING([rpm platform suffix])
  89. if test "x$PLATFORM_SUFFIX" != "x"; then
  90. AC_MSG_RESULT([$PLATFORM_SUFFIX])
  91. AC_SUBST([PLATFORM_SUFFIX])
  92. ax_dist_rpm_enabled=true
  93. else
  94. AC_MSG_RESULT([$PLATFORM_SUFFIX])
  95. AC_MSG_WARN([rpm support disabled... PLATFORM_SUFFIX not set])
  96. fi
  97. else
  98. AC_MSG_NOTICE([rpm support disabled... neither rpmbuild or rpm was found])
  99. fi
  100. else
  101. AC_MSG_RESULT([not found])
  102. AC_MSG_ERROR([rpm spec template "$1.in" could not be found])
  103. fi
  104. else
  105. AC_MSG_NOTICE([rpm support disabled... install_files not available])
  106. fi
  107. AM_CONDITIONAL([ax_dist_rpm_enabled], [test x"$ax_dist_rpm_enabled" = x"true"])
  108. AX_ADD_AM_MACRO_STATIC([
  109. if ax_dist_rpm_enabled
  110. AX_DIST_RPM_CLEANFILES = \$(top_builddir)/RPMChangeLog \$(AX_INSTALL_FILES_CLEANFILES)
  111. \$(top_builddir)/RPMChangeLog: \$(top_srcdir)/ChangeLog
  112. \$(GAWK) '/^[^0-9]/ { \\
  113. if( \$${AX_DOLLAR}1 == \"*\" ) \$${AX_DOLLAR}1 = \"-\"; print; } \\
  114. /^\$\$/ { \\
  115. print; } \\
  116. /^[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]/ { \\
  117. if( stop ) exit; \\
  118. split( \$${AX_DOLLAR}1, date, \"-\" ); \\
  119. \$${AX_DOLLAR}1 = strftime( \"%%a %%b %%d %%Y\", \\
  120. mktime( date[ 1 ] \" \" date[ 2 ] \" \" date [ 3 ] \" 00 00 00\" ) ); \\
  121. print \"* \" \$${AX_DOLLAR}0; } \\
  122. /Released \$(PACKAGE)-/ { \\
  123. gsub( /\$(PACKAGE)-/, \"\", \$${AX_DOLLAR}2 ); \\
  124. split( \$${AX_DOLLAR}2, ver, \".\" ); \\
  125. split( \"\$(VERSION)\", curr_ver, \".\" ); \\
  126. if( ver[ 1 ] != curr_ver[ 1 ] || ver[ 2 ] != curr_ver[ 2 ] ) stop = 1; } \\
  127. END { \\
  128. print \"[Please see the ChangeLog file for older changes] - Ed.\"; }' \\
  129. \$(top_srcdir)/ChangeLog > \$(top_builddir)/RPMChangeLog
  130. AX_DIST_RPM_CLEANFILES += \$(top_builddir)/\$(PACKAGE)-\$(VERSION).spec
  131. AX_DIST_RPM_EXTRA_DIST = \$(top_builddir)/\$(PACKAGE)-\$(VERSION).spec \$(top_builddir)/\$(AX_RPM_SPEC_FILE).in
  132. spec: \$(top_builddir)/\$(PACKAGE)-\$(VERSION).spec
  133. \$(top_builddir)/\$(PACKAGE)-\$(VERSION).spec: \$(top_builddir)/\$(AX_RPM_SPEC_FILE) \$(top_builddir)/install_files \$(top_builddir)/RPMChangeLog
  134. @cat \"\$(top_builddir)/\$(AX_RPM_SPEC_FILE)\" \\
  135. | \$(GAWK) -v files=\"\$\$files\" \\
  136. '{ print; } \\
  137. /%%defattr/ { while((getline < \"install_files\" ) > 0 ) { print; } }' \\
  138. > \"\$(top_builddir)/\$(PACKAGE)-\$(VERSION).spec\"
  139. @cat \"\$(top_builddir)/RPMChangeLog\" >> \"\$(top_builddir)/\$(PACKAGE)-\$(VERSION).spec\"
  140. AX_DIST_RPM_CLEANFILES += \\
  141. \$(top_builddir)/*.rpm \\
  142. \$(top_builddir)/rpmmacros
  143. ~/.rpmmacros:
  144. @echo \"~/.rpmmacros not found. Creating one like the following:\"; \\
  145. echo \"\"; \\
  146. echo \"%%packager <YOUR NAME>\"; \\
  147. echo \"\"; \\
  148. echo \"%%distribution <YOUR_DISTRIBUTION>\"; \\
  149. echo \"%%vendor <YOUR_ORGANISATION>\"; \\
  150. echo \"\"; \\
  151. echo \"%%_topdir \$\$HOME/\"; \\
  152. echo \"%%_tmppath /tmp/\"; \\
  153. echo \"\"; \\
  154. echo \"%%_rpmtopdir %%{_topdir}rpm/\"; \\
  155. echo \"%%_builddir %%{_tmppath}\"; \\
  156. echo \"%%_rpmdir %%{_rpmtopdir}RPMS/\"; \\
  157. echo \"%%_sourcedir %%{_rpmtopdir}SOURCES/\"; \\
  158. echo \"%%_specdir %%{_rpmtopdir}SPECS/\"; \\
  159. echo \"%%_srcrpmdir %%{_rpmtopdir}SRPMS/\"; \\
  160. echo \"\"; \\
  161. echo \"Where <YOUR_NAME> is your name and <YOUR_DISTRIBUTION> is the\"; \\
  162. echo \"distribution you are building on (e.g. SuSE Linux 8.2 or\"; \\
  163. echo \"RedHat Linux 7.1). and <YOUR_ORGANISATION> is the organisation\"; \\
  164. echo \"you are associated with.\"; \\
  165. echo \"\"; \\
  166. echo \"Running 'make create-rpmmacros' will create a ~/.rpmmacros file\"; \\
  167. echo \"for you and try to open it in an editor\"; \\
  168. exit -1
  169. create-rpmmacros:
  170. @if test -e ~/.rpmmacros; then \\
  171. echo \"Error: ~/.rpmmacros already exists\"; \\
  172. echo \"Please remove it if you want to use\"; \\
  173. echo \"this command to replace it\"; \\
  174. exit -1; \\
  175. else \\
  176. echo \"%%packager <YOUR NAME>\" > ~/.rpmmacros; \\
  177. echo \"\" >> ~/.rpmmacros; \\
  178. echo \"%%distribution <YOUR_DISTRIBUTION>\" >> ~/.rpmmacros; \\
  179. echo \"%%vendor <YOUR_ORGANISATION>\" >> ~/.rpmmacros; \\
  180. echo \"\" >> ~/.rpmmacros; \\
  181. echo \"%%_topdir \$\$HOME/\" >> ~/.rpmmacros; \\
  182. echo \"%%_tmppath /tmp/\" >> ~/.rpmmacros; \\
  183. echo \"\" >> ~/.rpmmacros; \\
  184. echo \"%%_rpmtopdir %%{_topdir}rpm/\" >> ~/.rpmmacros; \\
  185. echo \"%%_builddir %%{_tmppath}\" >> ~/.rpmmacros; \\
  186. echo \"%%_rpmdir %%{_rpmtopdir}RPMS/\" >> ~/.rpmmacros; \\
  187. echo \"%%_sourcedir %%{_rpmtopdir}SOURCES/\" >> ~/.rpmmacros; \\
  188. echo \"%%_specdir %%{_rpmtopdir}SPECS/\" >> ~/.rpmmacros; \\
  189. echo \"%%_srcrpmdir %%{_rpmtopdir}SRPMS/\" >> ~/.rpmmacros; \\
  190. if test \"x$EDITOR\" = "x"; then \\
  191. echo \"Error: no editor specified or found.\"; \\
  192. echo \"Please edit ~/.rpmmacros manually\"; \\
  193. else \\
  194. $EDITOR ~/.rpmmacros; \\
  195. exit \$\$?; \\
  196. fi \\
  197. fi
  198. rpmmacros: ~/.rpmmacros
  199. @cp -f ~/.rpmmacros rpmmacros;
  200. dist-rpm: rpm
  201. dist-srpm: srpm
  202. rpm: \$(PACKAGE)-\$(VERSION)-0.i*.$PLATFORM_SUFFIX.rpm
  203. srpm: \$(PACKAGE)-\$(VERSION)-0.src.rpm
  204. \$(top_builddir)/\$(PACKAGE)-\$(VERSION)-0.i*.$PLATFORM_SUFFIX.rpm: \$(top_builddir)/rpmmacros \$(top_builddir)/\$(PACKAGE)-\$(VERSION).tar.gz
  205. @\$(RPM) -tb \$(top_builddir)/\$(PACKAGE)-\$(VERSION).tar.gz
  206. @RPMDIR=\`cat \$(top_builddir)/rpmmacros | \$(GAWK) '/%%_rpmdir/ { print \$${AX_DOLLAR}2; }'\`; \\
  207. echo \"\$\$RPMDIR\" | \$(EGREP) \"%%{.*}\" > /dev/null 2>&1; \\
  208. EXIT=\$\$?; \\
  209. while test \"\$\$EXIT\" == \"0\"; do \\
  210. RPMDIR=\`echo \"\$\$RPMDIR\" | \$(GAWK) '/%%{.*}/ \\
  211. { match( \$${AX_DOLLAR}0, /%%{.*}/, macro ); \\
  212. suffix = substr( \$${AX_DOLLAR}0, RSTART + RLENGTH ); \\
  213. gsub( /{|}/, \"\", macro[ 0 ] ); \\
  214. while( ( getline < \"\$(top_builddir)/rpmmacros\" ) > 0 ) \\
  215. { if( \$${AX_DOLLAR}1 == macro[ 0 ] ) { print \$${AX_DOLLAR}2 suffix; exit; } } \\
  216. exit 1; \\
  217. }'\`; \\
  218. if test \"\$${AX_DOLLAR}?\" == \"0\"; then \\
  219. echo \"\$\$RPMDIR\" | \$(EGREP) \"%%{.*}\" > /dev/null 2>&1; \\
  220. EXIT=\"\$${AX_DOLLAR}?\"; \\
  221. else \\
  222. EXIT=\"1\"; \\
  223. fi; \\
  224. done; \\
  225. if test -d \"\$\$RPMDIR\"; then \\
  226. for dir in \`ls \"\$\$RPMDIR\"\`; do \\
  227. ls \"\$\${RPMDIR}\$\${dir}/\$(PACKAGE)-\$(VERSION)-0.\$\${dir}.rpm\" > /dev/null 2>&1; \\
  228. if test \"\$${AX_DOLLAR}?\" == \"0\"; then \\
  229. cp \"\$\${RPMDIR}\$\${dir}/\$(PACKAGE)-\$(VERSION)-0.\$\${dir}.rpm\" \"\$(top_builddir)/\$(PACKAGE)-\$(VERSION)-0.\$\${dir}.$PLATFORM_SUFFIX.rpm\"; \\
  230. found=true; \\
  231. fi; \\
  232. done; \\
  233. if ! \$\$found; then \\
  234. echo \"RPM built but not found.\"; \\
  235. echo \"Please copy it to \$(top_builddir) manually.\"; \\
  236. exit 1; \\
  237. fi; \\
  238. else \\
  239. echo \"RPM built but I cannot find RPM directory.\"; \\
  240. echo \"Please copy it to \$(top_builddir) manually.\"; \\
  241. exit 1; \\
  242. fi;
  243. \$(top_builddir)/\$(PACKAGE)-\$(VERSION).tar.gz: \$(top_builddir)/install_files
  244. cd \"\$(top_builddir)\" && \$(MAKE) \$(AM_MAKEFLAGS) dist-gzip
  245. \$(PACKAGE)-\$(VERSION)-0.src.rpm: \$(top_builddir)/rpmmacros \$(top_builddir)/\$(PACKAGE)-\$(VERSION).tar.gz
  246. @\$(RPM) -ts \$(top_builddir)/\$(PACKAGE)-\$(VERSION).tar.gz
  247. @SRPMDIR=\`cat rpmmacros | \$(GAWK) '/%%_srcrpmdir/ { print ${AX_DOLLAR}${AX_DOLLAR}2; }'\`; \\
  248. echo \"${AX_DOLLAR}${AX_DOLLAR}SRPMDIR\" | \$(EGREP) \"%%{.*}\" > /dev/null 2>&1; \\
  249. EXIT=${AX_DOLLAR}${AX_DOLLAR}?; \\
  250. while test \"${AX_DOLLAR}${AX_DOLLAR}EXIT\" == \"0\"; do \\
  251. SRPMDIR=\`echo \"${AX_DOLLAR}${AX_DOLLAR}SRPMDIR\" | \$(GAWK) '/%%{.*}/ \\
  252. { match( ${AX_DOLLAR}${AX_DOLLAR}0, /%%{.*}/, macro ); \\
  253. suffix = substr( ${AX_DOLLAR}${AX_DOLLAR}0, RSTART + RLENGTH ); \\
  254. gsub( /{|}/, \"\", macro[ 0 ] ); \\
  255. while( ( getline < \"rpmmacros\" ) > 0 ) \\
  256. { if( ${AX_DOLLAR}${AX_DOLLAR}1 == macro[ 0 ] ) { print ${AX_DOLLAR}${AX_DOLLAR}2 suffix; exit; } } \\
  257. exit 1; \\
  258. }'\`; \\
  259. if test \"${AX_DOLLAR}${AX_DOLLAR}?\" == \"0\"; then \\
  260. echo \"${AX_DOLLAR}${AX_DOLLAR}SRPMDIR\" | \$(EGREP) \"%%{.*}\" > /dev/null 2>&1; \\
  261. EXIT=\"${AX_DOLLAR}${AX_DOLLAR}?\"; \\
  262. else \\
  263. EXIT=\"1\"; \\
  264. fi; \\
  265. done; \\
  266. if test -d \"${AX_DOLLAR}${AX_DOLLAR}SRPMDIR\"; then \\
  267. ls \"${AX_DOLLAR}${AX_DOLLAR}{SRPMDIR}/\$(PACKAGE)-\$(VERSION)-0.src.rpm\" > /dev/null 2>&1; \\
  268. if test \"${AX_DOLLAR}${AX_DOLLAR}?\" == \"0\"; then \\
  269. cp \"\$${AX_DOLLAR}{SRPMDIR}/\$(PACKAGE)-\$(VERSION)-0.src.rpm\" \"${AX_DOLLAR}(top_builddir)/.\"; \\
  270. found=true; \\
  271. fi; \\
  272. if ! ${AX_DOLLAR}${AX_DOLLAR}found; then \\
  273. echo \"SRPM built but not found.\"; \\
  274. echo \"Please copy it to ${AX_DOLLAR}(top_builddir) manually.\"; \\
  275. exit 1; \\
  276. fi; \\
  277. else \\
  278. echo \"SRPM built but I cannot find SRPM directory.\"; \\
  279. echo \"Please copy it to ${AX_DOLLAR}(top_builddir) directory manually.\"; \\
  280. exit 1; \\
  281. fi;
  282. AX_DIST_RPM_EXTRA_BIN_DISTS = rpm
  283. AX_DIST_RPM_EXTRA_SRC_DISTS = srpm
  284. if ax_dist_rpm_enable_upload
  285. AX_DIST_RPM_UPLOAD_BIN = upload-rpm
  286. AX_DIST_RPM_UPLOAD_SRC = upload-srpm
  287. AX_DIST_RPM_UPLOAD_TARGETS = \\
  288. {rpm=>$PACKAGE-$VERSION-0.i*.$PLATFORM_SUFFIX.rpm} \\
  289. {srpm=>$PACKAGE-$VERSION-0.src.rpm}
  290. endif # ax_dist_rpm_enable_upload
  291. endif # ax_dist_rpm_enabled
  292. # These rules are included unconditionally since we cannot conditionally add
  293. # dependencies.
  294. clean-local: clean-ax-dist-rpm
  295. clean-ax-dist-rpm:
  296. -test -z \"\$(AX_DIST_RPM_CLEANFILES)\" || rm -f \$(AX_DIST_RPM_CLEANFILES)
  297. dist-hook: dist-hook-ax-dist-rpm
  298. dist-hook-ax-dist-rpm: \$(AX_DIST_RPM_EXTRA_DIST)
  299. -test -z \"\$(AX_DIST_RPM_EXTRA_DIST)\" || cp \$(AX_DIST_RPM_EXTRA_DIST) \$(distdir)
  300. ])
  301. ])