1 |
# |
2 |
# @(#)$Id$ |
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 |
-e '{ s/^(VERSION=\d+\.\d+\.)(\d+)(.*)$$/$$1.($$2+1).$$3/e;' \ |
64 |
-e '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 |
-e '{ s/^(VERSION=\d+\.)(\d+)(\..*)$$/$$1.($$2+1).".0"/e;' \ |
71 |
-e '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 |
-e '{ s/^(VERSION=)(\d+)(\..*)$$/$$1.($$2+1).".0.0"/e;' \ |
78 |
-e 's/^(RELEASE=)(\d+)(.*)$$/$$1."1".$$3/e; print; }' |
79 |
@$(MAKE) tagversion |
80 |
|
81 |
config.tmp: |
82 |
@cp config.mk config.tmp |
83 |
##config.tmp: config.mk |
84 |
##@cvs update . |
85 |
##@sed <config.mk >config.tmp '/^DATE=/d' |
86 |
##@echo 'DATE=$(_date)' >>config.tmp |
87 |
##@cp config.mk config.mk~ |
88 |
|
89 |
tagversion: |
90 |
@echo cvs tagging new release: $(VERSION) |
91 |
@rm -f config.tmp |
92 |
@echo Enter ChangeLog comment or hit return key: |
93 |
@perl -e '$$cl=<STDIN>; chomp($$cl); $$date=`date +%Y-%m-%d`; ' \ |
94 |
-e 'chomp($$date);' \ |
95 |
-e '$$login=getlogin();' \ |
96 |
-e '$$logstr="<unknown>";' \ |
97 |
-e '$$logstr=(getpwnam($$login))[6] if defined $$login;' \ |
98 |
-e 'print $$date." $$logstr\n\n";' \ |
99 |
-e 'print " * Release: $(VERSION)\n";' \ |
100 |
-e 'print " - ".$$cl."\n" unless ($$cl eq "");' \ |
101 |
-e 'print "\n"; ' >ChangeLog.tmp |
102 |
@if [ ! -r ChangeLog ] ; then touch ChangeLog ; cvs add ChangeLog ; fi |
103 |
@cat ChangeLog >>ChangeLog.tmp |
104 |
@mv ChangeLog.tmp ChangeLog |
105 |
@cvs commit -m "Release: $(VERSION)" |
106 |
@cvs tag -F -c `echo $(_vtag) |sed -e s/\\\./_/g -e s/-/_/g` |
107 |
@cvs tag -F -c latest |
108 |
|
109 |
#################################################################### |
110 |
# Build distributions in tar & RPM/PKG format |
111 |
#################################################################### |
112 |
# |
113 |
# These targets make distribution tar files and PKGs/RPMs from the |
114 |
# CVS repository, using the version declared in the config file. |
115 |
# The checked-out files in the current directory are neither |
116 |
# modified, nor read (apart from the config file). |
117 |
# |
118 |
# "pack" and "rpm" built from the sources in the current directory. |
119 |
# |
120 |
# |
121 |
# The prep:: target allows the including makefile to specify actions |
122 |
# required to process the files at distribution pack time. |
123 |
# |
124 |
# These targets make distribution tar files and PKGs/RPMs based on the |
125 |
# checked-out sources in the current directory. No connection to |
126 |
# the CVS repository is required, and the files do not need to be |
127 |
# committed. The RPM version numbers are generated from the |
128 |
# version number specified in the config file. |
129 |
# |
130 |
|
131 |
pack: envdir |
132 |
@echo packing distribution... |
133 |
@rm -rf $(_builddir)/$(_prodname) |
134 |
@rm -f $(_sourcedir)/$(_prodtar) |
135 |
@mkdir -p $(_builddir)/$(_prodname) |
136 |
@find . -path '*CVS*' -prune -o -type f -print >files.tmp |
137 |
@tar cfT - files.tmp |(cd $(_builddir)/$(_prodname) ; tar xf -) |
138 |
@rm -f files.tmp |
139 |
@[ ! -f specfile.spec -a -f specfile.cin ] \ |
140 |
&& cp specfile.cin \ |
141 |
$(_builddir)/$(_prodname)/specfile.spec \ |
142 |
|| : ; |
143 |
@cp cl2rpm \ |
144 |
$(_builddir)/$(_prodname)/ > /dev/null 2>&1 \ |
145 |
|| : ; |
146 |
@cd $(_builddir)/$(_prodname) ; \ |
147 |
sed <config.mk >config.tmp \ |
148 |
-e 's%^RELEASE=\(.*\)%RELEASE=\1%' \ |
149 |
-e 's%^VERSION=.*%&$(BRANCH)%' ; \ |
150 |
mv config.tmp config.mk ; \ |
151 |
echo 'TARFILE=$(_prodtar)' >>config.mk ; \ |
152 |
echo 'PROD=\#' >>config.mk ; \ |
153 |
$(MAKE) config.sh ;\ |
154 |
$(MAKE) prep ;\ |
155 |
test -n "$(_test_dep)" && rm -f $(_test_dep) ;\ |
156 |
rm -f config.sh |
157 |
@cd $(_builddir) ; tar czf $(_sourcedir)/$(_prodtar) $(_prodname) |
158 |
|
159 |
spec: pack |
160 |
@echo generating specfile.spec ... |
161 |
@cd $(_builddir)/$(_prodname) ; \ |
162 |
$(MAKE) config.sh ;\ |
163 |
./config.sh <specfile.spec >$(_specdir)/$(_prodname).spec |
164 |
@test -f ChangeLog && \ |
165 |
cl2rpm ChangeLog \ |
166 |
>>$(_specdir)/$(_prodname).spec 2>/dev/null || true |
167 |
|
168 |
rpm: spec |
169 |
@echo building rpm ... |
170 |
@cd $(_specdir) ; $(_rpmbuild) -ba $(_specdir)/$(_prodname).spec |
171 |
|
172 |
pkg: spec |
173 |
@echo building pkg ... |
174 |
@cd $(_specdir) ; $(_pkgbuild) -f $(_specdir)/$(_prodname).spec |
175 |
|
176 |
prep:: |
177 |
|
178 |
##################################################################### |
179 |
# Create substitution script |
180 |
#################################################################### |
181 |
# |
182 |
# This target reads the config file and creates a shell script which |
183 |
# can substitute variables of the form @VAR@ for all config |
184 |
# variables VAR. The messing around with the temporary makefile is |
185 |
# to ensure that any recursive or external references in the |
186 |
# variable values are evaluated by "make" in the same context as |
187 |
# when the config file is included in the makefile. |
188 |
|
189 |
config.sh: Makefile $(_test_dep) |
190 |
@cp /dev/null makefile.tmp |
191 |
@echo include config.mk >>makefile.tmp |
192 |
@echo dumpvars: >>makefile.tmp |
193 |
@cat config.mk | \ |
194 |
perl >>makefile.tmp \ |
195 |
-e 'my $$fmt = "\t\@echo \"-e \\\"s\@%s\@\$$(%s)g\\\" \\\\\"" ;' \ |
196 |
-e 'while (<>) { $$v{$$1}=1 if /^([A-Za-z0-9_]+)\s*:?=.*$$/; }' \ |
197 |
-e 'map { printf "$$fmt >>config.sh\n", $$_, $$_; } sort(keys(%v));' \ |
198 |
-e 'print "\n";' |
199 |
@echo '#!/bin/sh' >config.sh |
200 |
@echo 'sed \' >>config.sh |
201 |
@$(MAKE) -f makefile.tmp dumpvars >/dev/null |
202 |
@echo ' -e "s/\@MSG\@/ ** Generated file : do not edit **/"'>>config.sh |
203 |
@chmod oug+x config.sh |
204 |
@rm makefile.tmp |
205 |
|
206 |
#################################################################### |
207 |
# Configure |
208 |
#################################################################### |
209 |
|
210 |
%:: %.cin config.sh |
211 |
@echo configuring $@ ... |
212 |
@rm -f $@ ; cp $< $@ |
213 |
@./config.sh <$< >$@ ; chmod oug-w $@ |
214 |
|
215 |
%.$(MANSECT):: %.$(MANSECT).man.cin |
216 |
@echo creating $@ ... |
217 |
@./config.sh <$< >$@ ; chmod oug-w $@ |
218 |
|
219 |
configure: $(shell find . -name \*\.cin 2>/dev/null | sed -e 's/.cin//' || echo) |
220 |
|
221 |
default-install: |
222 |
@[ -f MAINTAINER ] && install -D -m 0644 MAINTAINER $(PREFIX)$(DOCDIR)/MAINTAINER || : |
223 |
@[ -f CHANGES ] && install -D -m 0644 CHANGES $(PREFIX)$(DOCDIR)/CHANGES || : |
224 |
@[ -f ChangeLog ] && install -D -m 0644 ChangeLog $(PREFIX)$(DOCDIR)/ChangeLog || : |
225 |
@[ -f README ] && install -D -m 0644 README $(PREFIX)$(DOCDIR)/README || : |
226 |
@[ -f INSTALL ] && install -D -m 0644 INSTALL $(PREFIX)$(DOCDIR)/INSTALL || : |
227 |
@[ -f LICENSE ] && install -D -m 0644 LICENSE $(PREFIX)$(DOCDIR)/LICENSE || : |
228 |
@[ -d doc ] && cd doc && for i in * ; do \ |
229 |
test `expr match $$i .\*\.cin\$$` -eq 0 && install -m 0444 $$i $(PREFIX)/$(DOCDIR)/$$i ; \ |
230 |
done || : |
231 |
|
232 |
|
233 |
#################################################################### |
234 |
# Install |
235 |
#################################################################### |
236 |
|
237 |
install: configure default-install |
238 |
@echo installing in $(PREFIX) ... |
239 |
# |
240 |
# modify location of installed scripts/binaries here |
241 |
# |
242 |
@mkdir -p $(PREFIX)/usr/local/lib/nagios/plugins/ |
243 |
@for i in \ |
244 |
scripts/check_* ; do \ |
245 |
install -m 0755 $$i $(PREFIX)/usr/local/lib/nagios/plugins/`basename $$i` ; \ |
246 |
done || : |
247 |
@mkdir -p $(PREFIX)/usr/local/lib/nagios/plugins/eventhandlers/ |
248 |
@for i in \ |
249 |
eventhandlers/* ; do \ |
250 |
install -m 0755 $$i $(PREFIX)/usr/local/lib/nagios/plugins/eventhandlers/`basename $$i` ; \ |
251 |
done || : |
252 |
|
253 |
#################################################################### |
254 |
|
255 |
filelist: install |
256 |
@find $(PREFIX) -type d | sed -e 's^$(PREFIX)g' -e 's/^/%dir /' >> $(FILELIST) |
257 |
@find $(PREFIX) ! -type d -a ! -name ".filelist" | sed -e 's^$(PREFIX)g' >> $(FILELIST) |
258 |
@echo Files found in distribution listing $(FILELIST) |
259 |
@cat $(FILELIST) |
260 |
|
261 |
|
262 |
clean:: |
263 |
@echo cleaning common files ... |
264 |
@rm -f config.sh config.tex |
265 |
@rm -f `find . -name '*~'` |
266 |
@rm -f `find . -name '*#'` |
267 |
@rm -f `find . -name '*.tmp'` |
268 |
|
269 |
dist: pack |
270 |
|
271 |
|
272 |
|