1# SPDX-License-Identifier: BSD-3-Clause
2
3# This creates a release tarball from a git checkout.
4#
5# Warning: a ".tarball-version" at the top of the source directory takes
6# precedence; even for git checkouts it does! This can be used to make
7# the build "more deterministic". See GIT_TAG in version.cmake.
8
9set(TAR_BASENAME sof-${GIT_TAG})
10set(TARBALL_PATH_TMP "${PROJECT_BINARY_DIR}/${TAR_BASENAME}.tar")
11set(TARBALL_PATH "${PROJECT_BINARY_DIR}/${TAR_BASENAME}.tgz")
12set(TARBALL_VERSION_BINARY_PATH "${PROJECT_BINARY_DIR}/${TARBALL_VERSION_FILE_NAME}")
13
14add_custom_target(dist
15	COMMAND git archive --prefix=${TAR_BASENAME}/ -o "${TARBALL_PATH_TMP}" HEAD
16
17	# .tarball-version in the top build directory for git users' convenience
18	COMMAND ${CMAKE_COMMAND} -E echo "${GIT_TAG}" > "${TARBALL_VERSION_BINARY_PATH}"
19	COMMAND ${CMAKE_COMMAND} -E echo "${GIT_LOG_HASH}" >> "${TARBALL_VERSION_BINARY_PATH}"
20
21	# ${TAR_BASENAME}/.tarball-version for the release tarball
22	COMMAND ${CMAKE_COMMAND} -E make_directory "${PROJECT_BINARY_DIR}/${TAR_BASENAME}"
23	COMMAND ${CMAKE_COMMAND} -E copy "${TARBALL_VERSION_BINARY_PATH}" "${PROJECT_BINARY_DIR}/${TAR_BASENAME}/${TARBALL_VERSION_FILE_NAME}"
24	COMMAND tar rf "${TARBALL_PATH_TMP}" -C "${PROJECT_BINARY_DIR}" "${TAR_BASENAME}/${TARBALL_VERSION_FILE_NAME}"
25
26	COMMAND gzip -9 < "${TARBALL_PATH_TMP}" > "${TARBALL_PATH}"
27
28	WORKING_DIRECTORY "${PROJECT_SOURCE_DIR}"
29	COMMENT "Creating tarball: ${TARBALL_PATH}
30Warning: you must invoke make/ninja 'rebuild_cache' when the version changes, 'clean' is not enough.
31"
32	BYPRODUCTS "$TARBALL_VERSION_BINARY_PATH" "${TARBALL_PATH_TMP}" "${TARBALL_PATH}"
33	VERBATIM
34	USES_TERMINAL
35)
36