summaryrefslogtreecommitdiffstats
path: root/encap/src/encap-profiles/Makefile
blob: a1b1f783d312a340a2b7bf6a01aff389a2a25f40 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
# $Id$

.PHONY : test log all install clean distclean uninstall encaps rename bcfg2only bcfg2bump
.SUFFIXES :
.SUFFIXES : .ep .sh .installed .packaged .d

export BASEDIR = /usr/local
export ENCAPDIR := ${BASEDIR}/encap
export EPKG := ${BASEDIR}/bin/epkg
export MKENCAP := ${BASEDIR}/bin/mkencap
export SHELL = /bin/sh
srcdir = .
export EP2TARGET := $(srcdir)/ep2target
PAGER ?= more

BCFG2 := $(basename $(wildcard bcfg2-[0-9].[0-9]*.ep))
BCFG2_CHEETAH := $(basename $(wildcard bcfg2-cheetah-[0-9].[0-9]*.ep))
BCFG2_ELEMENTTREE := $(basename $(wildcard bcfg2-elementtree-*.ep))
BCFG2_GZIP := $(basename $(wildcard bcfg2-gzip-*.ep))
BCFG2_M2CRYPTO := $(basename $(wildcard bcfg2-m2crypto-*.ep))
BCFG2_OPENSSL := $(basename $(wildcard bcfg2-openssl-*.ep))
BCFG2_PKG_CONFIG := $(basename $(wildcard bcfg2-pkg-config-*.ep))
BCFG2_PYTHON := $(basename $(wildcard bcfg2-python-[0-9].[0-9]*.ep))
BCFG2_READLINE := $(basename $(wildcard bcfg2-readline-*.ep))
BCFG2_SETUPTOOLS := $(basename $(wildcard bcfg2-setuptools-*.ep))
BCFG2_SWIG := $(basename $(wildcard bcfg2-swig-*.ep))
BCFG2_ZLIB := $(basename $(wildcard bcfg2-zlib-*.ep))
M4 := $(basename $(wildcard m4-*.sh))
MAKESELF := $(basename $(wildcard makeself-*.ep))
OSTIARTY := $(basename $(wildcard ostiary-[0-9].[0-9]*.ep))
PATCH := $(basename $(wildcard patch-*.ep))
RUNIT := $(basename $(wildcard runit-[0-9].[0-9]*.ep))

sources_ep := $(sort $(BCFG2) $(BCFG2_CHEETAH) $(BCFG2_ELEMENTTREE) $(BCFG2_GZIP) $(BCFG2_M2CRYPTO) $(BCFG2_OPENSSL) $(BCFG2_PKG_CONFIG) $(BCFG2_PYTHON) $(BCFG2_READLINE) $(BCFG2_SETUPTOOLS) $(BCFG2_SWIG) $(BCFG2_ZLIB) $(MAKESELF) $(OSTIARTY) $(PATCH) $(RUNIT))

sources_sh := $(M4)

# Only compile bcfg2-python-apt on known Debian and Ubuntu 
# systems (as python-apt is distribution-specific)
UNAME := $(shell uname)

ifeq ($(UNAME),Linux)
DISTRO := $(shell cat /etc/issue | grep ^[a-zA-Z] | head -1)
endif

ifeq ($(DISTRO),Debian GNU/Linux 3.1 \n \l)
BCFG2_PYTHON_APT = bcfg2-python-apt-0.5.10
OS ?= linux_debian_sarge
endif

ifeq ($(DISTRO),Debian GNU/Linux 4.0 \n \l)
BCFG2_PYTHON_APT = bcfg2-python-apt-0.6.19
OS ?= linux_debian_etch
endif

ifeq ($(DISTRO),Debian GNU/Linux testing/unstable \n \l)
BCFG2_PYTHON_APT = bcfg2-python-apt-0.6.19
OS ?= linux_debian_sid
endif

ifeq ($(DISTRO),Ubuntu 6.06.1 LTS \n \l)
BCFG2_PYTHON_APT = bcfg2-python-apt-0.6.16.2ubuntu8
OS ?= linux_ubuntu_dapper
endif

ifeq ($(DISTRO),Red Hat Linux release 6.0 (Hedwig))
OS ?= linux_redhat_60
endif

ifeq ($(DISTRO),Red Hat Linux release 7.2 (Enigma))
OS ?= linux_redhat_72
endif

