summaryrefslogtreecommitdiffstats
path: root/scripts/lib/ptxd_make_world_install_mangle_pc.awk
blob: b569e8a6173a01c0d9c395d0d7e6156c76cc7484 (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
#!/usr/bin/gawk -f
#
# Copyright (C) 2009 by Marc Kleine-Budde <mkl@pengutronix.de>
#
# See CREDITS for details about who has contributed to this project.
#
# For further information about the PTXdist project and license conditions
# see the README file.
#

BEGIN {
	FS = "([[:space:]]|=)[[:space:]]*";

	SYSROOT	= ENVIRON["pkg_sysroot_dir"];
	pkg_pkg_dir = ENVIRON["pkg_pkg_dir"];

	# quote "+" and "/"
	q_pkg_pkg_dir = gensub(/([+/])/, "\\\\\\1", "g", ENVIRON["pkg_pkg_dir"]);

	replace["prefix"]	= "${pcfiledir}/../..";
	replace["exec_prefix"]	= "${prefix}";
	replace["libdir"]	= "${prefix}/lib";
	replace["includedir"]	= "${prefix}/include";

	replace[SYSROOT "/include"]	= replace["includedir"]
	replace[SYSROOT "/lib"]		= replace["libdir"]
}


FNR == 1 {
	this_regex = "^" q_pkg_pkg_dir "(.*)lib\\/pkgconfig\\/.*";

	#
	# first remove pkg_pkg_dir
	#
	prefix = gensub(this_regex, "\\1", 1, FILENAME);
	replace[prefix "include"] = replace["includedir"];
	replace[prefix "lib"]     = replace["libdir"];

	rel_sysroot = replace["prefix"] gensub(/\/[^/]+/, "/..", "g", prefix);


	# delete file, in order to rename "in-place"
	system("rm " FILENAME);
}

$1 ~ /^(prefix|exec_prefix)$/ {
	print $1 "=" replace[$1]				> FILENAME;
	next;
}

$1 ~ /^(includedir|libdir)$/ {
	# replace e.g. /usr/include
	if (match($2, "^" "(" prefix "|" SYSROOT "/" ")" "(include|lib)")) {
		this_var = substr($2, RSTART, RLENGTH);
		sub(this_var, replace[this_var]);
	}

	print $0						> FILENAME;
	next;
}


$1 ~ /^(Libs(\.private)?|Cflags):$/ {
	this_regex = "(-[LI])(" SYSROOT "|" pkg_pkg_dir")/";

	#
	# replace absolute path by relative ones
	#
	print gensub(this_regex, "\\1" rel_sysroot, "g")	> FILENAME;
	next;
}

{
	print $0						> FILENAME;
}