Merge "Updating address of Fuel repositories" into experimental
[fuel.git] / fuel / 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 # BEGIN of variables to customize
14 #
15 #Input args
16 export ISOSRC = file:$(shell pwd)/fuel-7.0.iso
17 export ISOCACHE = $(shell pwd)/$(shell basename $(ISOSRC))
18 export PRODNO = "OPNFV_BGS"
19 export REVSTATE = "P0000"
20 export NEWISO = $(shell pwd)/release/opnfv-${REVSTATE}.iso
21
22 # Note! Invoke with "make REVSTATE=RXXXX all" to make release build!
23 # Invoke with ICOCACHE=/full/path/to/iso if cached ISO is in non-standard location.
24
25 # Build variables
26 export BUILD_BASE := $(shell pwd)
27 export DEB_DEST := $(BUILD_BASE)/release/packages/ubuntu/pool/main
28 export UDEB_DEST := $(BUILD_BASE)/release/packages/ubuntu/pool/debian-installer
29 export PUPPET_DEST := $(BUILD_BASE)/release/puppet/modules
30 export VERSION_FILE := $(BUILD_BASE)/.versions
31 export DOCKERIMG = opnfv.org/ubuntu-builder:14.04
32 export TOPDIR := $(shell pwd)
33 export REPOINFO  := $(BUILD_BASE)/repo_info.sh
34
35 #Build subclasses
36
37 SUBDIRS := f_isoroot
38
39 # f_example is only an example of how to generate a .deb package and
40 # should not be enabled in official builds.
41 #SUBDIRS += f_example
42
43 ORIGDIR := $(TOPDIR)/origiso
44 #
45 # END of variables to customize
46 #############################################################################
47
48 SUBCLEAN = $(addsuffix .clean,$(SUBDIRS))
49
50 .PHONY: all
51 all:
52         @docker version >/dev/null 2>&1 || (echo 'No Docker installation available'; exit 1)
53         @make -C docker
54         @docker/runcontext $(DOCKERIMG) $(MAKE) $(MAKEFLAGS) iso
55
56
57 ############################################################################
58 # BEGIN of Include definitions
59 #
60 include config.mk
61 include cache.mk
62 #
63 # END Include definitions
64 #############################################################################
65
66 $(ISOCACHE):
67         # Clone Fuel to non-persistent location and build
68         if [ ! -d /tmp/fuel-main ]; then \
69                 cd /tmp && git clone $(FUEL_MAIN_REPO); \
70         fi
71         cd /tmp/fuel-main && git checkout $(FUEL_MAIN_TAG)
72         @echo "fuel" `git -C /tmp/fuel-main show | grep commit | head -1 | cut -d " " -f2` >> $(VERSION_FILE)
73         # Setup cgroups for docker-in-docker
74         sudo /root/enable_dockerx2
75         # Patch for adding dosfstools, as Fuel 6.1 is running mkfs.vfat
76         cd /tmp/fuel-main && patch -p0 < $(TOPDIR)/fuel-main_5.patch
77         # Remove Docker optimizations, otherwise multistrap will fail during
78         # Fuel build.
79         sudo rm -f /etc/apt/apt.conf.d/docker*
80         #
81         cd /tmp/fuel-main && ./prepare-build-env.sh
82         cd /tmp/fuel-main && make repos
83         $(REPOINFO) -r /tmp/fuel-main > gitinfo_fuel.txt
84         #
85         cd /tmp/fuel-main && make iso
86         mv /tmp/fuel-main/build/artifacts/fuel*.iso .
87
88 .PHONY: mount-origiso umount-origiso
89 mount-origiso: $(ISOCACHE)
90         @echo "Mounting original ISO in $(ORIGDIR)"
91         @mkdir -p $(ORIGDIR)
92         @fuseiso $(ISOCACHE) $(ORIGDIR)
93
94 umount-origiso:
95         @echo "Unmounting original ISO from $(ORIGDIR)"
96         @fusermount -u $(ORIGDIR)
97         @rmdir $(ORIGDIR)
98
99 .PHONY: $(SUBDIRS)
100 $(SUBDIRS):
101         @mkdir -p release/packages/ubuntu/pool/main release/packages/ubuntu/pool/debian-installer release/puppet/modules release/isoroot
102         $(MAKE) -C $@ -f Makefile release
103
104 .PHONY: patch-packages
105 patch-packages:
106         ORIGISO=$(ISOCACHE) REVSTATE=$(REVSTATE) $(MAKE) -C $@ -f Makefile release
107
108 .PHONY: clean $(SUBCLEAN)
109 clean:  $(SUBCLEAN)
110         $(MAKE) -C patch-packages -f Makefile clean
111         @rm -f *.iso
112         @rm -Rf release
113         @rm -Rf newiso
114         @rm -f $(NEWISO)
115         @rm -f $(BUILD_BASE)/gitinfo_*.txt
116
117 $(SUBCLEAN): %.clean:
118         $(MAKE) -C $* -f Makefile clean
119
120 # Todo: Make things smarter - we shouldn't need to clean everything
121 # betwen make invocations.
122 .PHONY: iso
123 iso:    $(ISOCACHE) $(SUBDIRS) patch-packages
124         $(REPOINFO) . > gitinfo_main.txt
125         install/install.sh iso $(ISOCACHE) $(NEWISO) $(PRODNO) $(REVSTATE)
126         @printf "\n\nProduct ISO is $(NEWISO)\n\n"
127
128 # Start a bash shell in docker for Makefile debugging
129 .PHONY: debug
130 debug:
131         @docker version >/dev/null 2>&1 || (echo 'No Docker installation available'; exit 1)
132         docker/runcontext $(DOCKERIMG) bash
133
134 #############################################################################
135 # Cache operations - only used when building through ci/build.sh
136 #############################################################################
137
138 # Create a unique hash to be used for getting and putting cache, based on:
139 #   - The commit ID of the full Fuel repo structre
140 #   - The contents of all local Fuel patches
141 .cacheid:
142         cd /tmp && git clone $(FUEL_MAIN_REPO)
143         cd /tmp/fuel-main && git checkout $(FUEL_MAIN_TAG)
144         cd /tmp/fuel-main && make repos
145         $(REPOINFO) -r /tmp/fuel-main > .cachedata
146         sha1sum fuel-main*.patch >> .cachedata
147         cat .cachedata | $(CACHETOOL) getid > .cacheid
148         # Not removing fuel-main as it is re-used in build
149
150 # Clean local data related to caching - called prior to ordinary build
151 .PHONY: clean-cache
152 clean-cache:
153         rm -f .cachedata .cacheid
154
155 # Try to download cache - called prior to ordinary build
156 .PHONY: get-cache
157 get-cache: .cacheid
158         @if $(CACHETOOL) check $(shell cat .cacheid); then \
159                  $(CACHETOOL) get $(shell cat .cacheid) | tar xf -;\
160         else \
161                 exit 0;\
162         fi
163
164 # Store cache if not already stored - called after ordinary build
165 .PHONY: put-cache
166 put-cache: .cacheid
167         @tar cf - fuel*.iso gitinfo_fuel.txt | $(CACHETOOL) put $(shell cat .cacheid)