fixed pkg-config rule
[k8jam.git] / src / search.c
blobc4f8bd837623cb7cb2b9a7101fd5c6273db5d1f2
1 /*
2 * Copyright 1993-2002 Christopher Seiwald and Perforce Software, Inc.
4 * This file is part of Jam - see jam.c for Copyright information.
5 */
6 /*
7 * search.c - find a target along $(SEARCH) or $(LOCATE)
9 * 11/04/02 (seiwald) - const-ing for string literals
11 #include "jam.h"
12 #include "lists.h"
13 #include "search.h"
14 #include "timestamp.h"
15 #include "pathsys.h"
16 #include "variable.h"
17 #include "newstr.h"
20 const char *search (const char *target, time_t *time) {
21 PATHNAME f[1];
22 LIST *varlist;
23 char buf[MAXJPATH];
25 /* parse the filename */
26 path_parse(target, f);
27 f->f_grist.ptr = 0;
28 f->f_grist.len = 0;
29 if ((varlist = var_get("LOCATE"))) {
30 f->f_root.ptr = varlist->string;
31 f->f_root.len = strlen(varlist->string);
32 path_build(f, buf, 1);
33 if (DEBUG_SEARCH) printf("locate %s: %s\n", target, buf);
34 timestamp(buf, time);
35 return newstr(buf);
37 if ((varlist = var_get("SEARCH"))) {
38 while (varlist) {
39 f->f_root.ptr = varlist->string;
40 f->f_root.len = strlen(varlist->string);
41 path_build(f, buf, 1);
42 if (DEBUG_SEARCH) printf("search %s: %s\n", target, buf);
43 timestamp(buf, time);
44 if (*time) return newstr(buf);
45 varlist = list_next(varlist);
48 /* look for the obvious */
49 /* this is a questionable move: should we look in the obvious place if SEARCH is set? */
50 f->f_root.ptr = 0;
51 f->f_root.len = 0;
52 path_build(f, buf, 1);
53 if (DEBUG_SEARCH) printf("search %s: %s\n", target, buf);
54 timestamp(buf, time);
55 return newstr(buf);