summaryrefslogtreecommitdiffstats
path: root/scripts/lib/ptxd_make_pkghash.awk
blob: 5f90923a9125e0a3c21e8a68a9b2acce44f7db8a (plain) (blame)
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
#!/usr/bin/gawk -f
#
# Copyright (C) 2019 by Michael Olbrich <m.olbrich@pengutronix.de>
#
# For further information about the PTXdist project and license conditions
# see the README file.
#

BEGIN {
	PTXDIST_TEMPDIR		= ENVIRON["PTXDIST_TEMPDIR"];
	dirs = ""
}

$1 == "PATCHES:" {
	pkg = $2
	patch_dir = $3
	pkgs[patch_dir]  = pkgs[patch_dir] " " pkg
	dirs = dirs " " patch_dir
}

$1 == "CONFIG:" {
	pkg = $2
	config = $3
	configs[pkg] = configs[pkg] " " config
}

function dump_file(src, dst, tmp) {
	if (!src)
		return

	old_RS = RS
	RS = "^$"
	getline tmp < src
	printf "%s", tmp >> dst
	RS = old_RS
	close(src)
	close(dst)
}

END {
	for (pkg in configs) {
		config = configs[pkg]
		f1 = PTXDIST_TEMPDIR "/pkghash-" pkg
		split(configs[pkg], cfgs)
		asort(cfgs, cfgs)
		for (config in cfgs)
			dump_file(cfgs[config], f1)
	}
	command = "find " dirs " -type f ! -name '.*' -printf '%H %P\\n'"
	while (command | getline)
		files[$1] = files[$1] " " $2
	close(command)
	for (dir in pkgs) {
		split(pkgs[dir], list, " ")
		split(files[dir], file_list, " ")
		asort(file_list, file_list)
		for (pkg in list) {
			pkg = list[pkg]
			f1 = PTXDIST_TEMPDIR "/pkghash-" pkg
			f2 = PTXDIST_TEMPDIR "/pkghash-" pkg "_EXTRACT"
			for (file in file_list) {
				file = dir "/" file_list[file]
				dump_file(file, f1)
				dump_file(file, f2)
			}
		}
	}
}