1#   -*-makefile-*-
2#   rpm.make
3#
4#   Makefile rules to build a RPM spec files and RPM packages
5#
6#   Copyright (C) 2001-2007 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 3
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.
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# When building a package, the make package generates automatically:
42#
43#  * the .tgz source file to be copied into where_you_build_rpms/SOURCES/
44#    <generated by source-dist.make>
45#
46#  * the spec file to be copied into where_you_build_rpms/SPECS/
47#    <generate by rpm.make>
48#
49# at this point, to build the rpm you just do
50#  cd where_you_build_rpms/SPECS/
51#  rpm -ba my_package.spec
52#
53# If you are *very* lazy, typing `make rpm' will do it all automatically
54# for you.  But in that case, you need to have set the shell environment
55# variable `RPM_TOPDIR' to the top dir of where you build rpms (eg,
56# /usr/src/redhat/).
57#
58
59# To build the spec file for a package, you need to do two things:
60
61# [1] Add - after common.make - the following lines in your GNUmakefile:
62#
63# PACKAGE_NAME = Gomoku
64# PACKAGE_VERSION = 1.1.1
65#
66# (replace them with name, version of your software).  This is mainly
67# needed so that when you build the .tgz and the spec file, they have
68# names which are in sync.  Make sure to keep the library version and
69# the package version in sync.
70#
71# The other important variable you may want to set in your makefiles is
72#
73# GNUSTEP_INSTALLATION_DOMAIN - Installation domain (defaults to LOCAL)
74#
75# Make sure that your filesystem layout matches the one of your target
76# system else your files might end up in the wrong directory when
77# installed.  In other words, use the same version of gnustep-make
78# that will be used on the target system, and configured in the same
79# way.
80
81# [2] Provide a $(PACKAGE_NAME).spec.in file, which contains the RPM
82# spec preamble.  Here is an example:
83
84# Summary: A table board game
85# Release: 1
86# License: GPL
87# Group: Amusements/Games
88# Source: http://www.gnustep.it/nicola/Applications/Gomoku/%{gs_name}-%{gs_version}.tar.gz
89#
90# %description
91# Gomoku is an extended TicTacToe game for GNUstep. You win the game if
92# you are able to put 5 of your pieces in a row, column or diagonal. You
93# loose if the computer does it before you. You can play the game on
94# boards of different size; the default size is 8 but 10 is also nice to
95# play. The game has 6 different difficulty levels.
96
97# Comments:
98#  you must not include: `Name', `Version', `BuildRoot' and `Prefix'
99# entries.  These are generated automatically; `Name' and `Version'
100# from $(PACKAGE_NAME) and $(PACKAGE_VERSION), and so for BuildRoot
101# and Prefix.  you might include all the other tags listed in the RPM
102# doc if you want.
103#
104#  You can use the following if you need:
105#  %{gs_name}    expands to the value of the make variable PACKAGE_NAME
106#  %{gs_version} expands to the value of the make variable PACKAGE_VERSION
107#  (make sure you use them in `Source:' as shown).
108#
109
110# A special note: if you need `./configure' to be run before
111# compilation (usually only needed for GNUstep core libraries
112# themselves), define the following make variable:
113#
114# PACKAGE_NEEDS_CONFIGURE = yes
115#
116# in your makefile.
117
118#
119# At this point, typing
120#  `make dist' will generate the .tgz (can be used outside rpm.make)
121#  `make specfile' will generate the (matching) specfile.
122#
123
124#
125# As said before, if you are very lazy, typing something like
126#
127# make distclean
128# `RPM_TOPDIR=/usr/src/redhat' make rpm
129#
130# will do the whole job once you have written your '.spec.in' file,
131# and set the PACKAGE_NAME and PACKAGE_VERSION variables in the makefile.
132# The generated rpm will be in /usr/src/redhat/RPMS/.
133#
134
135#
136# Internal targets
137#
138
139# If we have been called with something like
140#
141# make DESTDIR=/var/tmp/package-build filelist=yes install
142#
143# we are being called inside the rpm installation stage, and we need
144# to produce the file list from the installed files.
145#
146GNUSTEP_FILE_LIST = $(GNUSTEP_OBJ_DIR)/file-list
147
148ifeq ($(filelist),yes)
149
150  # Build the file-list only at top level
151#  ifeq ($(MAKELEVEL),0)
152
153  # Remove the old file list before installing, and initialize the new one.
154  before-install:: $(GNUSTEP_OBJ_DIR)
155	$(ECHO_NOTHING)rm -f $(GNUSTEP_FILE_LIST)$(END_ECHO)
156	$(ECHO_NOTHING)echo "%attr (-, root, root)" >> $(GNUSTEP_FILE_LIST)$(END_ECHO)
157
158  # Get the list of files inside DESTDIR
159  internal-after-install::
160	$(ECHO_NOTHING)for file in `$(TAR) Pcf - $(DESTDIR) | $(TAR) t`; do \
161	  if [ -d "$$file" ]; then                                \
162	    echo "%dir $$file" > /dev/null;                       \
163	  else                                                    \
164	    echo "$$file" >> $(GNUSTEP_FILE_LIST);                \
165	  fi;                                                     \
166	done$(END_ECHO)
167	$(ECHO_NOTHING)sed -e "s|^$(DESTDIR)||" $(GNUSTEP_FILE_LIST) > file-list.tmp$(END_ECHO)
168	$(ECHO_NOTHING)mv file-list.tmp $(GNUSTEP_FILE_LIST)$(END_ECHO)
169
170#  endif # MAKELEVEL
171
172endif # filelist == yes
173
174# NB: The filelist is automatically deleted when GNUSTEP_OBJ_DIR is
175# deleted (that is, by make clean)
176
177SPEC_FILE_NAME=$(PACKAGE_NAME).spec
178SPEC_FILE=$(GNUSTEP_OBJ_DIR)/$(SPEC_FILE_NAME)
179SPEC_RULES_TEMPLATE=$(GNUSTEP_MAKEFILES)/spec-rules.template
180SPEC_IN=$(PACKAGE_NAME).spec.in
181SPEC_SCRIPT_IN=$(PACKAGE_NAME).script.spec.in
182
183# Recognize both YES and yes
184ifeq ($(PACKAGE_NEEDS_CONFIGURE),YES)
185  PACKAGE_NEEDS_CONFIGURE = yes
186endif
187
188.PHONY: specfile rpm check-RPM_TOPDIR
189
190#
191# The user will type `make specfile' to generate the specfile
192#
193specfile: $(SPEC_FILE)
194
195#
196# This is the real target - depends on having a correct .spec.in file
197#
198$(SPEC_FILE): $(SPEC_IN) $(GNUSTEP_OBJ_DIR)
199	$(ECHO_NOTHING)echo "Generating the spec file..."$(END_ECHO)
200	$(ECHO_NOTHING)rm -f $@$(END_ECHO)
201	$(ECHO_NOTHING)echo "##" >> $@$(END_ECHO)
202	$(ECHO_NOTHING)echo "## Generated automatically by GNUstep make - do not edit!" >> $@$(END_ECHO)
203	$(ECHO_NOTHING)echo "## Edit the $(SPEC_IN) file instead" >> $@$(END_ECHO)
204	$(ECHO_NOTHING)echo "##" >> $@$(END_ECHO)
205	$(ECHO_NOTHING)echo " " >> $@$(END_ECHO)
206	$(ECHO_NOTHING)echo "## Code dynamically generated" >> $@$(END_ECHO)
207	$(ECHO_NOTHING)echo "%define gs_name         $(PACKAGE_NAME)" >> $@$(END_ECHO)
208	$(ECHO_NOTHING)echo "%define gs_version      $(PACKAGE_VERSION)" >> $@$(END_ECHO)
209	$(ECHO_NOTHING)echo "%define gs_install_domain $(GNUSTEP_INSTALLATION_DOMAIN)" >> $@$(END_ECHO)
210	$(ECHO_NOTHING)echo "%define gs_makefiles    $(GNUSTEP_MAKEFILES)" >> $@$(END_ECHO)
211	$(ECHO_NOTHING)echo "%define gs_file_list    $(GNUSTEP_FILE_LIST)" >> $@$(END_ECHO)
212ifeq ($(PACKAGE_NEEDS_CONFIGURE),yes)
213	$(ECHO_NOTHING)echo "%define gs_configure    YES" >> $@$(END_ECHO)
214else
215	$(ECHO_NOTHING)echo "%define gs_configure    NO" >> $@$(END_ECHO)
216endif
217	$(ECHO_NOTHING)echo " " >> $@$(END_ECHO)
218	$(ECHO_NOTHING)echo "Name: %{gs_name}" >> $@$(END_ECHO)
219	$(ECHO_NOTHING)echo "Version: %{gs_version}" >> $@$(END_ECHO)
220	$(ECHO_NOTHING)echo "BuildRoot: /var/tmp/%{gs_name}-buildroot" >> $@$(END_ECHO)
221	$(ECHO_NOTHING)echo "" >> $@$(END_ECHO)
222	$(ECHO_NOTHING)echo "## Code from $(SPEC_IN)" >> $@$(END_ECHO)
223	$(ECHO_NOTHING)cat $(SPEC_IN) >> $@$(END_ECHO)
224	$(ECHO_NOTHING)echo "" >> $@$(END_ECHO)
225	$(ECHO_NOTHING)echo "## Fixed rules from $(SPEC_RULES_TEMPLATE)" >> $@$(END_ECHO)
226	$(ECHO_NOTHING)cat $(SPEC_RULES_TEMPLATE) >> $@$(END_ECHO)
227	$(ECHO_NOTHING)if [ -f $(SPEC_SCRIPT_IN) ]; then                         \
228	    echo "" >> $@;                                          \
229	    echo "## Script rules from $(SPEC_SCRIPT_IN)" >> $@;    \
230	    cat $(SPEC_SCRIPT_IN) >> $@;                            \
231          fi$(END_ECHO)
232
233check-RPM_TOPDIR:
234	$(ECHO_NOTHING)if [ "$(RPM_TOPDIR)" = "" ]; then                                 \
235	  echo "I can't build the RPM if you do not set your RPM_TOPDIR"; \
236	  echo "shell variable";                                          \
237	  exit 1; \
238	fi;$(END_ECHO)
239
240# In old RPM versions, building was done using 'rpm -ba'; in newer RPM
241# versions, it can only be done using 'rpmbuild -ba'.  Try to support
242# the old RPM versions by using 'rpm' instead of 'rpmbuild', if
243# 'rpmbuild' is not available.  This hack can presumably be removed
244# when all RPM versions on earth will have been updated to the new
245# setup (it might take a while).
246
247rpm: check-RPM_TOPDIR dist specfile
248	$(ECHO_NOTHING)echo "Generating the rpm..."$(END_ECHO)
249ifneq ($(RELEASE_DIR),)
250	$(ECHO_NOTHING)cp $(RELEASE_DIR)/$(PACKAGE_NAME)-$(PACKAGE_VERSION).tar.gz \
251	    $(RPM_TOPDIR)/SOURCES/$(END_ECHO)
252else
253	$(ECHO_NOTHING)cp ../$(PACKAGE_NAME)-$(PACKAGE_VERSION).tar.gz $(RPM_TOPDIR)/SOURCES/$(END_ECHO)
254endif
255	$(ECHO_NOTHING)cp $(SPEC_FILE) $(RPM_TOPDIR)/SPECS/; \
256	cd $(RPM_TOPDIR)/SPECS/; \
257	if which rpmbuild > /dev/null 2>/dev/null; then \
258	  rpmbuild="rpmbuild"; \
259	else \
260	  if which rpm > /dev/null 2>/dev/null; then \
261	    rpmbuild="rpm"; \
262	  else \
263	    echo "Error: You don't have rpm installed!"; \
264	    rpmbuild="rpmbuild"; \
265	  fi; \
266	fi; \
267	$${rpmbuild} -ba $(SPEC_FILE_NAME)$(END_ECHO)
268