ifeq ($(DISTRO),Red Hat Enterprise Linux AS release 4 (Nahant Update 4))
OS ?= linux_redhat_rhel4
endif

ifeq ($(DISTRO),Red Hat Enterprise Linux AS release 4 (Nahant Update 5))
OS ?= linux_redhat_rhel4
endif

ifeq ($(DISTRO),Welcome to SuSE SLES 8 (powered by UnitedLinux 1.0) (i586))
OS ?= linux_suse_sles8
endif

ifeq ($(DISTRO),Welcome to SUSE Linux Enterprise Server 10 (i586) - Kernel \r (\l).)
OS ?= linux_suse_sles10
endif

ifeq ($(DISTRO),Welcome to SUSE Linux Enterprise Server 10 (x86_64) - Kernel \r (\l).)
OS ?= linux_suse_sles10
endif

ifdef BCFG2_PYTHON_APT
sources_ep += $(BCFG2_PYTHON_APT)
endif

# List of all sources...
sources := $(sort $(sources_ep) $(sources_sh))

%.installed : %.ep # Clean, compile and install an encap package
	@printf "***** START .ep.installed for |$*| ***** \n"
	-$(EPKG) -q -r $(ENCAPDIR)/$*
	-rm -rf $(ENCAPDIR)/$*
	-$(MKENCAP) -m /usr/local/bin/m4 -b -DUP $(srcdir)/$*.ep > ./$*.log 2>&1
	-$(MKENCAP) -m /usr/local/bin/m4 -b -T $(srcdir)/$*.ep >> ./$*.log 2>&1
	$(MKENCAP) -m /usr/local/bin/m4 -b -CBI $(srcdir)/$*.ep >> ./$*.log 2>&1
	$(EPKG) -q -i $(ENCAPDIR)/$*
	test -h $(BASEDIR)/var/encap/$*
	touch ./$*.installed
	@printf "***** STOP .ep.installed for |$*| ***** \n"

%.installed : %.sh # Create and install a "fake" encap package
	@printf "***** START .sh.installed for |$*| ***** \n"
	-$(EPKG) -q -r $(ENCAPDIR)/$*
	-rm -rf $(ENCAPDIR)/$*
	chmod 755 $(srcdir)/$*.sh && $(srcdir)/$*.sh
	$(EPKG) -q -i $(ENCAPDIR)/$*
	test -h $(BASEDIR)/var/encap/$*
	touch ./$*.installed
	@printf "***** STOP .sh.installed for |$*| ***** \n"

%.packaged : %.installed # Create .tar.gz encap packages
	@printf "***** START .installed.packaged for |$*| ***** \n"
	-rm $(ENCAPDIR)/$*-*.tar.gz
	-(cd $(ENCAPDIR) && $(MKENCAP) -e $*)
	-(cd $(ENCAPDIR) && $(MKENCAP) -c $*)
	mv $(ENCAPDIR)/$*-encap-*.tar.gz ./
	touch ./$*.packaged
	@printf "***** STOP .installed.packaged for |$*| ***** \n"

%.d : %.ep # Create dependancy files from .ep files
	@printf "***** START .d.ep for |$*| ***** \n"
	chmod 755 $(EP2TARGET) && $(EP2TARGET) $< > $@
	@printf "***** STOP .d.ep for |$*| ***** \n"

%.d : %.sh # Create dependancy files from .sh files
	@printf "***** START .d.sh for |$*| ***** \n"
	chmod 755 $(EP2TARGET) && $(EP2TARGET) $< > $@
	@printf "***** STOP .d.sh for |$*| ***** \n"

log :
	( $(MAKE) install > ./make.log 2>&1 \
	&& $(MAKE) encaps >> ./make.log 2>&1 \
	&& $(MAKE) rename >> ./make.log 2>&1 ) &

all : install encaps rename

.DELETE_ON_ERROR : # delete the target of a rule if it has changed and its
                   # commands exit with a nonzero exit status

install : $(EPKG) $(MKENCAP) $(EP2TARGET) $(M4).installed $(addsuffix .installed,$(sources))

encaps : $(EPKG) $(MKENCAP) $(EP2TARGET) $(addsuffix .packaged,$(sources))

