Fixup fromcvs/togit conversion
[minix-pkgsrc.git] / mk / pkgformat / pkg / reduce-resolved-depends.awk
blobc17114bfb1aded4c98a387af6f64a3f8f421a296
1 #!/usr/bin/awk -f
3 # $NetBSD: reduce-resolved-depends.awk,v 1.1 2012/07/02 14:53:13 joerg Exp $
5 # Copyright (c) 2012 The NetBSD Foundation, Inc.
6 # All rights reserved.
8 # This code is derived from software contributed to The NetBSD Foundation
9 # by Joerg Sonnenberger.
11 # Redistribution and use in source and binary forms, with or without
12 # modification, are permitted provided that the following conditions
13 # are met:
14 # 1. Redistributions of source code must retain the above copyright
15 # notice, this list of conditions and the following disclaimer.
16 # 2. Redistributions in binary form must reproduce the above copyright
17 # notice, this list of conditions and the following disclaimer in the
18 # documentation and/or other materials provided with the distribution.
20 # THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
21 # ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
22 # TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23 # PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
24 # BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25 # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26 # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27 # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28 # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29 # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30 # POSSIBILITY OF SUCH DAMAGE.
33 ######################################################################
35 # NAME
36 # reduce-resolved-depends.awk -- drop redundant build dependencies
38 # SYNOPSIS
39 # reduce-resolved-depends.awk
41 # DESCRIPTION
42 # reduce-resolved-depends.awk removes build dependencies from the
43 # dependency list on stdin, if they provided as dependency of
44 # one of the full dependencies in the list.
46 # ENVIRONMENT
47 # CAT
48 # PKG_INFO
49 # HOST_PKG_INFO (for cross-compilation)
51 ######################################################################
53 BEGIN {
54 CAT = ENVIRON["CAT"] ? ENVIRON["CAT"] : "cat"
55 PKG_INFO = ENVIRON["PKG_INFO"] ? ENVIRON["PKG_INFO"] : "pkg_info"
56 HOST_PKG_INFO = ENVIRON["HOST_PKG_INFO"] ? ENVIRON["HOST_PKG_INFO"] : "pkg_info"
58 PROGNAME = "reduce-resolved-depends.awk"
59 ERRCAT = CAT " 1>&2"
61 while (getline == 1) {
62 if (NF != 3) {
63 print "ERROR: [" PROGNAME "] invalid dependency line " $0 | ERRCAT
64 exit 1
66 if ($1 != "full" &&
67 $1 != "build" &&
68 $1 != "tool" &&
69 $1 != "bootstrap") {
70 print "ERROR: [" PROGNAME "] invalid dependency line " $0 | ERRCAT
71 exit 1
73 type[NR] = $1
74 pattern[NR] = $2
75 pkg[NR] = $3
77 lines = NR + 1
79 # Register all full dependencies first.
80 # Keep track of the first line for each of them to skip duplicates later.
81 for (i = 0; i < lines; ++i) {
82 if (type[i] == "full" && checked_full[pkg[i]] != 1) {
83 checked_full[pkg[i]] = 1
84 checked_build[pkg[i]] = 1
85 checked_tool[pkg[i]] = 1
86 checked_bootstrap[pkg[i]] = 1
87 print_line[i] = 1
91 for (i = 0; i < lines; ++i) {
92 if (type[i] == "bootstrap" && checked_bootstrap[pkg[i]] != 1) {
93 checked_bootstrap[pkg[i]] = 1
94 found = 0
95 if (PKG_INFO == HOST_PKG_INFO) {
96 cmd = PKG_INFO " -qr " pkg[i]
97 while (cmd | getline dpkg) {
98 if (checked_full[dpkg] == 1)
99 found = 1
101 close(cmd)
103 if (found == 0)
104 print_line[i] = 1
108 for (i = 0; i < lines; ++i) {
109 if (type[i] == "tool" && checked_tool[pkg[i]] != 1) {
110 checked_tool[pkg[i]] = 1
111 if (checked_bootstrap[pkg[i]] == 1)
112 continue
113 found = 0
114 if (PKG_INFO == HOST_PKG_INFO) {
115 cmd = PKG_INFO " -qr " pkg[i]
116 while (cmd | getline dpkg) {
117 if (checked_full[dpkg] == 1)
118 found = 1
120 close(cmd)
122 if (found == 0)
123 print_line[i] = 1
127 for (i = 0; i < lines; ++i) {
128 if (type[i] == "build" && checked_build[pkg[i]] != 1) {
129 checked_build[pkg[i]] = 1
130 if (PKG_INFO == HOST_PKG_INFO)
131 if (checked_bootstrap[pkg[i]] == 1)
132 continue
133 found = 0
134 cmd = PKG_INFO " -qr " pkg[i]
135 while (cmd | getline dpkg) {
136 if (checked_full[dpkg] == 1)
137 found = 1
139 close(cmd)
140 if (found == 0)
141 print_line[i] = 1
145 for (i = 0; i < lines; ++i) {
146 if (print_line[i] == 1)
147 printf("%s\t%s\t%s\n", type[i], pattern[i], pkg[i])