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