rename : encaps
	if [ "$(OS)x" != "x" ]; then OS="$(OS)"; fi && \
	if [ "$${OS}x" != "x" ]; then \
		for OLDNAME in `(ls . | grep .*-encap-.*.tar.gz) || break`; do \
			NEWNAME="`printf "%s\n" "$${OLDNAME}" \
				| awk -F- '{$$NF = "OSDIST.tar.gz" ; print}' \
				| sed s:\ :-:g | sed s:OSDIST:\$${OS}:g`" ; \
			if [ "$${OLDNAME}x" != "$${NEWNAME}x" ]; then \
				mv ./$${OLDNAME} ./$${NEWNAME}; \
			fi; \
		done; \
	fi	
	for OLDNAME in `(ls . | grep .*-doc-.*-encap-.*.tar.gz) || break`; do \
		NEWNAME="`printf "%s\n" "$${OLDNAME}" \
			| awk -F- '{$$NF = "OSDIST.tar.gz" ; print}' \
			| sed s:\ :-:g | sed s:OSDIST:share:g`" ; \
		if [ "$${OLDNAME}x" != "$${NEWNAME}x" ]; then \
			mv ./$${OLDNAME} ./$${NEWNAME}; \
		fi; \
	done

clean :
	-(rm ./*.log; rm ./*.packaged; rm ./*.gz; rm ./*~)

distclean : clean
	-rm ./*.d

uninstall : distclean
	-(find $(BASEDIR)/lib/bcfg2 | grep "\.pyc" | xargs -n1 rm)
	-(ENCAPS="m4 patch runit makeself ostiary bcfg2"; \
	for ENCAP in $${ENCAPS}; do \
		$(EPKG) -q -r $(ENCAPDIR)/$${ENCAP}-*; \
		rm -rf $(ENCAPDIR)/$${ENCAP}-*; \
		rm ./$${ENCAP}-*.installed; \
	done)
	-rm -rf  $(BASEDIR)/lib/bcfg2

bcfg2only :
	$(MAKE) -t; sleep 2; touch $(srcdir)/$(BCFG2).ep; $(MAKE)

bcfg2bump :
	@if [ "$(NEW)x" != "x" ]; then NEW="$(NEW)"; fi && \
	if [ "$(OLD)x" != "x" ]; then OLD="$(OLD)"; fi && \
	if [ "$(FORCE)x" != "x" ]; then FORCE="$(FORCE)"; fi && \
	if [ "$${OLD}x" != "x" -a "$${NEW}x" != "x" ]; then \
	OLDBASE="`printf "%s\n" "$${OLD}" | sed 's:\.ep::g'`"; \
	NEWBASE="`printf "%s\n" "$${NEW}" | sed 's:\.ep::g'`"; \
		if [ "$${FORCE}x" != "yesmamx" ]; then \
			printf "About to 'svn mv %s %s'\n" "$$OLD" "$$NEW"; \
			printf "\tand edit the later as appropriate.\n"; \
			printf "And then 'rm %s%s'...\n" "$$OLDBASE" ".*"; \
			printf "Press 'return' to continue, or 'ctrl-c' to exit. "; \
			read THROWAWAY; \
		fi; \
		svn mv $${OLD} $${NEW} && \
		sed s:$${OLDBASE}:$${NEWBASE}:g $${NEW} > $${NEW}.tmp && \
		mv $${NEW}.tmp $${NEW} && \
		rm $${OLDBASE}.*; \
		printf "Changes to %s are:\n" "$${NEW}"; \
		if [ "$${FORCE}x" != "yesmamx" ]; then \
			svn diff $${NEW} | $(PAGER); \
			printf "'svn commit %s %s -m \"EncapPackages: Bumped bcfg2 .ep version to %s\"'? \n" "$${OLD}" "$${NEW}" "$${NEW}"; \
			printf "Press 'return' to commit, or 'ctrl-c' to exit. "; \
			read THROWAWAY; \
		else \
			svn diff $${NEW}; \
		fi; \
		svn commit $${OLD} $${NEW} -m "EncapPackages: Bumped bcfg2 .ep version to $${NEW}"; \
	else \
		printf "Set the OLD, NEW (and optionally FORCE) environment "; \
		printf "variables. Example:\n"; \
		printf "\tOLD=bcfg2-0.8.3pre5.ep NEW=bcfg2-0.8.3.ep $(MAKE) bcfg2bump\n";\
	fi

include $(addsuffix .d,$(sources))