1##### http://autoconf-archive.cryp.to/am_rpm_init.html
2#
3# SYNOPSIS
4#
5#   AM_RPM_INIT
6#
7# DESCRIPTION
8#
9#   Setup variables for creation of rpms. It will define several
10#   variables useful for creating rpms on a system where rpms are
11#   supported. Currently, I requires changes to Makefile.am to function
12#   properly (see the example below).
13#
14#   Also note that I do not use any non-UNIX OSs (and for the most
15#   part, I only use RedHat), so this is probably generally not useful
16#   for other systems.
17#
18#   Required setup:
19#
20#   In configure.in:
21#
22#     dnl For my rpm.m4 macros
23#     RELEASE=1
24#     AC_SUBST(RELEASE)
25#
26#     AM_RPM_INIT
27#     dnl Enable or disable the rpm making rules in Makefile.am
28#     AM_CONDITIONAL(MAKE_RPMS, test x$make_rpms = xtrue)
29#
30#   Furthermore, the %GNUconfigure rpm macro has a problem in that it
31#   does not define CXXFLAGS for the target system correctly, so for
32#   compiling C++ code, add the following line _before_ calling
33#   AC_PROG_CXX:
34#
35#     dnl This is a little hack to make this work with rpm better (see mysql++.spec.in)
36#     test -z "$CXXFLAGS" && CXXFLAGS="${CFLAGS}"
37#
38#   Changes to Makefile.am (I am trying to get rid of this step;
39#   suggestions invited):
40#
41#   if MAKE_RPMS
42#     rpm: @RPM_TARGET@
43#
44#     srpm: @SRPM_TARGET@
45#
46#     .PHONY: rpm srpm
47#
48#     $(RPM_TARGET): $(DISTFILES)
49#       ${MAKE} dist
50#       -mkdir -p $(SRPM_DIR)
51#       -mkdir -p `dirname $(RPM_TARGET)`
52#       $(RPMBUILD_PROG) --define 'version $(VERSION)' --define 'rel $(RELEASE)' $(RPM_ARGS) $(RPM_TARBALL)
53#       @echo "$(RPM_TARGET) created"
54#
55#     $(SRPM_TARGET): $(DISTFILES)
56#       ${MAKE} dist
57#       -mkdir -p $(SRPM_DIR)
58#       $(RPMBUILD_PROG) --define 'version $(VERSION)' --define 'rel $(RELEASE)' $(SRPM_ARGS) $(RPM_TARBALL)
59#       @echo "$(SRPM_TARGET) created"
60#   endif
61#
62#   Also, it works best with a XXXX.spec.in file like the following
63#   (this is way down on the wishlist, but a program to generate the
64#   skeleton spec.in much like autoscan would just kick butt!):
65#
66#     ---------- 8< ----------
67#     # -*- Mode:rpm-spec -*-
68#     # mysql++.spec.in
69#     Summary: Your package description goes here
70#     %define rel @RELEASE@
71#
72#     %define version @VERSION@
73#     %define pkgname @PACKAGE@
74#     %define prefix /usr
75#
76#     %define lt_release @LT_RELEASE@
77#     %define lt_version @LT_CURRENT@.@LT_REVISION@.@LT_AGE@
78#
79#     # This is a hack until I can figure out how to better handle replacing
80#     # autoconf macros... (gotta love autoconf...)
81#     %define __aclocal   aclocal || aclocal -I ./macros
82#     %define configure_args  @RPM_CONFIGURE_ARGS@
83#
84#     Name: %{pkgname}
85#     Version: %{version}
86#     Release: %{rel}
87#
88#     Copyright: LGPL
89#     Group: # your group name goes here
90#     Source: %{pkgname}-%{version}.tar.gz
91#     Requires: # additional requirements
92#     Buildroot: /tmp/%{pkgname}-root
93#     URL: http://yoururl.go.here
94#     Prefix: %{prefix}
95#     BuildArchitectures: # Target platforms, i.e., i586
96#     Packager: Your Name <youremail@your.address>
97#
98#     %description
99#     Your package description
100#
101#     %changelog
102#
103#     %prep
104#     %setup
105#     #%patch
106#
107#     %build
108#     %GNUconfigure %{configure_args}
109#     # This is why we copy the CFLAGS to the CXXFLAGS in configure.in
110#     # CFLAGS="%{optflags}" CXXFLAGS="%{optflags}" ./configure %{_target_platform} --prefix=%{prefix}
111#     make
112#
113#     %install
114#     # To make things work with BUILDROOT
115#     if [ "$RPM_BUILD_ROOT" != "/tmp/%{pkgname}-root" ]
116#     then
117#       echo
118#       echo @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
119#       echo @                                                                    @
120#       echo @  RPM_BUILD_ROOT is not what I expected.  Please clean it yourself. @
121#       echo @                                                                    @
122#       echo @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
123#       echo
124#     else
125#       echo Cleaning RPM_BUILD_ROOT: "$RPM_BUILD_ROOT"
126#       rm -rf "$RPM_BUILD_ROOT"
127#     fi
128#     make DESTDIR="$RPM_BUILD_ROOT" install
129#
130#     %clean
131#     # Call me paranoid, but I do not want to be responsible for nuking
132#     # someone's harddrive!
133#     if [ "$RPM_BUILD_ROOT" != "/tmp/%{pkgname}-root" ]
134#     then
135#       echo
136#       echo @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
137#       echo @                                                                    @
138#       echo @  RPM_BUILD_ROOT is not what I expected.  Please clean it yourself. @
139#       echo @                                                                    @
140#       echo @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
141#       echo
142#     else
143#       echo Cleaning RPM_BUILD_ROOT: "$RPM_BUILD_ROOT"
144#       rm -rf "$RPM_BUILD_ROOT"
145#     fi
146#
147#     %files
148#     %defattr(-, root, root)
149#     # Your application file list goes here
150#     # %{prefix}/lib/lib*.so*
151#     %doc COPYRIGHT ChangeLog README AUTHORS NEWS
152#     %doc doc/*
153#
154#     # If you install a library
155#     %post -p /sbin/ldconfig
156#
157#     # If you install a library
158#     %postun -p /sbin/ldconfig
159#
160#     %package devel
161#     Summary: Development files for %{pkgname}
162#     Group: Applications/Databases
163#     %description devel
164#     Development files for %{pkgname}.
165#
166#     %files devel
167#     %defattr(-, root, root)
168#     # Your development files go here
169#     # Programmers documentation goes here
170#     %doc doc
171#
172#     # end of file
173#     ---------- >8 ----------
174#
175# LAST MODIFICATION
176#
177#   2000-07-19
178#
179# COPYLEFT
180#
181#   Copyright (c) 2000 Dale K. Hawkins <dhawkins@cdrgts.com>
182#
183#   Copying and distribution of this file, with or without
184#   modification, are permitted in any medium without royalty provided
185#   the copyright notice and this notice are preserved.
186
187dnl AM_RPM_INIT
188dnl Figure out how to create rpms for this system and setup for an
189dnl automake target
190
191AC_DEFUN([AM_RPM_INIT],
192[dnl
193AC_REQUIRE([AC_CANONICAL_HOST])
194dnl Find the RPM program
195AC_ARG_WITH(rpmbuild-prog,[  --with-rpmbuild-prog=PROG   Which rpm to use (optional)],
196            rpmbuild_prog="$withval", rpmbuild_prog="")
197
198AC_ARG_ENABLE(rpm-rules, [  --enable-rpm-rules       Try to create rpm make rules (defaults to yes)],
199                enable_rpm_rules="$withval",enable_rpm_rules=yes)
200
201AC_ARG_WITH(rpm-arch, [  --with-rpm-arch=ARCH     Use the given architecture to build (defaults to auto)],
202                rpmarch="$withval",rpmarch="auto")
203
204AC_ARG_WITH(rpm-extra-args, [  --with-rpm-extra-args=ARGS       Run rpm with extra arguments (defaults to none)],
205                rpm_extra_args="$withval", rpm_extra_args="")
206
207  RPM_TARGET=""
208
209  if test x$enable_rpm_rules = xno ; then
210     echo "Not trying to build rpms for your system"
211     no_rpm=yes
212  else
213    if test x$rpmbuild_prog != x ; then
214       if test x${RPMBUILD_PROG+set} != xset ; then
215          RPMBUILD_PROG=$rpmbuild_prog
216       fi
217    fi
218
219    if test x$rpmarch = xauto; then
220      if test x${RPM_ARCH+set} != xset ; then
221        RPM_ARCH=`rpm --eval '%{_arch}'`
222      fi
223    elif test x${rpmarch+set} = xset ; then
224      RPM_ARCH=$rpmarch
225    else
226      RPM_ARCH=`rpm --eval '%{_arch}'`
227    fi
228
229    AC_PATH_PROG(RPMBUILD_PROG, rpmbuild, no)
230    no_rpm=no
231    if test "$RPMBUILD_PROG" = "no" ; then
232echo "*** RPM Configuration Failed"
233echo "*** Failed to find the rpmbuild program.  If you want to build rpm packages"
234echo "*** indicate the path to the rpmbuild program using  --with-rpmbuild-prog=PROG"
235      no_rpm=yes
236      RPM_MAKE_RULES=""
237    else
238      AC_MSG_CHECKING(how rpm sets %{_rpmdir})
239      rpmdir=`rpm --eval '%{_rpmdir}'`
240      if test x$rpmdir = x'%{_rpmdir}' ; then
241        AC_MSG_RESULT([not set (cannot build rpms?)])
242        echo "*** Could not determine the value of %{_rpmdir}"
243        echo "*** This could be because it is not set, or your version of rpm does not set it"
244        echo "*** It must be set in order to generate the correct rpm generation commands"
245        echo "***"
246        echo "*** You might still be able to create rpms, but I could not automate it for you"
247        echo "*** BTW, if you know this is wrong, please help to improve the rpm.m4 module"
248        echo "*** Send corrections, updates and fixes to dhawkins@cdrgts.com.  Thanks."
249      else
250        AC_MSG_RESULT([$rpmdir])
251      fi
252      AC_MSG_CHECKING(how rpm sets %{_srcrpmdir})
253      srcrpmdir=`rpm --eval '%{_srcrpmdir}'`
254      if test x$srcrpmdir = x'%{_srcrpmdir}' ; then
255        AC_MSG_RESULT([not set (cannot build rpms?)])
256        echo "*** Could not determine the value of %{_srcrpmdir}"
257        echo "*** This could be because it is not set, or your version of rpm does not set it"
258        echo "*** It must be set in order to generate the correct rpm generation commands"
259        echo "***"
260        echo "*** You might still be able to create rpms, but I could not automate it for you"
261        echo "*** BTW, if you know this is wrong, please help to improve the rpm.m4 module"
262        echo "*** Send corrections, updates and fixes to dhawkins@cdrgts.com.  Thanks."
263      else
264        AC_MSG_RESULT([$srcrpmdir])
265      fi
266      AC_MSG_CHECKING(where RPMs end up)
267      rpmfilename=$rpmdir/`rpm --eval '%{_rpmfilename}' | sed -e 's/%{ARCH}/$(RPM_ARCH)/g' -e 's/%{NAME}/$(PACKAGE)/g' -e 's/%{VERSION}/$(VERSION)/g' -e 's/%{RELEASE}/$(RELEASE)/g'`
268      AC_MSG_RESULT([$rpmfilename])
269      AC_MSG_CHECKING(where source RPMs end up)
270      srcrpmfilename=$srcrpmdir/`rpm --eval '%{_rpmfilename}' | sed -e 's/^%{ARCH}\///g' -e 's/%{ARCH}/src/g' -e 's/%{NAME}/$(PACKAGE)/g' -e 's/%{VERSION}/$(VERSION)/g' -e 's/%{RELEASE}/$(RELEASE)/g'`
271      AC_MSG_RESULT([$srcrpmfilename])
272      AC_MSG_CHECKING(where source files go)
273      rpmsrcdir=`rpm --eval '%{_sourcedir}'`
274      AC_MSG_RESULT([$rpmsrcdir])
275
276      RPM_SOURCE_DIR="${rpmsrcdir}"
277      RPM_DIR="${rpmdir}"
278      SRPM_DIR="${srcrpmdir}"
279      RPM_TARGET="${rpmfilename}"
280      SRPM_TARGET="${srcrpmfilename}"
281      RPM_ARGS="-ta --target=${RPM_ARCH} ${rpm_extra_args}"
282      SRPM_ARGS="-ts ${rpm_extra_args}"
283      RPM_EXTRA_ARGS="${rpm_extra_args}"
284      RPM_TARBALL='$(PACKAGE)-$(VERSION).tar.gz'
285    fi
286  fi
287
288  case "${no_rpm}" in
289    yes) make_rpms=false;;
290    no) make_rpms=true;;
291    *) AC_MSG_WARN([not making rpms])
292       make_rpms=false;;
293  esac
294  AC_SUBST(RPM_SOURCE_DIR)
295  AC_SUBST(RPM_DIR)
296  AC_SUBST(SRPM_DIR)
297  AC_SUBST(RPM_TARGET)
298  AC_SUBST(SRPM_TARGET)
299  AC_SUBST(RPM_ARGS)
300  AC_SUBST(SRPM_ARGS)
301  AC_SUBST(RPM_EXTRA_ARGS)
302  AC_SUBST(RPM_TARBALL)
303  AC_SUBST(RPM_ARCH)
304
305  RPM_CONFIGURE_ARGS=${ac_configure_args}
306  AC_SUBST(RPM_CONFIGURE_ARGS)
307])
308