1 |
# |
2 |
# @(#)$Id: Makefile,v 1.1 2008/02/05 16:58:12 davidg Exp $ |
3 |
# |
4 |
|
5 |
.PHONY: release minorversion majorversion tagversion |
6 |
.PHONY: pack rpm pkg prep clean dist userdoc apidoc check |
7 |
|
8 |
_os := $(shell uname -s) |
9 |
_date := $(shell date '+%d/%m/%y %H:%M') |
10 |
|
11 |
####################################################### |
12 |
# |
13 |
# General settings |
14 |
# |
15 |
####################################################### |
16 |
|
17 |
#################################################################### |
18 |
# Linux specific settings |
19 |
#################################################################### |
20 |
# |
21 |
# |
22 |
|
23 |
_rpmbuild := $(shell [ -x /usr/bin/rpmbuild ] && echo rpmbuild || echo rpm) |
24 |
_builddir := $(shell rpm --eval %_builddir) |
25 |
_specdir := $(shell rpm --eval %_specdir) |
26 |
_sourcedir := $(shell rpm --eval %_sourcedir) |
27 |
_srcrpmdir := $(shell rpm --eval %_srcrpmdir) |
28 |
_rpmdir := $(shell rpm --eval %_rpmdir) |
29 |
|
30 |
|
31 |
include config.mk |
32 |
_module = $(NAME) |
33 |
_vpfx = $(NAME)_ |
34 |
_vtag = $(subst -,_,$(subst .,_,$(_vpfx)$(VERSION)$(BRANCH))) |
35 |
_prodname = $(NAME)-$(VERSION)$(BRANCH) |
36 |
_prodtar = $(_prodname).src.tgz |
37 |
|
38 |
|
39 |
################################################################### |
40 |
# Create linux specific build directories |
41 |
################################################################### |
42 |
|
43 |
envdir:: $(_srcrpmdir) $(_rpmdir) |
44 |
$(_srcrpmdir): |
45 |
mkdir -p $(_srcrpmdir) |
46 |
$(_rpmdir): |
47 |
mkdir -p $(_rpmdir) |
48 |
|
49 |
#################################################################### |
50 |
# Create new release/version/majorversion |
51 |
#################################################################### |
52 |
# |
53 |
# These targets update the X.Y.Z components of the version in the |
54 |
# config file and then commit the current version, tagging all |
55 |
# files with the release number from the config file. Also |
56 |
# wires the current date and time into the config file. Also |
57 |
# adds an entry to the ChangeLog. |
58 |
|
59 |
|
60 |
release: config.tmp |
61 |
@echo 'increasing release number x.x.<X> and timestamp..' |
62 |
@perl <config.tmp >config.mk -e 'while (<>) \ |
63 |
{ s/^(VERSION=\d+\.\d+\.)(\d+)(.*)$$/$$1.($$2+1).$$3/e; \ |
64 |
s/^(RELEASE=)(\d+)(.*)$$/$$1."1".$$3/e; print; }' |
65 |
@$(MAKE) tagversion |
66 |
|
67 |
minorversion: config.tmp |
68 |
@echo 'increasing minorversion number x.<X>.x and timestamp..' |
69 |
@perl <config.tmp >config.mk -e 'while (<>) \ |
70 |
{ s/^(VERSION=\d+\.)(\d+)(\..*)$$/$$1.($$2+1).".0"/e; \ |
71 |
s/^(RELEASE=)(\d+)(.*)$$/$$1."1".$$3/e; print; }' |
72 |
@$(MAKE) tagversion |
73 |
|
74 |
majorversion: config.tmp |
75 |
@echo 'increasing majorversion number <X>.x.x and timestamp..' |
76 |
@perl <config.tmp >config.mk -e 'while (<>) \ |
77 |
{ s/^(VERSION=)(\d+)(\..*)$$/$$1.($$2+1).".0.0"/e; \ |
78 |
s/^(RELEASE=)(\d+)(.*)$$/$$1."1".$$3/e; print; }' |
79 |
@$(MAKE) tagversion |
80 |
|
81 |
config.tmp: config.mk |
82 |
@cvs update . |
83 |
@sed <config.mk >config.tmp '/^DATE=/d' |
84 |
@echo 'DATE=$(_date)' >>config.tmp |
85 |
@cp config.mk config.mk~ |
86 |
|
87 |
tagversion: |
88 |
@echo cvs tagging new release: $(VERSION) |
89 |
@rm -f config.tmp |
90 |
@echo Enter ChangeLog comment or hit return key: |
91 |
@perl -e '$$cl=<STDIN>; chomp($$cl); $$date=`date +%Y-%m-%d`; \ |
92 |
chomp($$date); \ |
93 |
$$login=getlogin(); \ |
94 |
$$logstr="<unknown>"; \ |
95 |
$$logstr=(getpwnam($$login))[6] if defined $$login; \ |
96 |
print $$date." $$logstr\n\n"; \ |
97 |
print " * Release: $(VERSION)\n"; \ |
98 |
print " - ".$$cl."\n" unless ($$cl eq ""); \ |
99 |
print "\n"; ' >ChangeLog.tmp |
100 |
@if [ ! -r ChangeLog ] ; then touch ChangeLog ; cvs add ChangeLog ; fi |
101 |
@cat ChangeLog >>ChangeLog.tmp |
102 |
@mv ChangeLog.tmp ChangeLog |
103 |
@cvs commit -m "Release: $(VERSION)" |
104 |
@cvs tag -F -c `echo $(_vtag) |sed -e s/\\\./_/g -e s/-/_/g` |
105 |
@cvs tag -F -c latest |
106 |
|
107 |
#################################################################### |
108 |
# Build distributions in tar & RPM/PKG format |
109 |
#################################################################### |
110 |
# |
111 |
# These targets make distribution tar files and PKGs/RPMs from the |
112 |
# CVS repository, using the version declared in the config file. |
113 |
# The checked-out files in the current directory are neither |
114 |
# modified, nor read (apart from the config file). |
115 |
# |
116 |
# "pack" and "rpm" built from the sources in the current directory. |
117 |
# |
118 |
# |
119 |
# The prep:: target allows the including makefile to specify actions |
120 |
# required to process the files at distribution pack time. |
121 |
# |
122 |
# These targets make distribution tar files and PKGs/RPMs based on the |
123 |
# checked-out sources in the current directory. No connection to |
124 |
# the CVS repository is required, and the files do not need to be |
125 |
# committed. The RPM version numbers are generated from the |
126 |
# version number specified in the config file. |
127 |
# |
128 |
|
129 |
pack: envdir |
130 |
@echo packing distribution... |
131 |
@rm -rf $(_builddir)/$(_prodname) |
132 |
@rm -f $(_sourcedir)/$(_prodtar) |
133 |
@mkdir -p $(_builddir)/$(_prodname) |
134 |
@find . -path '*CVS*' -prune -o -type f -print >files.tmp |
135 |
@tar cfT - files.tmp |(cd $(_builddir)/$(_prodname) ; tar xf -) |
136 |
@rm -f files.tmp |
137 |
@[ ! -f specfile.spec -a -f specfile.cin ] \ |
138 |
&& cp specfile.cin \ |
139 |
$(_builddir)/$(_prodname)/specfile.spec \ |
140 |
|| : ; |
141 |
@cp cl2rpm \ |
142 |
$(_builddir)/$(_prodname)/ > /dev/null 2>&1 \ |
143 |
|| : ; |
144 |
@cd $(_builddir)/$(_prodname) ; \ |
145 |
sed <config.mk >config.tmp \ |
146 |
-e 's%^RELEASE=\(.*\)%RELEASE=\1%' \ |
147 |
-e 's%^VERSION=.*%&$(BRANCH)%' ; \ |
148 |
mv config.tmp config.mk ; \ |
149 |
echo 'TARFILE=$(_prodtar)' >>config.mk ; \ |
150 |
echo 'PROD=\#' >>config.mk ; \ |
151 |
$(MAKE) config.sh ;\ |
152 |
$(MAKE) prep ;\ |
153 |
test -n "$(_test_dep)" && rm -f $(_test_dep) ;\ |
154 |
rm -f config.sh |
155 |
@cd $(_builddir) ; tar czf $(_sourcedir)/$(_prodtar) $(_prodname) |
156 |
@cp -p $(_sourcedir)/$(_prodtar) . |
157 |
|
158 |
spec: pack |
159 |
@echo generating specfile.spec ... |
160 |
@cd $(_builddir)/$(_prodname) ; \ |
161 |
$(MAKE) config.sh ;\ |
162 |
./config.sh <specfile.spec >$(_specdir)/$(_prodname).spec |
163 |
@test -f ChangeLog && \ |
164 |
cl2rpm ChangeLog \ |
165 |
>>$(_specdir)/$(_prodname).spec 2>/dev/null || true |
166 |
|
167 |
rpm: spec |
168 |
@echo building rpm ... |
169 |
@cd $(_specdir) ; $(_rpmbuild) -ba $(_specdir)/$(_prodname).spec |
170 |
@if [ -f $(_srcrpmdir)/$(_prodname)-$(RELEASE).src.rpm ] ; then \ |
171 |
mv $(_srcrpmdir)/$(_prodname)-$(RELEASE).src.rpm . ; \ |
172 |
fi |
173 |
@if [ -f $(_rpmdir)/i386/$(_prodname)-$(RELEASE).i386.rpm ] ; then \ |
174 |
mv $(_rpmdir)/i386/$(_prodname)-$(RELEASE).i386.rpm . ; \ |
175 |
fi |
176 |
@if [ -f $(_rpmdir)/i686/$(_prodname)-$(RELEASE).i686.rpm ] ; then \ |
177 |
mv $(_rpmdir)/i686/$(_prodname)-$(RELEASE).i686.rpm . ; \ |
178 |
fi |
179 |
@if [ -f $(_rpmdir)/x86_64/$(_prodname)-$(RELEASE).x86_64.rpm ] ; then \ |
180 |
mv $(_rpmdir)/x86_64/$(_prodname)-$(RELEASE).x86_64.rpm . ; \ |
181 |
fi |
182 |
@if [ -f $(_rpmdir)/athlon/$(_prodname)-$(RELEASE).athlon.rpm ] ; then \ |
183 |
mv $(_rpmdir)/athlon/$(_prodname)-$(RELEASE).athlon.rpm . ; \ |
184 |
fi |
185 |
@if [ -f $(_rpmdir)/ia64/$(_prodname)-$(RELEASE).ia64.rpm ] ; then \ |
186 |
mv $(_rpmdir)/ia64/$(_prodname)-$(RELEASE).ia64.rpm . ; \ |
187 |
fi |
188 |
@if [ -f $(_rpmdir)/noarch/$(_prodname)-$(RELEASE).noarch.rpm ] ; then \ |
189 |
mv $(_rpmdir)/noarch/$(_prodname)-$(RELEASE).noarch.rpm . ; \ |
190 |
fi |
191 |
|
192 |
pkg: spec |
193 |
@echo building pkg ... |
194 |
@cd $(_specdir) ; $(_pkgbuild) -f $(_specdir)/$(_prodname).spec |
195 |
|
196 |
prep:: |
197 |
|
198 |
##################################################################### |
199 |
# Create substitution script |
200 |
#################################################################### |
201 |
# |
202 |
# This target reads the config file and creates a shell script which |
203 |
# can substitute variables of the form @VAR@ for all config |
204 |
# variables VAR. The messing around with the temporary makefile is |
205 |
# to ensure that any recursive or external references in the |
206 |
# variable values are evaluated by "make" in the same context as |
207 |
# when the config file is included in the makefile. |
208 |
|
209 |
config.sh: Makefile $(_test_dep) |
210 |
@cp /dev/null makefile.tmp |
211 |
@echo include config.mk >>makefile.tmp |
212 |
@echo dumpvars: >>makefile.tmp |
213 |
@cat config.mk | \ |
214 |
perl >>makefile.tmp -e ' \ |
215 |
my $$fmt = "\t\@echo \"-e \\\"s\@%s\@\$$(%s)g\\\" \\\\\"" ; \ |
216 |
while (<>) { $$v{$$1}=1 if /^([A-Za-z0-9_]+)\s*:?=.*$$/; } \ |
217 |
map { printf "$$fmt >>config.sh\n", $$_, $$_; } sort(keys(%v)); \ |
218 |
print "\n"; \ |
219 |
' |
220 |
@echo '#!/bin/sh' >config.sh |
221 |
@echo 'sed \' >>config.sh |
222 |
@$(MAKE) -f makefile.tmp dumpvars >/dev/null |
223 |
@echo ' -e "s/\@MSG\@/ ** Generated file : do not edit **/"'>>config.sh |
224 |
@chmod oug+x config.sh |
225 |
@rm makefile.tmp |
226 |
|
227 |
#################################################################### |
228 |
# Configure |
229 |
#################################################################### |
230 |
|
231 |
%:: %.cin config.sh |
232 |
@echo configuring $@ ... |
233 |
@rm -f $@ ; cp $< $@ |
234 |
@./config.sh <$< >$@ ; chmod oug-w $@ |
235 |
|
236 |
%.$(MANSECT):: %.$(MANSECT).man.cin |
237 |
@echo creating $@ ... |
238 |
@./config.sh <$< >$@ ; chmod oug-w $@ |
239 |
|
240 |
configure: $(shell find . -name \*\.cin 2>/dev/null | sed -e 's/.cin//' || echo) |
241 |
|
242 |
default-install: |
243 |
@[ -f MAINTAINER ] && install -D -m 0644 MAINTAINER $(PREFIX)$(DOCDIR)/MAINTAINER || : |
244 |
@[ -f CHANGES ] && install -D -m 0644 CHANGES $(PREFIX)$(DOCDIR)/CHANGES || : |
245 |
@[ -f ChangeLog ] && install -D -m 0644 ChangeLog $(PREFIX)$(DOCDIR)/ChangeLog || : |
246 |
@[ -f README ] && install -D -m 0644 README $(PREFIX)$(DOCDIR)/README || : |
247 |
@[ -f INSTALL ] && install -D -m 0644 INSTALL $(PREFIX)$(DOCDIR)/INSTALL || : |
248 |
@[ -f LICENSE ] && install -D -m 0644 LICENSE $(PREFIX)$(DOCDIR)/LICENSE || : |
249 |
@[ -d doc ] && cd doc && for i in * ; do \ |
250 |
test `expr match $$i .\*\.cin\$$` -eq 0 && install -m 0444 $$i $(PREFIX)/$(DOCDIR)/$$i ; \ |
251 |
done || : |
252 |
|
253 |
|
254 |
#################################################################### |
255 |
# Install |
256 |
#################################################################### |
257 |
|
258 |
install: configure default-install |
259 |
@echo installing in $(PREFIX) ... |
260 |
# |
261 |
# MODIFY location of installed scripts/binaries here |
262 |
# |
263 |
@mkdir -p $(PREFIX)/$(BINDIR) |
264 |
install -m 0755 lvrasize $(PREFIX)/$(BINDIR)/lvrasize |
265 |
|
266 |
#################################################################### |
267 |
|
268 |
filelist: install |
269 |
@find $(PREFIX) -type d | sed -e 's^$(PREFIX)g' -e 's/^/%dir /' >> $(FILELIST) |
270 |
@find $(PREFIX) ! -type d -a ! -name ".filelist" | sed -e 's^$(PREFIX)g' >> $(FILELIST) |
271 |
@echo Files found in distribution listing $(FILELIST) |
272 |
@cat $(FILELIST) |
273 |
|
274 |
|
275 |
clean:: |
276 |
@echo cleaning common files ... |
277 |
@rm -f config.sh config.tex |
278 |
@rm -f `find . -name '*~'` |
279 |
@rm -f `find . -name '*#'` |
280 |
@rm -f `find . -name '*.tmp'` |
281 |
@rm -f $(_prodtar) |
282 |
@rm -f `find . -name '$(_prodname)-$(RELEASE).*.rpm'` |
283 |
|
284 |
dist: pack |
285 |
|
286 |
|
287 |
|