1
2# SPDX-License-Identifier: BSD-3-Clause
3# Copyright(c) 2021 Intel Corporation
4
5
6.DEFAULT_GOAL := stage
7.PHONY: clean stage rsync tarball
8.PHONY: signed unsigned ldicts topologies tools build_tools
9.PHONY: compare signed_dummies
10
11# Override ?= variables in config.mk
12-include config.mk
13
14# List of /lib/firmware/sof/ images and symbolic links currently
15# released by Intel.
16
17# See rimage/config/*.toml
18SIGNED_list  ?= tgl tgl-h
19
20# To find aliases, try in a Linux kernel git clone:
21#
22#   git grep 'sof-.*\.ri' -- sound/soc/
23
24ALIAS_OTHER_KEY_list += adl adl-s rpl rpl-s
25
26# Not supported in the main branch anymore, go to stable-v2.3
27# UNSIGNED_list += bdw byt cht
28# SIGNED_list   += apl cnl icl jsl
29# ALIAS_SAME_KEY_list  += glk cfl cml
30# ALIAS_OTHER_KEY_list += ehl
31
32# Much older platforms
33# UNSIGNED_list += hsw sue
34# SIGNED_list += kbl skl
35
36ALIAS_list := ${ALIAS_SAME_KEY_list} ${ALIAS_OTHER_KEY_list}
37
38$(info UNSIGNED_list = ${UNSIGNED_list} )
39$(info SIGNED_list   = ${SIGNED_list}   )
40$(info ALIAS_list    = ${ALIAS_list}    )
41
42target_of_ehl := tgl
43target_of_adl   := tgl
44target_of_adl-s := tgl-h
45target_of_rpl   := tgl
46target_of_rpl-s := tgl-h
47
48ifeq (,${TOOLCHAIN})
49  ifeq (,${XTENSA_TOOLS_ROOT})
50    TOOLCHAIN := gcc
51  else
52    TOOLCHAIN := xcc
53  endif
54endif
55
56TREE_OPTS ?= --sort=size --dirsfirst
57INSTALL_OPTS ?= -D -p -m 0664
58
59# Keep SOF_VERSION optional
60
61SOF_VERSION ?= $(shell git describe --dirty)
62ifneq (${SOF_VERSION},)
63VERSION_DIR := ${SOF_VERSION}/
64VERSION_SUFFIX := -${SOF_VERSION}
65endif
66
67
68
69      ################################
70      ###  Top-level directories  ####
71      ################################
72
73# Our input:  build_*_?cc/ directories
74BUILDS_ROOT ?= ${CURDIR}/../installer-builds
75BUILD_TOOLS ?= ${BUILDS_ROOT}/build_tools
76
77STAGING_SOF ?= staging/sof
78STAGING_SOF_VERSION := ${STAGING_SOF}${VERSION_SUFFIX}
79
80STAGING_SOF_TPLG ?= staging/sof-tplg
81
82STAGING_TOOLS ?= staging/tools
83
84stage: signed unsigned ldicts aliases topologies tools
85ifneq (${STAGING_SOF_VERSION},${STAGING_SOF})
86	ln -sfT sof${VERSION_SUFFIX} ${STAGING_SOF}
87	test -e ${STAGING_SOF}
88endif
89	@file ${STAGING_SOF}
90	@tree ${TREE_OPTS} ${STAGING_SOF_VERSION}
91
92COMMUNITY	:= ${STAGING_SOF_VERSION}/community
93INTEL_SIGNED	:= ${STAGING_SOF_VERSION}/intel-signed
94${COMMUNITY} ${INTEL_SIGNED} ${BUILDS_ROOT} ${STAGING_SOF_VERSION}:
95	mkdir -p $@
96
97# The noise for incremental, do-nothing builds is incredible otherwise,
98# especially for build_tools
99GNUMAKEFLAGS = --no-print-directory
100
101      #####################################
102      ###    rsync to local or remote  ####
103      #####################################
104
105# Default value
106FW_DESTDIR ?= /lib/firmware/intel/
107
108# The rsync target does not depend on any other target so:
109# - it's possible to deploy a staging _subset_, e.g.: only topologies
110#   only,...
111# - "sudo make rsync" never builds as root by accident
112rsync:
113# The --mkpath option is too recent, dealing with both remote and local
114# would be complicated and this is also a safety against typos.
115	# The destination directory must already exist
116	rsync -a --info=progress2 staging/sof* "${FW_DESTDIR}"
117ifneq (${USER_DESTDIR},)
118	# TODO: add more user space binaries: sof-ctl, probes,...
119	# absorbe scripts/sof-target-install.sh
120	cd ${BUILD_TOOLS} && rsync -a ${TOOLS_RELPATHS} ${USER_DESTDIR}
121endif
122
123clean:
124	${RM} -r ${STAGING_SOF}* ${STAGING_SOF_TPLG}* ${STAGING_TOOLS}*
125	${RM} ${BUILDS_ROOT}/staging_sof_tree.txt
126
127cleanall: clean
128	${RM} -r "${BUILD_TOOLS}/" "${BUILDS_ROOT}"/build_*_?cc/
129
130
131      #####################################
132      ###           tarball            ####
133      #####################################
134
135tarball: stage
136	cd staging && tar cfz sof-build${VERSION_SUFFIX}.tgz \
137	  sof${VERSION_SUFFIX} sof-tplg${VERSION_SUFFIX} \
138	  tools${VERSION_SUFFIX}
139
140
141      #####################################
142      ###           Stage tools        ####
143      #####################################
144
145# This is only for the tarball, rsync takes the RELPATHS shortcut
146tools: build_tools
147	mkdir -p ${STAGING_TOOLS}${VERSION_SUFFIX}
148	cd ${BUILD_TOOLS} && \
149	  cp -p ${TOOLS_RELPATHS} ${CURDIR}/${STAGING_TOOLS}${VERSION_SUFFIX}
150
151   ##########################################################
152   ###  Stage sof-*.ri firmware files and symbolic links ####
153   ##########################################################
154
155#
156# 1. Stages all *.ri files
157#
158# 2. Create symbolic links, including (broken) intel-signed symbolic
159#    links that must be fixed in a final release, otherwise the release
160#    is incomplete. To check all symlinks: file $(find -type l)
161#
162
163# '%' is the platform name
164SIGNED_FWS := ${SIGNED_list:%=${COMMUNITY}/sof-%.ri}
165# $(info SIGNED_FWS = ${SIGNED_FWS})
166signed: ${SIGNED_FWS}
167${SIGNED_FWS}: ${COMMUNITY}/sof-%.ri:    \
168               ${BUILDS_ROOT}/build_%_${TOOLCHAIN}/sof.ri     \
169	     | ${COMMUNITY} ${INTEL_SIGNED}
170	install ${INSTALL_OPTS} $< $@
171	ln -sfT     intel-signed/sof-$*.ri ${STAGING_SOF_VERSION}/sof-$*.ri
172
173# '%' is the platform name
174UNSIGNED_FWS := ${UNSIGNED_list:%=${STAGING_SOF_VERSION}/sof-%.ri}
175# $(info UNSIGNED_FWS = ${UNSIGNED_FWS})
176unsigned: ${UNSIGNED_FWS}
177${UNSIGNED_FWS}: ${STAGING_SOF_VERSION}/sof-%.ri:   \
178                 ${BUILDS_ROOT}/build_%_${TOOLCHAIN}/sof.ri
179	install ${INSTALL_OPTS} $< $@
180
181
182BUILD_SOF_RIS := \
183      ${UNSIGNED_list:%=${BUILDS_ROOT}/build_%_${TOOLCHAIN}/sof.ri} \
184        ${SIGNED_list:%=${BUILDS_ROOT}/build_%_${TOOLCHAIN}/sof.ri}
185
186# When the build is not deterministic use this to reduce noise when testing
187# this Makefile.
188# Also very useful with XCC, see next comment.
189ifneq (true,${BUILD_ONLY_ONCE})
190.PHONY: ${BUILD_SOF_RIS}
191endif
192
193# Incremental builds are not possible with XCC because the entire
194# toolchain requires $XTENSA_SYSTEM but CMake does not support
195# build-time environment variables. In the future we could move the
196# XTENSA_SYSTEM values out of xtensa-build-all.sh and into some shared
197# config file included here.
198${BUILD_SOF_RIS}: ${BUILDS_ROOT}/build_%_${TOOLCHAIN}/sof.ri: | ${BUILDS_ROOT}
199	cd ${BUILDS_ROOT} && bdir="$$(dirname $@)" &&  \
200      if [ -e $${bdir}/build.ninja -o -e $${bdir}/Makefile ] && \
201          [ xcc != "${TOOLCHAIN}" ] ; then \
202        cmake --build $${bdir} -- bin; else \
203      $(CURDIR)/../scripts/xtensa-build-all.sh -i "${IPC_VERSION}" $*; fi
204
205
206       ########################################
207       ###  Stage *.ldc logger dictionaries ###
208       ########################################
209
210# '%' is the platform name
211LDICTS := ${UNSIGNED_list:%=${STAGING_SOF_VERSION}/sof-%.ldc} \
212            ${SIGNED_list:%=${STAGING_SOF_VERSION}/sof-%.ldc}
213# $(info LDICTS = ${LDICTS})
214ldicts: ${LDICTS}
215${LDICTS}: ${STAGING_SOF_VERSION}/sof-%.ldc:  \
216                                ${BUILDS_ROOT}/build_%_${TOOLCHAIN}/sof.ri
217	if test -e ${BUILDS_ROOT}/build_$*_${TOOLCHAIN}/sof.ldc; then \
218	install ${INSTALL_OPTS} ${BUILDS_ROOT}/build_$*_${TOOLCHAIN}/sof.ldc $@ ; \
219	else printf '# CONFIG_TRACE was disabled\n' > $@; fi
220
221
222        #######################################
223        ###  Platform -> platform aliases  ####
224        #######################################
225
226# '%' is the platform name
227COMM_ALIASES   := ${ALIAS_list:%=${STAGING_SOF_VERSION}/community/sof-%.ri}
228DICT_ALIASES   := ${ALIAS_list:%=${STAGING_SOF_VERSION}/sof-%.ldc}
229
230${COMM_ALIASES}: ${STAGING_SOF_VERSION}/community/sof-%.ri: | ${COMMUNITY}
231	ln -sfT sof-${target_of_$*}.ri $@
232
233${DICT_ALIASES}: ${STAGING_SOF_VERSION}/sof-%.ldc: | ${STAGING_SOF_VERSION}
234	ln -sfT sof-${target_of_$*}.ldc $@
235
236# ->intel-signed/ symlinks for platform aliases. The other, identical
237# looking ->intel-signed/ symlinks for the other, "normal" platforms are
238# created here but by the signed: target.
239#
240# Some have the same key, others just the code. We don't make any
241# difference, no platform re-direction here, this is merely pointing at
242# ->intel-signed/same.ri
243SIGNED_ALIASES := ${ALIAS_list:%=${STAGING_SOF_VERSION}/sof-%.ri}
244${SIGNED_ALIASES}: ${STAGING_SOF_VERSION}/sof-%.ri: | ${STAGING_SOF_VERSION}
245	ln -sfT intel-signed/sof-$*.ri $@
246
247# Platform indirection inside the intel-signed/ directory
248SIGNED_PLATFORM_ALIASES := ${ALIAS_SAME_KEY_list:%=${INTEL_SIGNED}/sof-%.ri}
249${SIGNED_PLATFORM_ALIASES}: ${INTEL_SIGNED}/sof-%.ri: | ${INTEL_SIGNED}
250	ln -sfT sof-${target_of_$*}.ri $@
251
252
253aliases: ${COMM_ALIASES} ${DICT_ALIASES} ${SIGNED_ALIASES} \
254         ${SIGNED_PLATFORM_ALIASES}
255
256            ##################################
257            ### Stage sof-tplg/ topologies ###
258            ##################################
259
260# The build is not deterministic; use this to reduce noise when testing
261# this Makefile
262ifneq (true,${BUILD_ONLY_ONCE})
263.PHONY: ${BUILD_TOOLS}
264endif
265
266# Deploy and release only "official", top-level topology files starting
267# with the 'sof-' prefix to avoid any experimental stuff.
268topologies: ${BUILD_TOOLS}
269	install ${INSTALL_OPTS}  -t ${STAGING_SOF_TPLG}${VERSION_SUFFIX}/ \
270               ${BUILD_TOOLS}/topology/sof-*.tplg
271ifneq (,${VERSION_SUFFIX})
272	ln -sfT sof-tplg${VERSION_SUFFIX} ${STAGING_SOF_TPLG}
273	test -e ${STAGING_SOF_TPLG}
274endif
275	@file ${STAGING_SOF_TPLG}
276	@tree ${TREE_OPTS} ${STAGING_SOF_TPLG}${VERSION_SUFFIX} | \
277            head -n 10; printf '├── ...\n..\n'
278
279
280             ######################
281             ### build-tools.sh ###
282             ######################
283
284TOOLS_RELPATHS  := ctl/sof-ctl  logger/sof-logger  probes/sof-probes
285TOOLS_TARGETS   := sof-ctl      sof-logger         sof-probes
286TOOLS_FLAGS     := -c           -l                 -p
287
288.PHONY: build_tools
289build_tools: ${BUILD_TOOLS}
290
291# We could use more targets rather than "set -e" with a multi-lines "for" loop.
292# That would be more flexible but also quite verbose.
293${BUILD_TOOLS}:
294	set -e; if test -e ${BUILD_TOOLS}/build.ninja || \
295                   test -e ${BUILD_TOOLS}/Makefile; then \
296        for i in topologies ${TOOLS_TARGETS}; do \
297          cmake --build ${BUILD_TOOLS} -- $$i; done; else         \
298          BUILD_TOOLS_DIR=${BUILD_TOOLS} ../scripts/build-tools.sh -T ${TOOLS_FLAGS} ; \
299        fi
300
301
302             ####################
303             ### Self-Testing ###
304             ####################
305
306COMPARE_REFS ?= /lib/firmware/intel
307
308checktree:
309	cd ${STAGING_SOF_VERSION} && \
310             tree -a -v --dirsfirst . >  ${BUILDS_ROOT}/staging_sof_tree.txt
311	# Update sof-cavs-nocodec.tplg when adding or removing a default platform
312	diff -u tests/staging_sof${IPC_VERSION}_ref.txt ${BUILDS_ROOT}/staging_sof_tree.txt
313	# Check two random topologies are there
314	test -f ${STAGING_SOF_TPLG}/sof-tgl-nocodec.tplg
315	test -f ${STAGING_SOF_TPLG}/sof-imx8-wm8960.tplg
316	for t in sof-ctl sof-logger sof-probes; do \
317	   test -f ${STAGING_TOOLS}${VERSION_SUFFIX}/$${t}; done
318
319# Useful for testing this Makefile. COMPARE_REFS can be /lib/firmware,
320# sof-bin, a previous version of this Makefile,...
321# As the first arguments maybe symbolic links, their trailing slash is
322# critical.
323compare: stage
324	! diff -qr --no-dereference ${COMPARE_REFS}/sof/ \
325             ${STAGING_SOF_VERSION}/ \
326             | grep -v ' differ$$' # || true
327	! diff -qr --no-dereference ${COMPARE_REFS}/sof-tplg/ \
328             ${STAGING_SOF_TPLG}${VERSION_SUFFIX}/ \
329             | grep -v ' differ$$'
330
331# Invoke this manually to check symbolic links are correct
332SIGNED_DUMMIES := ${SIGNED_list:%=${INTEL_SIGNED}/sof-%.ri} \
333                   ${ALIAS_OTHER_KEY_list:%=${INTEL_SIGNED}/sof-%.ri}
334signed_dummies: ${SIGNED_DUMMIES}
335	! file $$(find staging -type l) | grep -i broken
336
337${SIGNED_DUMMIES}: | ${INTEL_SIGNED}
338	touch $@
339