]> err.no Git - sope/blob - gnustep-make/Master/rpm.make
gnu runtime bugfix
[sope] / gnustep-make / Master / rpm.make
1 #
2 #   rpm.make
3 #
4 #   Makefile rules to build a RPM spec files and RPM packages
5 #
6 #   Copyright (C) 2001 Free Software Foundation, Inc.
7 #
8 #   Author: Nicola Pero <n.pero@mi.flashnet.it>
9 #  
10 #   This file is part of the GNUstep Makefile Package.
11 #
12 #   This library is free software; you can redistribute it and/or
13 #   modify it under the terms of the GNU General Public License
14 #   as published by the Free Software Foundation; either version 2
15 #   of the License, or (at your option) any later version.
16 #   
17 #   You should have received a copy of the GNU General Public
18 #   License along with this library; see the file COPYING.LIB.
19 #   If not, write to the Free Software Foundation,
20 #   51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21
22 #
23 # FIXME: Move all this documentation into the documentation
24 #
25
26 #
27 # FIXME/TODO: Update for GNUSTEP_BUILD_DIR
28 #
29
30 # rpm puts all tools, bundles, applications, subprojects, libraries,
31 # etc specified in the GNUmakefile into a single rpm. There aren't any
32 # provisions for putting separate apps/tools/etc in separate rpms
33 # (other than putting them in separate dirs).
34
35 # Note: we don't make development packages separated from the standard
36 # ones.  Every package containing a library's object files will also
37 # contain the header files for the library <only the ones which were
38 # declared in the makefile of course>.
39 #
40 #
41 # You can build two kind of packages:
42 #  - normal packages
43 #  - debugging packages
44 #
45 # First we describe normal packages.
46 #
47 # the make package generates automatically:
48 #  * the .tgz source file to be copied into where_you_build_rpms/SOURCES/
49 #    <generated by source-dist.make>
50 #
51 #  * the spec file to be copied into where_you_build_rpms/SPECS/
52 #    <generate by rpm.make>
53 #
54 # at this point, to build the rpm you just do
55 #  cd where_you_build_rpms/SPECS/
56 #  rpm -ba my_package.spec
57 #
58 # If you are *very* lazy, typing `make rpm' will do it all automatically 
59 # for you.  But in that case, you need to have set the shell environment 
60 # variable `RPM_TOPDIR' to the top dir of where you build rpms (eg, 
61 # /usr/src/redhat/).
62 #
63
64 # To build the spec file for a package, you need to do two things:
65
66 # [1] Add - after common.make - the following lines in your GNUmakefile:
67 #
68 # PACKAGE_NAME = Gomoku
69 # PACKAGE_VERSION = 1.1.1
70
71 # (replace them with name, version of your software).  This is mainly
72 # needed so that when you build the .tgz and the spec file, they have
73 # names which are in sync.  Make sure to keep the library version and
74 # the package version in sync.
75 #
76 # The other important variable you may want to set in your makefiles is
77 #
78 # GNUSTEP_INSTALLATION_DIR - Installation dir (defaults to GNUSTEP_LOCAL_ROOT)
79 #
80 # If your package is relocatable (this is true by default - see below
81 # for how to make it non-relocatable) the user will be able to install
82 # the package elsewhere by using something like `rpm -Uvh --prefix
83 # /home/nicola/GNUstep your_package.rpm' when installing the package.
84 #
85
86 # [2] Provide a $(PACKAGE_NAME).spec.in file, which contains the RPM
87 # spec preamble.  Here is an example:
88
89 # Summary: A table board game
90 # Release: 1
91 # Copyright: GPL
92 # Group: Amusements/Games
93 # Source: http://www.gnustep.it/nicola/Applications/Gomoku/%{gs_name}-%{gs_version}.tar.gz
94 #
95 # %description 
96 # Gomoku is an extended TicTacToe game for GNUstep. You win the game if
97 # you are able to put 5 of your pieces in a row, column or diagonal. You
98 # loose if the computer does it before you. You can play the game on
99 # boards of different size; the default size is 8 but 10 is also nice to
100 # play. The game has 6 different difficulty levels.
101
102 # Comments:
103 #  you must not include: `Name', `Version', `BuildRoot' and `Prefix'
104 # entries.  These are generated automatically; `Name' and `Version'
105 # from $(PACKAGE_NAME) and $(PACKAGE_VERSION), and so for BuildRoot
106 # and Prefix.  you might include all the other tags listed in the RPM
107 # doc if you want.  The `Prefix:' entry is automatically included only
108 # if your package is relocatable (should be the default for all
109 # non-system packages.  If you want your package to be non-relocatable
110 # (to be used only for system packages which *must* be installed in
111 # GNUSTEP_SYSTEM_ROOT), add the line
112 #
113 #  RPM_DISABLE_RELOCATABLE=YES
114 #
115 #  (FIXME improve variable name) to your GNUmakefile.  This will not generate 
116 #  a `Prefix:' line in the spec file.
117 #
118 #  
119 #  You can use the following if you need:
120 #  %{gs_name}    expands to the value of the make variable PACKAGE_NAME
121 #  %{gs_version} expands to the value of the make variable PACKAGE_VERSION  
122 #  (make sure you use them in `Source:' as shown).
123 #
124 #
125
126 # A special note: if you need `./configure --prefix=/usr/GNUstep'
127 # (/usr/GNUstep being replaced by your GNUSTEP_SYSTEM_ROOT) to be run
128 # before compilation (usually only needed for GNUstep core libraries
129 # themselves), define the following make variable:
130 #
131 # PACKAGE_NEEDS_CONFIGURE = YES
132 #
133 # in your makefile.
134
135 #
136 # At this point, typing 
137 #  `make dist' will generate the .tgz (can be used outside rpm.make)
138 #  `make specfile' will generate the (matching) specfile.
139 #
140
141
142 # Debugging packages.
143 #
144
145 #
146 # A debugging package is called
147 # $(PACKAGE_NAME)-debug-$(PACKAGE_VERSION) rather than
148 # $(PACKAGE_NAME)-$(PACKAGE_VERSION).  The source .tgz have the same
149 # name though.  The source rpm package instead has a different name
150 # because it contains the .spec file, which is different between debug
151 # and non debug version.
152 #
153 # To build the spec for the debugging package, type `make debug=yes specfile'. 
154 # This builds a specfile as for the non-debugging package, except:
155 #
156 # It uses $(PACKAGE_NAME)-debug.spec.in rather than
157 # ${PACKAGE_NAME).spec.in if found.  (this allows you to customize
158 # package description, summary, release number, group for the
159 # debugging case).
160 #
161 # It will compile everything with debugging enabled when building the 
162 # debugging package.
163 #
164 # It will manage the package having a different name (eg
165 # Gomoku-debug-1.1.1) than the .tgz (eg Gomoku-1.1.1.tgz).
166 #
167 # Unless `standalone=yes' (ie, unless you create the specfile using 
168 # `make debug=yes standalone=yes specfile') it will perform the following 
169 # additional tasks:
170 #
171 #  * build and install the non-debugging software before the debugging one;
172 #  * remove from the debugging package all files already included in the 
173 #    non-debugging one (this is why it needs to build the non-debugging 
174 #    software first);
175 #  * add a dependency of the debugging package from the non-debugging one.
176 #
177 # <FIXME: Add comments about when is appropriate one and when the other one>
178
179 #
180 # As said before, if you are very lazy, typing something like
181 #
182 # make distclean
183 # `RPM_TOPDIR=/usr/src/redhat' make rpm
184 #
185 # will do the whole job once you have written your '.spec.in' file,
186 # and set the PACKAGE_NAME and PACKAGE_VERSION variables in the makefile.
187 # The generated rpm will be in /usr/src/redhat/RPMS/.
188 #
189
190 #
191 # Internal targets
192 #
193
194 # If we have been called with something like
195 #
196 # make INSTALL_ROOT_DIR=/var/tmp/package-build/ \
197 #      GNUSTEP_INSTALLATION_DIR=/var/tmp/package-build/usr/GNUstep/Local \
198 #      filelist=yes install
199 #
200 # we are being called inside the rpm installation stage, and we need
201 # to produce the file list from the installed files.
202
203 ifeq ($(filelist),yes)
204
205   # Build the file-list only at top level
206 #  ifeq ($(MAKELEVEL),0)
207
208   # Determine which file list to build
209   ifeq ($(debug),yes)
210     FILE_LIST = $(shell pwd)/file-list-debug
211    else
212     FILE_LIST = $(shell pwd)/file-list
213   endif
214
215   # Remove the old file list before installing, and initialize the new one.
216   before-install::
217         -rm -f $(FILE_LIST)
218         echo "%attr (-, root, root)" >> $(FILE_LIST)
219
220   # install - done by other GNUmakefiles - NB: must install everything inside
221   # GNUSTEP_INSTALLATION_DIR, or prefix all installation dirs with 
222   # $INSTALL_ROOT_DIR such as 
223   # $(INSTALL_DATA) page.html $(INSTALL_ROOT_DIR)/usr/local/MySoftware/
224   # instead of $(INSTALL_DATA) page.html /usr/local/MySoftware/
225
226   # Get the list of files inside GNUSTEP_INSTALL_BASE
227   internal-after-install::
228         for file in `$(TAR) Pcf - $(INSTALL_ROOT_DIR) | $(TAR) t`; do \
229           if [ -d "$$file" ]; then                                \
230             echo "%dir $$file" > /dev/null;                       \
231           else                                                    \
232             echo "$$file" >> $(FILE_LIST);                        \
233           fi;                                                     \
234         done                                                    
235         sed -e "s|$(INSTALL_ROOT_DIR)||" $(FILE_LIST) > file-list.tmp
236         mv file-list.tmp $(FILE_LIST)                             
237
238 #  endif # MAKELEVEL
239
240 endif # filelist == yes
241
242
243 #
244 # Manage debug vs non-debug
245 #
246 ifneq ($(debug), yes)
247   SPEC_FILE=$(PACKAGE_NAME).spec
248   SPEC_RULES_TEMPLATE=$(GNUSTEP_MAKEFILES)/spec-rules.template
249   SPEC_IN=$(PACKAGE_NAME).spec.in
250   SPEC_SCRIPT_IN=$(PACKAGE_NAME).script.spec.in
251   PACKAGE_EXTENSION=""
252 else
253   SPEC_FILE=$(PACKAGE_NAME)-debug.spec
254   ifeq ($(standalone),yes)
255     SPEC_RULES_TEMPLATE=$(GNUSTEP_MAKEFILES)/spec-debug-alone-rules.template
256   else 
257     SPEC_RULES_TEMPLATE=$(GNUSTEP_MAKEFILES)/spec-debug-rules.template
258   endif
259   SPEC_IN=$(PACKAGE_NAME)-debug.spec.in
260   SPEC_SCRIPT_IN=$(PACKAGE_NAME)-debug.script.spec.in
261   PACKAGE_EXTENSION="-debug"
262 endif
263
264 .PHONY: specfile rpm check-RPM_TOPDIR
265
266 #
267 # The user will type `make specfile' to generate the specfile
268 #
269 specfile: $(SPEC_FILE)
270
271
272 # Issue a warning if the $(PACKAGE_NAME)-debug.spec.in file is not found
273 #
274 $(PACKAGE_NAME)-debug.spec.in: 
275         @echo "WARNING - $(PACKAGE_NAME)-debug.spec.in not found!"
276         @echo "You need to create it to build the debugging package." 
277         @echo "If you already have a $(PACKAGE_NAME).spec.in, just take it as"
278         @echo "a start for the $(PACKAGE_NAME)-debug.spec.in - and make"
279         @echo "the little necessary changes in summary and description."
280         @echo ""
281
282 #
283 # This is the real target - depends on having a correct .spec.in file
284 #
285 $(SPEC_FILE): $(SPEC_IN)
286         @echo "Generating the spec file..."
287         @-rm -f $@
288         @echo "##" >> $@
289         @echo "## Generated automatically by GNUstep make - do not edit!" >> $@
290         @echo "## Edit the $(SPEC_IN) file instead" >> $@
291         @echo "##" >> $@
292         @echo " " >> $@
293         @echo "## Code dynamically generated" >> $@
294         @echo "%define gs_root         $(GNUSTEP_SYSTEM_ROOT)" >> $@
295         @echo "%define gs_install_dir  $(GNUSTEP_INSTALLATION_DIR)" >> $@
296         @echo "%define gs_name         $(PACKAGE_NAME)" >> $@
297         @echo "%define gs_version      $(PACKAGE_VERSION)" >> $@
298 ifeq ($(PACKAGE_NEEDS_CONFIGURE),YES)
299         @echo "%define gs_configure    YES" >> $@
300 else
301         @echo "%define gs_configure    NO" >> $@
302 endif
303         @echo " " >> $@
304         @echo "Name: %{gs_name}$(PACKAGE_EXTENSION)" >> $@
305         @echo "Version: %{gs_version}" >> $@
306         @echo "BuildRoot: /var/tmp/%{gs_name}-buildroot" >> $@
307 ifeq ($(RPM_DISABLE_RELOCATABLE),YES)
308         @echo "Prefix: %{gs_install_dir}" >> $@
309 endif
310 ifeq ($(debug),yes)
311 ifneq ($(standalone),yes)
312         @echo "requires: %{gs_name} = %{gs_version}" >> $@
313 endif
314 endif
315         @echo "" >> $@
316         @echo "## Code from $(SPEC_IN)" >> $@
317         @cat $(SPEC_IN) >> $@
318         @echo "" >> $@
319         @echo "## Fixed rules from $(SPEC_RULES_TEMPLATE)" >> $@ 
320         @cat $(SPEC_RULES_TEMPLATE) >> $@
321         @ if [ -f $(SPEC_SCRIPT_IN) ]; then                         \
322             echo "" >> $@;                                          \
323             echo "## Script rules from $(SPEC_SCRIPT_IN)" >> $@;    \
324             cat $(SPEC_SCRIPT_IN) >> $@;                            \
325           fi
326
327 check-RPM_TOPDIR:
328         @if [ "$(RPM_TOPDIR)" = "" ]; then                                 \
329           echo "I can't build the RPM if you do not set your RPM_TOPDIR"; \
330           echo "shell variable";                                          \
331           exit 1; \
332         fi;
333
334 # In old RPM versions, building was done using 'rpm -ba'; in newer RPM
335 # versions, it can only be done using 'rpmbuild -ba'.  Try to support
336 # the old RPM versions by using 'rpm' instead of 'rpmbuild', if
337 # 'rpmbuild' is not available.  This hack can presumably be removed
338 # when all RPM versions on earth will have been updated to the new
339 # setup (it might take a while).
340
341 rpm: check-RPM_TOPDIR dist specfile
342         @echo "Generating the rpm...";
343 ifneq ($(RELEASE_DIR),)
344         @cp $(RELEASE_DIR)/$(PACKAGE_NAME)-$(PACKAGE_VERSION).tar.gz \
345             $(RPM_TOPDIR)/SOURCES/;
346 else
347         @cp ../$(PACKAGE_NAME)-$(PACKAGE_VERSION).tar.gz $(RPM_TOPDIR)/SOURCES/;
348 endif   
349         @cp $(SPEC_FILE) $(RPM_TOPDIR)/SPECS/; \
350         cd $(RPM_TOPDIR)/SPECS/; \
351         if which rpmbuild > /dev/null 2>/dev/null; then \
352           rpmbuild="rpmbuild"; \
353         else \
354           if which rpm > /dev/null 2>/dev/null; then \
355             rpmbuild="rpm"; \
356           else \
357             echo "Error: You don't have rpm installed!"; \
358             rpmbuild="rpmbuild"; \
359           fi; \
360         fi; \
361         $${rpmbuild} -ba $(SPEC_FILE)
362
363 ifneq ($(PACKAGE_NAME),)
364 internal-distclean::
365         rm -rf $(PACKAGE_NAME).spec $(PACKAGE_NAME)-debug.spec
366 endif