aboutsummaryrefslogtreecommitdiffstats
path: root/Makefile
blob: c3cba553bf726d30bf2a09319ea88214c20140d0 (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
#
# Grand Unified Makefile for Xen.
#

INSTALL_DIR ?= $(shell pwd)/install

SOURCEFORGE_MIRROR := http://heanet.dl.sourceforge.net/sourceforge
#http://voxel.dl.sourceforge.net/sourceforge/
#http://easynews.dl.sourceforge.net/sourceforge

.PHONY: docs delete-symlinks clean

# a not partcularly useful but safe default target
all: make-symlinks
	$(MAKE) prefix=$(INSTALL_DIR) dist=yes -C xen install
	$(MAKE) prefix=$(INSTALL_DIR) dist=yes -C tools install

# install everything into the standard system directories
install: dist
	$(MAKE) -C xen install
	$(MAKE) -C tools install
	$(shell cp -a install/boot/*$(LINUX_VER)* /boot/)
	$(shell cp -a install/lib/modules/* /lib/modules/)

# install xen and tools into the install directory
dist: all
	$(MAKE) linux-xenU
	$(MAKE) linux-xen0

LINUX_RELEASE    ?= 2.6
LINUX_VER        ?= $(shell ( /bin/ls -ld linux-$(LINUX_RELEASE).*-xen-sparse ) 2>/dev/null | \
		      sed -e 's!^.*linux-\(.\+\)-xen-sparse!\1!' )
LINUX26_VER      ?= $(shell ( /bin/ls -ld linux-2.6.*-xen-sparse ) 2>/dev/null | \
		      sed -e 's!^.*linux-\(.\+\)-xen-sparse!\1!' )
LINUX_CONFIG_DIR ?= $(INSTALL_DIR)/boot
LINUX_SRC_PATH   ?= .:..
LINUX_SRC        ?= $(firstword $(foreach dir,$(subst :, ,$(LINUX_SRC_PATH)),\
                    $(wildcard $(dir)/linux-$(LINUX_VER).tar.*z*)))

# search for a pristine kernel tar ball, or try downloading one
pristine-linux-src: 
ifeq ($(LINUX_SRC),)
	@echo "Cannot find linux-$(LINUX_VER).tar.gz in path $(LINUX_SRC_PATH)"
	@wget http://www.kernel.org/pub/linux/kernel/v$(LINUX_RELEASE)/linux-$(LINUX_VER).tar.bz2 -O./linux-$(LINUX_VER).tar.bz2
LINUX_SRC := ./linux-$(LINUX_VER).tar.bz2 
endif

patches/ebtables.diff:
	mkdir -p patches
	#wget $(SOURCEFORGE_MIRROR)/ebtables/ebtables-brnf-5_vs_2.4.25.diff.gz \
	     -O- | gunzip -c > $@
	wget http://www.cl.cam.ac.uk/netos/xen/downloads/ebtables-brnf-5_vs_2.4.27.diff.gz -O- | gunzip -c > $@

LINUX_TREES := linux-$(LINUX_VER)-xen0 linux-$(LINUX_VER)-xenU

# make a linux-xen build tree from a pristine kernel plus sparse tree
ifeq ($(LINUX_RELEASE),2.4)
mk-linux-trees: patches/ebtables.diff pristine-linux-src 
	$(RM) -rf $(LINUX_TREES)
	echo $(LINUX_SRC) | grep -q bz2 && \
	    tar -jxf $(LINUX_SRC) || tar -zxf $(LINUX_SRC)
	mv linux-$(LINUX_VER) linux-$(LINUX_VER)-xen0
	( cd linux-$(LINUX_VER)-xen-sparse ; \
          ./mkbuildtree ../linux-$(LINUX_VER)-xen0 )
	cp -al linux-$(LINUX_VER)-xen0 linux-$(LINUX_VER)-xenU
	( cd linux-$(LINUX_VER)-xen0 ; \
          patch -p1 -F3 < ../patches/ebtables.diff )
else
mk-linux-trees: pristine-linux-src 
	$(RM) -rf $(LINUX_TREES)
	echo $(LINUX_SRC) | grep -q bz2 && \
	    tar -jxf $(LINUX_SRC) || tar -zxf $(LINUX_SRC)
	mv linux-$(LINUX_VER) linux-$(LINUX_VER)-xen0
	( cd linux-$(LINUX_VER)-xen-sparse ; \
          ./mkbuildtree ../linux-$(LINUX_VER)-xen0 )
	cp -al linux-$(LINUX_VER)-xen0 linux-$(LINUX_VER)-xenU
endif

# configure the specified linux tree
CDIR = $(subst config-,linux-$(LINUX_VER)-,$@)
ifeq ($(LINUX_RELEASE),2.4)
config-xen%:
	$(MAKE) -C $(CDIR) ARCH=xen mrproper
	cp $(LINUX_CONFIG_DIR)/config-$(LINUX_VER)-$(subst config-,,$@) \
	    $(CDIR)/.config || \
	    $(MAKE) -C $(CDIR) ARCH=xen $(subst config-,,$@)_config
	$(MAKE) -C $(CDIR) ARCH=xen oldconfig
	$(MAKE) -C $(CDIR) ARCH=xen dep
else
config-xen%:
	$(MAKE) -C $(CDIR) ARCH=xen mrproper
	@[ -e $(LINUX_CONFIG_DIR)/config-$(LINUX_VER)-$(subst config-,,$@) ] \
	  && cp $(LINUX_CONFIG_DIR)/config-$(LINUX_VER)-$(subst config-,,$@) \
		$(CDIR)/.config || \
	$(MAKE) -C $(CDIR) ARCH=xen $(subst config-,,$@)_defconfig
endif

# build the specified linux tree
BDIR = $(subst linux-,linux-$(LINUX_VER)-,$@)
linux-xen%:	
	$(MAKE) -C $(BDIR) ARCH=xen modules
	$(MAKE) -C $(BDIR) ARCH=xen INSTALL_MOD_PATH=$(INSTALL_DIR) \
	    modules_install
	$(MAKE) -C $(BDIR) ARCH=xen INSTALL_PATH=$(INSTALL_DIR) install


NETBSD_RELEASE   ?= 2.0
NETBSD_VER       ?= $(shell ( /bin/ls -ld netbsd-$(NETBSD_RELEASE)*-xen-sparse ) 2>/dev/null | \
		      sed -e 's!^.*netbsd-\(.\+\)-xen-sparse!\1!' )
NETBSD_CVSSNAP   ?= 20040906
NETBSD_SRC_PATH  ?= .:..
NETBSD_SRC       ?= $(firstword $(foreach dir,$(subst :, ,$(NETBSD_SRC_PATH)),\
                    $(wildcard $(dir)/netbsd-$(NETBSD_VER)-xen-kernel-$(NETBSD_CVSSNAP).tar.*z*)))
NETBSD_TOOLS_SRC ?= $(firstword $(foreach dir,$(subst :, ,$(NETBSD_SRC_PATH)),\
                    $(wildcard $(dir)/netbsd-$(NETBSD_VER)-tools.tar.*z*)))

NETBSD_TREES := netbsd-$(NETBSD_VER)-xenU

pristine-netbsd-src: 
ifeq ($(NETBSD_SRC),)
	@echo "Cannot find netbsd-$(NETBSD_VER)-xen-kernel-$(NETBSD_CVSSNAP).tar.gz in path $(NETBSD_SRC_PATH)"
	@wget http://www.cl.cam.ac.uk/Research/SRG/netos/xen/downloads/netbsd-$(NETBSD_VER)-xen-kernel-$(NETBSD_CVSSNAP).tar.bz2 -O./netbsd-$(NETBSD_VER)-xen-kernel-$(NETBSD_CVSSNAP).tar.bz2
NETBSD_SRC := ./netbsd-$(NETBSD_VER)-xen-kernel-$(NETBSD_CVSSNAP).tar.bz2 
endif

pristine-netbsd-tools-src: 
ifeq ($(NETBSD_TOOLS_SRC),)
	@echo "Cannot find netbsd-$(NETBSD_VER)-tools.tar.gz in path $(NETBSD_SRC_PATH)"
	@wget http://www.cl.cam.ac.uk/Research/SRG/netos/xen/downloads/netbsd-$(NETBSD_VER)-tools.tar.bz2 -O./netbsd-$(NETBSD_VER)-tools.tar.bz2
NETBSD_TOOLS_SRC := ./netbsd-$(NETBSD_VER)-tools.tar.bz2 
endif

netbsd-tools: pristine-netbsd-tools-src
	@[ -d netbsd-$(NETBSD_RELEASE)-tools ] || { \
		echo extract $(NETBSD_TOOLS_SRC); \
		tar -jxf $(NETBSD_TOOLS_SRC); }

mk-netbsd-trees: netbsd-tools pristine-netbsd-src 
	$(RM) -rf $(NETBSD_TREES)
	echo $(NETBSD_SRC) | grep -q bz2 && \
	    tar -jxf $(NETBSD_SRC) || tar -zxf $(NETBSD_SRC)
	mv netbsd-$(NETBSD_VER)-xen-kernel-$(NETBSD_CVSSNAP) \
	    netbsd-$(NETBSD_VER)-xenU
	( cd netbsd-$(NETBSD_VER)-xen-sparse ; \
          ./mkbuildtree ../netbsd-$(NETBSD_VER)-xenU )

# build the specified netbsd tree
NBDIR = $(subst netbsd-,netbsd-$(NETBSD_VER)-,$@)
netbsd-xen%:	
	$(MAKE) -C $(NBDIR) config
	$(MAKE) -C $(NBDIR) netbsd
	$(MAKE) -C $(NBDIR) INSTALL_PATH=$(INSTALL_DIR) INSTALL_NAME=boot/netbsd-$(NETBSD_VER)-$(subst netbsd-,,$@) install

# build xen, the tools, and a domain 0 plus unprivileged linux-xen images,
# and place them in the install directory. 'make install' should then
# copy them to the normal system directories
world:
	$(MAKE) clean
	$(MAKE) all
	$(MAKE) mk-linux-trees
	$(MAKE) config-xenU
	$(MAKE) linux-xenU
	$(MAKE) config-xen0
	$(MAKE) linux-xen0
	$(MAKE) docs

linux26:
	$(MAKE) LINUX_RELEASE=2.6 mk-linux-trees
	$(MAKE) LINUX_RELEASE=2.6 config-xenU
	$(MAKE) LINUX_RELEASE=2.6 linux-xenU
	$(MAKE) LINUX_RELEASE=2.6 config-xen0
	$(MAKE) LINUX_RELEASE=2.6 linux-xen0

linux24:
	$(MAKE) LINUX_RELEASE=2.4 mk-linux-trees
	$(MAKE) LINUX_RELEASE=2.4 config-xenU
	$(MAKE) LINUX_RELEASE=2.4 linux-xenU
	$(MAKE) LINUX_RELEASE=2.4 config-xen0
	$(MAKE) LINUX_RELEASE=2.4 linux-xen0

netbsd:
	$(MAKE) mk-netbsd-trees
	$(MAKE) netbsd-xenU

clean: delete-symlinks
	$(MAKE) -C xen clean
	$(MAKE) -C tools clean
	$(MAKE) -C docs clean

# clean, but blow away linux build tree plus src tar ball
mrproper: clean
	rm -rf install/* patches $(LINUX_TREES) linux-$(LINUX_VER).tar.*

make-symlinks: delete-symlinks
	ln -sf linux-$(LINUX26_VER)-xen-sparse linux-xen-sparse

delete-symlinks:
	$(RM) linux-xen-sparse

# handy target to install twisted (use rpm or apt-get in preference)
install-twisted:
	wget http://www.twistedmatrix.com/products/get-current.epy
	tar -zxf Twisted-*.tar.gz
	( cd Twisted-* ; python setup.py install )

install-logging: LOGGING=logging-0.4.9.2
install-logging:
	[ -f $(LOGGING).tar.gz ] || wget http://www.red-dove.com/$(LOGGING).tar.gz
	tar -zxf $(LOGGING).tar.gz
	( cd $(LOGGING) && python setup.py install )

# handy target to upgrade iptables (use rpm or apt-get in preference)
install-iptables:
	wget http://www.netfilter.org/files/iptables-1.2.11.tar.bz2
	tar -jxf iptables-*.tar.bz2
	( cd iptables-* ; \
	  make PREFIX= KERNEL_DIR=../linux-$(LINUX_VER)-xen0 install)

uninstall:
	cp -a /etc/xen /etc/xen.old && rm -rf /etc/xen 
	rm -rf "/usr/lib/python2.2/site-packages/xen* /usr/lib/libxc* /usr/lib/python2.2/site-packages/Xc*"

docs:
	$(MAKE) -C docs all || true