2 * Copyright 1993-2002 Christopher Seiwald and Perforce Software, Inc.
3 * This file is part of Jam - see jam.c for Copyright information.
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, version 3 of the License ONLY.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 * search.c - find a target along $(SEARCH) or $(LOCATE)
23 #include "timestamp.h"
31 static void call_bind_rule (const char *target
, const char *boundname
) {
32 LIST
*bind_rule
= var_get("BINDRULE");
36 lol_add(&lol
, list_new(L0
, target
, 1));
37 lol_add(&lol
, list_new(L0
, boundname
, 1));
38 if (lol_get(&lol
, 1)) list_free(evaluate_rule(bind_rule
->string
, &lol
, L0
));
44 const char *search (const char *target
, time_t *time
) {
47 static char buf
[MAXJPATH
];
48 /* parse the filename */
49 path_parse(target
, f
);
52 if ((varlist
= var_get("LOCATE"))) {
53 f
->f_root
.ptr
= varlist
->string
;
54 f
->f_root
.len
= strlen(varlist
->string
);
55 path_build(buf
, f
); /* was with binding, but it does nothing now */
56 if (DEBUG_SEARCH
) printf("locate %s: %s\n", target
, buf
);
60 if ((varlist
= var_get("SEARCH"))) {
62 f
->f_root
.ptr
= varlist
->string
;
63 f
->f_root
.len
= strlen(varlist
->string
);
64 path_build(buf
, f
); /* was with binding, but it does nothing now */
65 if (DEBUG_SEARCH
) printf("search %s: %s\n", target
, buf
);
67 if (*time
) return newstr(buf
);
68 varlist
= list_next(varlist
);
71 /* look for the obvious */
72 /* this is a questionable move: should we look in the obvious place if SEARCH is set? */
75 path_build(buf
, f
); /* was with binding, but it does nothing now */
76 if (DEBUG_SEARCH
) printf("search %s: %s\n", target
, buf
);
78 call_bind_rule(target
, buf
);