summaryrefslogtreecommitdiff
path: root/script/update/release/src
blob: 3a96601566caab0ccd097697a535d1e15db94d33 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
#!/usr/bin/env sh
# SPDX-License-Identifier: GPL-3.0-or-later
# SPDX-FileCopyrightText: 2020,2021,2023 Leah Rowe <leah@libreboot.org>

[ "x${DEBUG+set}" = 'xset' ] && set -v
set -u -e

. "include/err.sh"

read projectname < projectname

trees_fetch_list="coreboot u-boot seabios"
simple_fetch_list="flashrom grub memtest86plus me_cleaner uefitool"
simple_fetch_list="${simple_fetch_list} bios_extract biosutilities"
download_only_list="pico-serprog stm32-vserprog"

dirlist="config util script include util-fw"
linklist="build update handle" # symlinks in main directory, to script: lbmk
filelist="lbmk README.md COPYING version versiondate projectname"

version="version-unknown"
versiondate="version-date-unknown"
eval "$(setvars "" reldir dirname srcdir)"

printf "Building source code archive, version %s\n" "${version}"

main()
{
	[ -f version ] && read version < version
	[ -f versiondate ] && read versiondate < versiondate

	create_release_directory
	download_modules
	copy_files
	purge_files

	create_release_archive
	printf "Source code archive available at %s.tar.xz\n\n" "${srcdir}"
}

create_release_directory()
{
	reldir="release/${version}"
	dirname="${projectname}-${version}_src"
	srcdir="${reldir}/${dirname}"

	[ -d "release/" ] || x_ mkdir -p release/
	[ -d "${reldir}/" ] || x_ mkdir -p "${reldir}/"
	[ ! -d "${srcdir}/" ] || x_ rm -Rf "${srcdir}/"
	[ ! -f "${srcdir}.tar.xz" ] || \
		x_ rm -f "${srcdir}.tar.xz/"

	x_ mkdir -p "${srcdir}/"
	x_ printf "%s" "${version}" > "${srcdir}"/version
}

download_modules()
{
	for modname in ${trees_fetch_list}; do
		[ -d "${modname}" ] || x_ ./update project trees ${modname}
	done
	for modname in ${simple_fetch_list} ${download_only_list}; do
		[ -d "${modname}/" ] || x_ ./update project repo ${modname}
	done
}

copy_files()
{
	for dir in ${trees_fetch_list}; do
		[ -d "${dir}" ] || continue
		for subdir in "${dir}"/*; do
			[ -d "${subdir}" ] || continue
			[ "${subdir##*/}" = "${dir}" ] && continue
			x_ mkdir -p "${srcdir}/${dir}"
			[ ! -d "${srcdir}/${dir}/${subdir##*/}" ] || \
			    x_ rm -Rf "${srcdir}/${dir}/${subdir##*/}"
			x_ cp -R "${subdir}" "${srcdir}/${dir}/${subdir##*/}"
		done
	done
	for dir in ${simple_fetch_list} ${dirlist}; do
		x_ cp -R "${dir}/" "${srcdir}/"
	done

	for i in ${filelist}; do
		if [ ! -f "${i}" ]; then
			x_ rm -Rf "${srcdir}"
			err "copy_files: file '${i}' does not exist"
		fi
		x_ cp "${i}" "${srcdir}/"
	done
	(
	x_ cd "${srcdir}/"
	for i in ${linklist}; do
		x_ ln -s lbmk "${i}"
	done
	)
}

purge_files()
{
	(
	x_ cd "${srcdir}/"
	[ ! -d "coreboot/default/util/kbc1126" ] || \
		x_ ./update project build -c "coreboot/default/util/kbc1126"
	x_ ./update project build -x coreboot
	for p in u-boot seabios coreboot; do
		x_ ./update project build -c "${p}"
	done
	x_ ./update project build -c bios_extract flashrom grub uefitool \
	    util-fw/stm32-vserprog util-fw/stm32-vserprog/libopencm3 \
	    memtest86plus/build32 memtest86plus/build64 util/*

	x_ rm -Rf .git* */.git* */*/.git* */*/*/.git* */*/*/*/.git* \
	    */*/*/*/*/.git* */*/*/*/*/*/.git* */*/*/*/*/*/*/.git*
	x_ rm -Rf cbutils elf util-fw/rp2040/pico-serprog/build
	)
}

create_release_archive()
{
	(
	x_ cd "${reldir}/"
	x_ tar -c "${dirname}/" | xz -T0 -9e >"${dirname}.tar.xz"
	x_ rm -Rf "${dirname}/"
	)
}

main $@