Fix build failure in fuel base & qemu
[fuel.git] / build / Makefile
1 ##############################################################################
2 # Copyright (c) 2015 Ericsson AB and others.
3 # stefan.k.berg@ericsson.com
4 # jonas.bjurel@ericsson.com
5 # All rights reserved. This program and the accompanying materials
6 # are made available under the terms of the Apache License, Version 2.0
7 # which accompanies this distribution, and is available at
8 # http://www.apache.org/licenses/LICENSE-2.0
9 ##############################################################################
10
11 SHELL = /bin/bash
12
13 # This file will be created if needed by runcontext to contain proxy
14 # settings.
15 -include environment.mk
16
17 ############################################################################
18 # BEGIN of variables to customize
19 #
20 #Input args
21 export ISOSRC = file:$(shell pwd)/fuel-7.0.iso
22 export ISOCACHE = $(shell pwd)/$(shell basename $(ISOSRC))
23 export PRODNO = "OPNFV_BGS"
24 export REVSTATE = "P0000"
25
26 ifdef BUILD_FUEL_PLUGINS
27 $(warning Overriding plugin build selection to $(BUILD_FUEL_PLUGINS))
28 export NEWISO = $(shell pwd)/release/unofficial-opnfv-${REVSTATE}.iso
29 else
30 export NEWISO = $(shell pwd)/release/opnfv-${REVSTATE}.iso
31 endif
32
33 # Note! Invoke with "make REVSTATE=RXXXX all" to make release build!
34 # Invoke with ICOCACHE=/full/path/to/iso if cached ISO is in non-standard location.
35
36 # Build variables
37 export BUILD_BASE := $(shell pwd)
38 export DEB_DEST := $(BUILD_BASE)/release/packages/ubuntu/pool/main
39 export UDEB_DEST := $(BUILD_BASE)/release/packages/ubuntu/pool/debian-installer
40 export PUPPET_DEST := $(BUILD_BASE)/release/puppet/modules
41 export VERSION_FILE := $(BUILD_BASE)/.versions
42 export DOCKERIMG = opnfv.org/ubuntu-builder:14.04
43 export TOPDIR := $(shell pwd)
44 export REPOINFO  := $(BUILD_BASE)/repo_info.sh
45
46 #Build subclasses
47
48 SUBDIRS := f_isoroot
49
50 # f_example is only an example of how to generate a .deb package and
51 # should not be enabled in official builds.
52 #SUBDIRS += f_example
53
54 ORIGDIR := $(TOPDIR)/origiso
55 #
56 # END of variables to customize
57 #############################################################################
58
59 SUBCLEAN = $(addsuffix .clean,$(SUBDIRS))
60
61 .PHONY: all
62 all:
63         @docker version >/dev/null 2>&1 || (echo 'No Docker installation available'; exit 1)
64         @make -C docker
65         @docker/runcontext $(DOCKERIMG) $(MAKE) $(MAKEFLAGS) iso
66
67
68 ############################################################################
69 # BEGIN of Include definitions
70 #
71 include config.mk
72 include cache.mk
73 #
74 # END Include definitions
75 #############################################################################
76
77 $(ISOCACHE):
78         # Clone Fuel to non-persistent location and build
79         if [ ! -d /tmp/fuel-main ]; then \
80                 cd /tmp && git clone $(FUEL_MAIN_REPO); \
81         fi
82         cd /tmp/fuel-main && git checkout $(FUEL_MAIN_TAG)
83         @echo "fuel" `git -C /tmp/fuel-main show | grep commit | head -1 | cut -d " " -f2` >> $(VERSION_FILE)
84         # Setup cgroups for docker-in-docker
85         sudo /root/enable_dockerx2
86         # Patch for adding dosfstools, as Fuel 6.1 is running mkfs.vfat
87         cd /tmp/fuel-main && patch -p0 < $(TOPDIR)/fuel-main_5.patch
88         # Patch for changing the second layer Docker --bip address
89         cd /tmp/fuel-main && patch -p0 < $(TOPDIR)/fuel-main_6.patch
90         # Remove Docker optimizations, otherwise multistrap will fail during
91         # Fuel build.
92         sudo rm -f /etc/apt/apt.conf.d/docker*
93         #
94         # Need to replace the old Docker v. 1.5.0 with a later version to be
95         # able to access the Docker remote repository!
96         cd /tmp/fuel-main && patch -p0 < $(TOPDIR)/fuel-main_docker_version.patch
97         cd /tmp/fuel-main && patch -p0 < $(TOPDIR)/fuel-main_docker_dns.patch
98         #
99         cd /tmp/fuel-main && ./prepare-build-env.sh
100         cd /tmp/fuel-main && make repos
101         $(REPOINFO) -r /tmp/fuel-main > gitinfo_fuel.txt
102         #
103         cd /tmp/fuel-main && sudo make iso
104         cp /tmp/fuel-main/build/artifacts/fuel*.iso .
105
106 .PHONY: mount-origiso umount-origiso
107 mount-origiso: $(ISOCACHE)
108         @echo "Mounting original ISO in $(ORIGDIR)"
109         @mkdir -p $(ORIGDIR)
110         @fuseiso $(ISOCACHE) $(ORIGDIR)
111
112 umount-origiso:
113         @echo "Unmounting original ISO from $(ORIGDIR)"
114         @fusermount -u $(ORIGDIR)
115         @rmdir $(ORIGDIR)
116
117 .PHONY: $(SUBDIRS)
118 $(SUBDIRS):
119         @mkdir -p release/packages/ubuntu/pool/main release/packages/ubuntu/pool/debian-installer release/puppet/modules release/isoroot
120         $(MAKE) -C $@ -f Makefile release
121
122 .PHONY: patch-packages
123 patch-packages:
124         ORIGISO=$(ISOCACHE) REVSTATE=$(REVSTATE) $(MAKE) -C $@ -f Makefile release
125
126 .PHONY: clean $(SUBCLEAN)
127 clean:  $(SUBCLEAN)
128         $(MAKE) -C patch-packages -f Makefile clean
129         @rm -f *.iso
130         @rm -Rf release
131         @rm -Rf newiso
132         @rm -Rf .versions
133         @rm -f $(NEWISO)
134         @rm -f $(BUILD_BASE)/gitinfo_*.txt
135
136 .PHONY: deepclean
137 deepclean: clean clean-cache
138         make -C docker clean
139         docker rmi opnfv.org/ubuntu-builder:14.04 &>/dev/null || exit 0
140         docker rmi opnfv.org/ubuntu-builder:latest &>/dev/null || exit 0
141         docker rmi ubuntu:14.04 &>/dev/null || exit 0
142         @if docker images | grep -q "ubuntu *14.04"; then \
143                 echo "Error: ubuntu:14.04 still present!"; \
144                 exit 1; \
145         fi
146         @if docker images | grep -q "opnfv.org/ubuntu-builder"; then \
147                 echo "Error: opnfv.org/ubuntu-builder still present!"; \
148                 exit 1; \
149         fi
150
151 $(SUBCLEAN): %.clean:
152         $(MAKE) -C $* -f Makefile clean
153
154 .PHONY: setup-env
155 setup-env:
156         @if [ -f environment.mk ]; then \
157                 sudo bash -c "cat environment.mk >> /etc/environment"; \
158         fi
159
160 # Todo: Make things smarter - we shouldn't need to clean everything
161 # betwen make invocations.
162 .PHONY: iso
163 iso:    setup-env $(ISOCACHE) $(SUBDIRS) patch-packages
164         $(REPOINFO) . > gitinfo_main.txt
165         install/install.sh iso $(ISOCACHE) $(NEWISO) $(PRODNO) $(REVSTATE)
166         @printf "\n\nProduct ISO is $(NEWISO)\n\n"
167
168 # Start a bash shell in docker for Makefile debugging
169 .PHONY: debug
170 debug:
171         @docker version >/dev/null 2>&1 || (echo 'No Docker installation available'; exit 1)
172         @make -C docker
173         docker/runcontext $(DOCKERIMG) debug
174
175 #############################################################################
176 # Cache operations - only used when building through ci/build.sh
177 #############################################################################
178
179 # Create a unique hash to be used for getting and putting cache, based on:
180 #   - The commit ID of the full Fuel repo structre
181 #   - The contents of all local Fuel patches
182 .cacheid:
183         cd /tmp && git clone $(FUEL_MAIN_REPO)
184         cd /tmp/fuel-main && git checkout $(FUEL_MAIN_TAG)
185         cd /tmp/fuel-main && make repos
186         $(REPOINFO) -r /tmp/fuel-main > .cachedata
187         sha1sum fuel-main*.patch >> .cachedata
188         cat .cachedata | $(CACHETOOL) getid > .cacheid
189         # Not removing fuel-main as it is re-used in build
190
191 # Clean local data related to caching - called prior to ordinary build
192 .PHONY: clean-cache
193 clean-cache: $(SUBCLEANCACHE)
194         rm -f .cachedata .cacheid
195
196 # Try to download cache - called prior to ordinary build
197 .PHONY: get-cache
198 get-cache: .cacheid
199         @if $(CACHETOOL) check $(shell cat .cacheid); then \
200                  $(CACHETOOL) get $(shell cat .cacheid) | tar xf -;\
201         else \
202                 exit 0;\
203         fi
204
205 # Store cache if not already stored - called after ordinary build
206 .PHONY: put-cache
207 put-cache: .cacheid
208         @tar cf - fuel*.iso gitinfo_fuel.txt | $(CACHETOOL) put $(shell cat .cacheid)