4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
23 * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
29 #include <sys/param.h>
42 static pkg_list
*packages
[HASH_SIZE
];
44 #define HASH(name) (hash(name) % HASH_SIZE)
47 processed_package(const char *pkgname
)
52 bucket
= HASH(pkgname
);
53 for (tmp
= packages
[bucket
]; tmp
!= NULL
; tmp
= tmp
->next
) {
54 if (strcmp(tmp
->pkg_name
, pkgname
) == 0)
61 mark_processed(const char *pkgname
)
66 bucket
= HASH(pkgname
);
67 tmp
= malloc(sizeof (pkg_list
));
68 bzero(tmp
, sizeof (pkg_list
));
69 (void) strcpy(tmp
->pkg_name
, pkgname
);
70 tmp
->next
= packages
[bucket
];
71 packages
[bucket
] = tmp
;
75 add_dependency(pkg_list
*dependlist
, const char *pkgname
)
80 pkg
= malloc(sizeof (pkg_list
));
81 bzero(pkg
, sizeof (pkg_list
));
82 (void) strcpy(pkg
->pkg_name
, pkgname
);
85 if (dependlist
== NULL
)
87 /* insert at end, since the order matters */
88 for (tmp
= dependlist
; tmp
->next
!= NULL
; tmp
= tmp
->next
) {
96 free_dependency_list(pkg_list
*dependlist
)
102 dependlist
= dependlist
->next
;
110 print_dependencies(const char *pkgname
, pkg_list
*dependlist
)
114 fprintf(stderr
, "%s:", pkgname
);
115 for (tmp
= dependlist
; tmp
!= NULL
; tmp
= tmp
->next
)
116 fprintf(stderr
, " %s", tmp
->pkg_name
);
117 fprintf(stderr
, "\n");
121 static char *suffix_list
[] = {
124 #elif defined(__sparc)
131 #error "Unknown architecture."
137 find_dependencies(const char *pkgname
, const char *parentdir
)
139 char dependfile
[MAXPATHLEN
+ 1];
140 char pkgdir
[MAXPATHLEN
+ 1];
142 char deppkg
[MAXNAME
];
143 char archpkg
[MAXNAME
];
146 pkg_list
*dependlist
= NULL
;
149 (void) sprintf(dependfile
, "%s/%s/depend", parentdir
, pkgname
);
150 fp
= fopen(dependfile
, "r");
153 * depend won't exist in ON packages until a build
154 * has been done, but it would be nice if you didn't have
155 * to do that. So try the generic depend file that those
156 * packages would copy in during the build.
158 (void) sprintf(dependfile
, "%s/common_files/depend", parentdir
);
159 fp
= fopen(dependfile
, "r");
163 while (fgets(buf
, BUFSIZ
, fp
) != NULL
) {
164 if ((buf
[0] == '\0') || (buf
[0] == '#') || isspace(buf
[0]))
166 /* we only care about prerequisites */
169 (void) sscanf(buf
, "P %s", deppkg
);
171 * We have to be careful with some of the packages that are
172 * listed as dependencies but exist under a different name -
173 * SUNWcar is good, because it's actually SUNWcar.{c,d,i,m,u}.
174 * What do we do there? We can't just go for all the '.'
175 * packages, since on x86 we only want the .i one, and on sparc
176 * we want everything _but_ .i. Maybe
178 * I think perhaps what we do is, if we don't find a package
179 * dependency, on intel we append '.i' and try for that, and on
180 * sparc we try the other extensions. Any we find get added.
182 * Note also we're quiet on failures. This is because you might
183 * be dependant on some outside package.
185 (void) sprintf(pkgdir
, "%s/%s", parentdir
, deppkg
);
186 if (stat(pkgdir
, &sbuf
) == -1) {
187 if (errno
!= ENOENT
) {
190 for (suffixes
= &suffix_list
[0]; *suffixes
!= NULL
;
192 (void) sprintf(archpkg
, "%s%s", deppkg
,
194 (void) sprintf(pkgdir
, "%s/%s", parentdir
,
196 if (stat(pkgdir
, &sbuf
) == -1) {
199 if (!S_ISDIR(sbuf
.st_mode
)) {
203 dependlist
= add_dependency(dependlist
,
207 if (!S_ISDIR(sbuf
.st_mode
)) {
210 dependlist
= add_dependency(dependlist
, deppkg
);
217 process_dependencies(const char *pkgname
, const char *parentdir
,
218 elem_list
*list
, int verbose
)
221 char pkgdir
[MAXPATHLEN
+ 1];
222 pkg_list
*dependlist
;
225 dependlist
= find_dependencies(pkgname
, parentdir
);
227 * print_dependencies(pkgname, dependlist);
229 if (dependlist
== NULL
)
232 for (tmp
= dependlist
; tmp
!= NULL
; tmp
= tmp
->next
) {
233 (void) sprintf(pkgdir
, "%s/%s", parentdir
, tmp
->pkg_name
);
234 count
+= process_package_dir(tmp
->pkg_name
, pkgdir
, list
,
238 free_dependency_list(dependlist
);