Update submodules.
[vuplus_openvuplus_3.0] / Makefile
1 #!/usr/bin/make -f
2 #
3 # Permission is hereby granted, free of charge, to any person obtaining a copy
4 # of this software and associated documentation files (the "Software"), to deal
5 # in the Software without restriction, including without limitation the rights
6 # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7 # copies of the Software, and to permit persons to whom the Software is
8 # furnished to do so, subject to the following conditions:
9 #
10 # The above copyright notice and this permission notice shall be included in
11 # all copies or substantial portions of the Software.
12 #
13 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14 # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15 # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16 # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17 # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18 # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19 # THE SOFTWARE.
20 #
21
22 # Note: You can override all variables by storing them
23 # in an external file called "make.conf".
24 -include conf/make.conf
25
26 # Target platform:
27 # vusolo, bm750, vuuno, vuultimo, vusolo2
28 #
29 # This only sets the default value. All platforms now use a shared build
30 # directory. Run "MACHINE=vuultimo bitbake vuplus-image" to build an image
31 # for the vuultimo, if it is not the default.
32 MACHINE ?= vusolose
33
34 MULTI_TEMPORARILY ?= NO
35
36 # Adjust according to the number CPU cores to use for parallel build.
37 # Default: Number of processors in /proc/cpuinfo, if present, or 1.
38 NR_CPU := $(shell [ -f /proc/cpuinfo ] && grep -c '^processor\s*:' /proc/cpuinfo || echo 1)
39 BB_NUMBER_THREADS ?= $(NR_CPU)
40 PARALLEL_MAKE ?= -j $(NR_CPU)
41
42 XSUM ?= md5sum
43
44 BUILD_DIR = $(CURDIR)/build
45 TOPDIR = $(BUILD_DIR)/$(MACHINE)
46 DL_DIR = $(CURDIR)/sources
47
48 ifeq ($(MULTI_TEMPORARILY), YES)
49 SSTATE_DIR = $(TOPDIR)/sstate-cache
50 TMPDIR = $(TOPDIR)/tmp
51 DEPDIR = $(TOPDIR)/.deps
52 else
53 SSTATE_DIR = $(BUILD_DIR)/sstate-cache
54 TMPDIR = $(BUILD_DIR)/tmp
55 DEPDIR = $(BUILD_DIR)/.deps
56 endif
57
58 BBLAYERS ?= \
59         $(CURDIR)/meta-bsp \
60         $(CURDIR)/meta-openvuplus \
61         $(CURDIR)/meta-openembedded/meta-oe \
62         $(CURDIR)/meta-openembedded/meta-networking \
63         $(CURDIR)/meta-openembedded/meta-multimedia \
64         $(CURDIR)/meta-openembedded/meta-filesystems \
65         $(CURDIR)/meta-openembedded/meta-python \
66         $(CURDIR)/openembedded-core/meta
67
68 CONFFILES = \
69         $(TOPDIR)/bitbake.env \
70         $(TOPDIR)/conf/bblayers.conf \
71         $(TOPDIR)/conf/local.conf
72
73 CONFDEPS = \
74         $(DEPDIR)/.bitbake.env.$(BITBAKE_ENV_HASH) \
75         $(DEPDIR)/.bblayers.conf.$(MACHINE).$(BBLAYERS_CONF_HASH) \
76         $(DEPDIR)/.local.conf.$(MACHINE).$(LOCAL_CONF_HASH)
77
78 GIT ?= git
79 GIT_REMOTE := $(shell $(GIT) remote)
80 GIT_USER_NAME := $(shell $(GIT) config user.name)
81 GIT_USER_EMAIL := $(shell $(GIT) config user.email)
82
83 hash = $(shell echo $(1) | $(XSUM) | awk '{print $$1}')
84
85 .DEFAULT_GOAL := all
86 all: init usage
87
88 $(BBLAYERS):
89         [ -d $@ ] || $(MAKE) $(MFLAGS) update
90
91 init: $(BBLAYERS) $(CONFFILES)
92         @if [ ! -e $(CURDIR)/sources ]; then mkdir -p $(CURDIR)/sources; fi
93
94 help:
95         @echo "Your options:"
96         @echo
97         @echo "  * Update the SDK"
98         @echo "      $$ $(MAKE) update"
99         @echo
100         @echo "  * Select a new target machine:"
101         @echo "      $$ echo MACHINE=vuultimo >> conf/make.conf"
102         @echo "    [Valid values: vusolo, bm750, vuuno, vuultimo, vusolo2]"
103         @echo
104         @echo "  * Build a firmware image for the selected target machine:"
105         @echo "      $$ $(MAKE) image"
106         @echo
107         @echo "  * Build a firmware image for a different target machine:"
108         @echo "      $$ $(MAKE) image MACHINE=vuultimo"
109         @echo "    [Valid values: vusolo, bm750, vuuno, vuultimo, vusolo2]"
110         @echo
111         @echo "  * Download all source files at once:"
112         @echo "      $$ $(MAKE) download"
113         @echo
114         @echo "  * Set up the environment to build recipes manually:"
115         @echo "      $$ cd $(BUILD_DIR)"
116         @echo "      $$ source bitbake.env"
117         @echo "      $$ bitbake <target>"
118         @echo "    [Replace <target> with a recipe name, e.g. vuplus-image or enigma2]"
119         @echo
120         @echo "Your current settings:"
121         @echo "  MACHINE = $(MACHINE)"
122         @echo
123         @echo "  BB_NUMBER_THREADS = $(BB_NUMBER_THREADS)"
124         @echo "  PARALLEL_MAKE = $(PARALLEL_MAKE)"
125         @echo
126         @echo "Trouble finding a recipe? Try ./scripts/drepo grep 'search string'"
127         @echo "or ./scripts/drepo find -name \"*recipe*\"."
128         @echo
129
130 usage:
131         @echo "[*] Please run '$(MAKE) help' to display further information!"
132
133 clean:
134         @echo '[*] Deleting generated configuration files'
135         @$(RM) $(CONFFILES) $(CONFDEPS)
136
137 distclean: clean
138         @echo '[*] Deleting dependencies directory'
139         @$(RM) -r $(DEPDIR)
140         @echo '[*] Deleting download directory'
141         @$(RM) -r $(DL_DIR)
142         @echo '[*] Deleting tmp directory'
143         @$(RM) -r $(TMPDIR)
144         @echo '[*] Deleting sstate directory'
145         @$(RM) -r $(SSTATE_DIR)
146         @echo '[*] Deleting build directory'
147         @$(RM) -r $(BUILD_DIR)
148         @echo '[*] Deleting git submodules'
149         @$(GIT) submodule foreach 'rm -rf .* * 2>/dev/null || true'
150
151 image: init
152         @echo '[*] Building image for $(MACHINE)'
153         @. $(TOPDIR)/bitbake.env && cd $(TOPDIR) && bitbake vuplus-image
154
155 download: init
156         @echo '[*] Downloading sources'
157         @. $(TOPDIR)/bitbake.env && cd $(TOPDIR) && bitbake -cfetchall -k vuplus-image
158
159 update:
160         @echo '[*] Updating Git repositories...'
161         @HASH=`$(XSUM) $(MAKEFILE_LIST)`; \
162         if [ -n "$(GIT_REMOTE)" ]; then \
163                 $(GIT) pull --ff-only || $(GIT) pull --rebase; \
164         fi; \
165         if [ "$$HASH" != "`$(XSUM) $(MAKEFILE_LIST)`" ]; then \
166                 echo '[*] Makefile changed. Restarting...'; \
167                 $(MAKE) $(MFLAGS) --no-print-directory $(MAKECMDGOALS); \
168         else \
169                 $(GIT) submodule sync && \
170                 $(GIT) submodule update --init && \
171                 echo "[*] The Vuplus SDK is now up-to-date."; \
172         fi
173
174 .PHONY: all clean help image init update usage
175
176 MACHINE_INCLUDE_CONF = $(CURDIR)/conf/$(basename $(@F))-$(MACHINE)-ext.conf
177 DISTRO_INCLUDE_CONF = $(CURDIR)/conf/$(basename $(@F))-ext.conf
178
179 BITBAKE_ENV_HASH := $(call hash, \
180         'BITBAKE_ENV_VERSION = "0"' \
181         'CURDIR = "$(CURDIR)"' \
182         )
183
184 $(TOPDIR)/bitbake.env: $(DEPDIR)/.bitbake.env.$(BITBAKE_ENV_HASH)
185         @echo '[*] Generating $@'
186         @test -d $(@D) || mkdir -p $(@D)
187         @echo '# Automatically generated file. Do not edit!' > $@
188         @echo 'export PATH=$(CURDIR)/openembedded-core/scripts:$(CURDIR)/bitbake/bin:$${PATH}' >> $@
189
190 LOCAL_CONF_HASH := $(call hash, \
191         'LOCAL_CONF_VERSION = "0"' \
192         'CURDIR = "$(CURDIR)"' \
193         'TOPDIR = "$(TOPDIR)"' \
194         'MACHINE = "$(MACHINE)"' \
195         'OPENVUPLUS_CONF_VERSION = "1"' \
196         'CURDIR = "$(CURDIR)"' \
197         'BB_NUMBER_THREADS = "$(BB_NUMBER_THREADS)"' \
198         'PARALLEL_MAKE = "$(PARALLEL_MAKE)"' \
199         'DL_DIR = "$(DL_DIR)"' \
200         'SSTATE_DIR = "$(SSTATE_DIR)"' \
201         'TMPDIR = "$(TMPDIR)"' \
202         )
203
204 $(TOPDIR)/conf/local.conf: $(DEPDIR)/.local.conf.$(MACHINE).$(LOCAL_CONF_HASH)
205         @echo '[*] Generating $@'
206         @test -d $(@D) || mkdir -p $(@D)
207         @echo '# Automatically generated file. Do not edit!' > $@
208         @echo 'TOPDIR = "$(TOPDIR)"' >> $@
209         @echo 'MACHINE = "$(MACHINE)"' >> $@
210         @echo 'BB_NUMBER_THREADS = "$(BB_NUMBER_THREADS)"' >> $@
211         @echo 'PARALLEL_MAKE = "$(PARALLEL_MAKE)"' >> $@
212         @echo 'DL_DIR = "$(DL_DIR)"' >> $@
213         @echo 'SSTATE_DIR = "$(SSTATE_DIR)"' >> $@
214         @echo 'TMPDIR = "$(TMPDIR)"' >> $@
215         @echo 'BB_GENERATE_MIRROR_TARBALLS = "0"' >> $@
216         @echo 'BBINCLUDELOGS = "yes"' >> $@
217         @echo 'CONF_VERSION = "1"' >> $@
218         @echo 'DISTRO = "vuplus"' >> $@
219         @echo 'EXTRA_IMAGE_FEATURES = "debug-tweaks"' >> $@
220         @echo 'USER_CLASSES = "buildstats"' >> $@
221         @echo 'include $(DISTRO_INCLUDE_CONF)' >> $@
222         @echo 'include $(MACHINE_INCLUDE_CONF)' >> $@
223         @echo 'INHERIT += "rm_work"' >> $@
224
225 BBLAYERS_CONF_HASH := $(call hash, \
226         'BBLAYERS_CONF_VERSION = "0"' \
227         'CURDIR = "$(CURDIR)"' \
228         'BBLAYERS = "$(BBLAYERS)"' \
229         )
230
231 $(TOPDIR)/conf/bblayers.conf: $(DEPDIR)/.bblayers.conf.$(MACHINE).$(BBLAYERS_CONF_HASH)
232         @echo '[*] Generating $@'
233         @test -d $(@D) || mkdir -p $(@D)
234         @echo '# Automatically generated file. Do not edit!' > $@
235         @echo 'LCONF_VERSION = "4"' >> $@
236         @echo 'BBFILES = ""' >> $@
237         @echo 'BBLAYERS = "$(BBLAYERS)"' >> $@
238         @echo 'include $(DISTRO_INCLUDE_CONF)' >> $@
239         @echo 'include $(MACHINE_INCLUDE_CONF)' >> $@
240
241 $(CONFDEPS):
242         @test -d $(@D) || mkdir -p $(@D)
243         @$(RM) $(basename $@).*
244         @touch $@