Missed a reference to prepare target which was earlier used by odl
[genesis.git] / fuel / build / cache.mk
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 CACHEVALIDATE := $(addsuffix .validate,$(SUBDIRS))
13 CACHECLEAN := $(addsuffix .clean,$(CACHEFILES) $(CACHEDIRS))
14
15 ############################################################################
16 # BEGIN of variables to customize
17 #
18 #CACHEDIRS := opendaylight/f_odl/package
19
20 #CACHEFILES := opendaylight/.odl-build-history
21 #CACHEFILES += opendaylight/.odl-build.log
22 CACHEFILES += .versions
23 CACHEFILES += $(shell basename $(ISOSRC))
24 #
25 # END of variables to customize
26 ############################################################################
27
28 .PHONY: prepare-cache
29 prepare-cache: make-cache-dir $(CACHEDIRS) $(CACHEFILES)
30
31 .PHONY: make-cache-dir
32 make-cache-dir:
33         @rm -rf ${CACHE_DIR}
34         @mkdir ${CACHE_DIR}
35
36 .PHONY: clean-cache
37 clean-cache: $(CACHECLEAN)
38         @rm -rf ${CACHE_DIR}
39
40 .PHONY: $(CACHEDIRS)
41 $(CACHEDIRS):
42         @mkdir -p $(dir $(CACHE_DIR)/$@)
43         @if [ ! -d $(BUILD_BASE)/$@ ]; then\
44            mkdir -p $(BUILD_BASE)/$@;\
45         fi
46         @ln -s $(BUILD_BASE)/$@ $(CACHE_DIR)/$@
47
48 .PHONY: $(CACHEFILES)
49 $(CACHEFILES):
50         @mkdir -p $(dir $(CACHE_DIR)/$@)
51         @if [ ! -d $(dir $(BUILD_BASE)/$@) ]; then\
52            mkdir -p $(dir $(BUILD_BASE)/$@);\
53         fi
54
55         @if [ ! -f $(BUILD_BASE)/$@ ]; then\
56            echo " " > $(BUILD_BASE)/$@;\
57            ln -s $(BUILD_BASE)/$@ $(CACHE_DIR)/$@;\
58            rm -f $(BUILD_BASE)/$@;\
59         else\
60            ln -s $(BUILD_BASE)/$@ $(CACHE_DIR)/$@;\
61         fi
62
63 .PHONY: validate-cache
64 validate-cache: $(CACHEVALIDATE)
65         @if [ "$(shell md5sum $(BUILD_BASE)/config.mk | cut -f1 -d " ")" != "$(shell cat $(VERSION_FILE) | grep config.mk | awk '{print $$NF}')" ]; then\
66            echo "Cache does not match current config.mk definition, cache must be rebuilt";\
67            exit 1;\
68         fi;
69
70         @if [ "$(shell md5sum $(BUILD_BASE)/cache.mk | cut -f1 -d " ")" != "$(shell cat $(VERSION_FILE) | grep cache.mk | awk '{print $$NF}')" ]; then\
71            echo "Cache does not match current cache.mk definition, cache must be rebuilt";\
72            exit 1;\
73         fi;
74
75 # Once the Make structure is refactored, this should go in as a validate-cache
76 # taget in the fuel Makefile
77
78         @REMOTE_ID=$(shell git ls-remote $(FUEL_MAIN_REPO) $(FUEL_MAIN_TAG)^{} | awk '{print $$(NF-1)}'); \
79         if [ -z $$REMOTE_ID ] || [ $$REMOTE_ID = " " ]; \
80         then \
81            REMOTE_ID=$(shell git ls-remote $(FUEL_MAIN_REPO) $(FUEL_MAIN_TAG) | awk '{print $$(NF-1)}'); \
82         fi; \
83         if [[ $$REMOTE_ID != $(shell cat $(VERSION_FILE) | grep fuel | awk '{print $$NF}') ]]; \
84         then \
85            echo "Cache does not match upstream Fuel, cache must be rebuilt!"; \
86            exit 1; \
87         fi
88
89 .PHONY: $(CACHEVALIDATE)
90 $(CACHEVALIDATE): %.validate:
91         @echo VALIDATE $(CACHEVALIDATE)
92         $(MAKE) -C $* -f Makefile validate-cache
93
94 .PHONY: $(CACHECLEAN)
95 $(CACHECLEAN): %.clean:
96         rm -rf ${CACHE_DIR}/$*