c33c1755ede1bfcabb476bbb65efe25fe9ec818d
[apex.git] / build / Makefile
1 ##############################################################################
2 # Copyright (c) 2015 Ericsson AB and others.
3 # stefan.k.berg@ericsson.com
4 # jonas.bjurel@ericsson.com
5 # dradez@redhat.com
6 # All rights reserved. This program and the accompanying materials
7 # are made available under the terms of the Apache License, Version 2.0
8 # which accompanies this distribution, and is available at
9 # http://www.apache.org/licenses/LICENSE-2.0
10 ##############################################################################
11
12 SHELL = /bin/bash
13 ############################################################################
14 # BEGIN of variables to customize
15 #
16 #Input args
17 export UNIT_TEST = FALSE
18 export INTERACTIVE = TRUE
19 export CENTDNLD = http://mirrors.cat.pdx.edu/centos/7.1.1503/isos/x86_64/CentOS-7-x86_64-DVD-1503-01.iso
20 export ISOSRC = file:$(shell pwd)/CentOS-7-x86_64-DVD-1503-01.iso
21 export ISOCACHE = $(shell pwd)/$(shell basename $(ISOSRC))
22 export PRODNO = "OPNFV_BGS"
23 export REVSTATE = "P0000"
24 export NEWISO = $(shell pwd)/release/OPNFV-CentOS-7-x86_64-${REVSTATE}.iso
25 export GENESISRPM = $(shell pwd)/x86_64/opnfv-genesis-0.1-1.x86_64.rpm
26
27 # Note! Invoke with "make REVSTATE=RXXXX all" to make release build!
28 # Invoke with ICOCACHE=/full/path/to/iso if cached ISO is in non-standard location.
29
30 #Build variables
31 export BUILD_BASE := $(shell pwd)
32 export CACHE_DIR := $(BUILD_BASE)/cache
33 export VERSION_FILE := $(BUILD_BASE)/.versions
34 export TOPDIR := $(shell pwd)
35
36 CENTDIR := $(TOPDIR)/centiso
37 #
38 # END of variables to customize
39 #############################################################################
40
41 SUBCLEAN = $(addsuffix .clean,$(SUBDIRS))
42
43
44 .PHONY: all
45 all: iso
46         @echo "Versions of cached build results built by" $(shell hostname) "at" $(shell date -u) > $(VERSION_FILE)
47         @echo "cache.mk" $(shell md5sum $(BUILD_BASE)/cache.mk | cut -f1 -d " ") >> $(VERSION_FILE)
48         @echo "config.mk" $(shell md5sum $(BUILD_BASE)/config.mk | cut -f1 -d " ") >> $(VERSION_FILE)
49
50 ############################################################################
51 # BEGIN of Include definitions
52 #
53 include config.mk
54 include cache.mk
55 #
56 # END Include definitions
57 #############################################################################
58
59 $(ISOCACHE):
60         test -s $(ISOCACHE) || { wget -nv $(CENTDNLD) ; }
61
62 .PHONY: mount-centiso umount-centiso
63 mount-centiso: $(ISOCACHE)
64         @echo "Mounting CentOS ISO in $(CENTDIR)"
65         @mkdir -p $(CENTDIR)
66         @fuseiso $(ISOCACHE) $(CENTDIR)
67
68 umount-centiso:
69         @set +e
70         @echo "Unmounting CentOS ISO from $(CENTDIR)"
71         @fusermount -u $(CENTDIR)
72         @rmdir $(CENTDIR)
73         @set -e
74
75 .PHONY: build-clean $(SUBCLEAN)
76 build-clean: $(SUBCLEAN)
77         @rm -Rf centos
78         @rm -Rf release
79         @rm -Rf newiso
80         @rm -f $(NEWISO)
81
82 .PHONY: clean $(SUBCLEAN)
83 clean:  clean-cache $(SUBCLEAN)
84         @rm -f *.iso
85         @rm -Rf release
86         @rm -Rf newiso
87         @rm -f $(NEWISO)
88         @rm -f $(BUILD_BASE)/.versions
89
90 $(SUBCLEAN): %.clean:
91         $(MAKE) -C $* -f Makefile clean
92
93 .PHONY: rpm-clean
94 rpm-clean:
95         rpmbuild --clean opnfv-genesis.spec -D '_topdir %(echo `pwd`)' -D '_builddir %(echo `pwd`)' -D '_sourcedir %(echo `pwd`)' -D '_rpmdir %(echo `pwd`)' -D '_specdir %(echo `pwd`)' -D '_srcrpmdir %(echo `pwd`)'
96
97 .PHONY: rpm
98 rpm:
99         pushd ../../ && git archive --format=tar --prefix=opnfv-genesis-0.1/ HEAD | gzip > foreman/build/opnfv-genesis.tar.gz
100         rpmbuild -ba opnfv-genesis.spec -D '_topdir %(echo `pwd`)' -D '_builddir %(echo `pwd`)' -D '_sourcedir %(echo `pwd`)' -D '_rpmdir %(echo `pwd`)' -D '_specdir %(echo `pwd`)' -D '_srcrpmdir %(echo `pwd`)' 
101         @make rpm-clean
102
103 .PHONY: instack
104 instack: instack.qcow2
105
106 instack.qcow2:
107         @./instack.sh
108
109 .PHONY: instack-clean
110 instack-clean:
111         @virsh destroy instack 2> /dev/null || echo -n ''
112         @virsh undefine instack 2> /dev/null || echo -n ''
113         @virsh destroy baremetal_0 2> /dev/null || echo -n ''
114         @virsh undefine baremetal_0 2> /dev/null || echo -n ''
115         @virsh destroy baremetal_1 2> /dev/null || echo -n ''
116         @virsh undefine baremetal_1 2> /dev/null || echo -n ''
117         rm -f instack.xml
118         rm -f instack.qcow2
119         rm -rf stack
120
121
122 # Todo: Make things smarter - we shouldn't need to clean everything
123 # betwen make invocations.
124 .PHONY: iso
125 iso:    build-clean $(ISOCACHE) instack.qcow2 rpm
126         @make mount-centiso
127         @mkdir centos release
128         cp -r $(CENTDIR)/* centos
129         @make umount-centiso
130         # modify the installer iso's contents
131         @cp -f isolinux.cfg centos/isolinux/isolinux.cfg
132         @cp $(GENESISRPM) centos/Packages
133         # regenerate yum repo data
134         @echo "Generating new yum metadata"
135         createrepo --update -g ../c7-opnfv-x86_64-comps.xml centos
136         # build the iso
137         @echo "Building OPNFV iso"
138         mkisofs -b isolinux/isolinux.bin -no-emul-boot -boot-load-size 4 -boot-info-table -V "OPNFV CentOS 7 x86_64" -R -J -v -T -o $(NEWISO) centos
139         @printf "\n\nISO is built at $(NEWISO)\n\n"