| 1 | /* Basic dependency engine for GNU Make.
|
|---|
| 2 | Copyright (C) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1999,
|
|---|
| 3 | 2002 Free Software Foundation, Inc.
|
|---|
| 4 | This file is part of GNU Make.
|
|---|
| 5 |
|
|---|
| 6 | GNU Make is free software; you can redistribute it and/or modify
|
|---|
| 7 | it under the terms of the GNU General Public License as published by
|
|---|
| 8 | the Free Software Foundation; either version 2, or (at your option)
|
|---|
| 9 | any later version.
|
|---|
| 10 |
|
|---|
| 11 | GNU Make is distributed in the hope that it will be useful,
|
|---|
| 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|---|
| 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|---|
| 14 | GNU General Public License for more details.
|
|---|
| 15 |
|
|---|
| 16 | You should have received a copy of the GNU General Public License
|
|---|
| 17 | along with GNU Make; see the file COPYING. If not, write to
|
|---|
| 18 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|---|
| 19 | Boston, MA 02111-1307, USA. */
|
|---|
| 20 |
|
|---|
| 21 | #include "make.h"
|
|---|
| 22 | #include "filedef.h"
|
|---|
| 23 | #include "job.h"
|
|---|
| 24 | #include "commands.h"
|
|---|
| 25 | #include "dep.h"
|
|---|
| 26 | #include "variable.h"
|
|---|
| 27 | #include "debug.h"
|
|---|
| 28 |
|
|---|
| 29 | #include <assert.h>
|
|---|
| 30 |
|
|---|
| 31 | #ifdef HAVE_FCNTL_H
|
|---|
| 32 | #include <fcntl.h>
|
|---|
| 33 | #else
|
|---|
| 34 | #include <sys/file.h>
|
|---|
| 35 | #endif
|
|---|
| 36 |
|
|---|
| 37 | #ifdef VMS
|
|---|
| 38 | #include <starlet.h>
|
|---|
| 39 | #endif
|
|---|
| 40 | #ifdef WINDOWS32
|
|---|
| 41 | #include <io.h>
|
|---|
| 42 | #endif
|
|---|
| 43 |
|
|---|
| 44 | extern int try_implicit_rule PARAMS ((struct file *file, unsigned int depth));
|
|---|
| 45 |
|
|---|
| 46 |
|
|---|
| 47 | /* The test for circular dependencies is based on the 'updating' bit in
|
|---|
| 48 | `struct file'. However, double colon targets have seperate `struct
|
|---|
| 49 | file's; make sure we always use the base of the double colon chain. */
|
|---|
| 50 |
|
|---|
| 51 | #define start_updating(_f) (((_f)->double_colon ? (_f)->double_colon : (_f))\
|
|---|
| 52 | ->updating = 1)
|
|---|
| 53 | #define finish_updating(_f) (((_f)->double_colon ? (_f)->double_colon : (_f))\
|
|---|
| 54 | ->updating = 0)
|
|---|
| 55 | #define is_updating(_f) (((_f)->double_colon ? (_f)->double_colon : (_f))\
|
|---|
| 56 | ->updating)
|
|---|
| 57 |
|
|---|
| 58 |
|
|---|
| 59 | /* Incremented when a command is started (under -n, when one would be). */
|
|---|
| 60 | unsigned int commands_started = 0;
|
|---|
| 61 |
|
|---|
| 62 | /* Current value for pruning the scan of the goal chain (toggle 0/1). */
|
|---|
| 63 | static unsigned int considered;
|
|---|
| 64 |
|
|---|
| 65 | static int update_file PARAMS ((struct file *file, unsigned int depth));
|
|---|
| 66 | static int update_file_1 PARAMS ((struct file *file, unsigned int depth));
|
|---|
| 67 | static int check_dep PARAMS ((struct file *file, unsigned int depth, FILE_TIMESTAMP this_mtime, int *must_make_ptr));
|
|---|
| 68 | static int touch_file PARAMS ((struct file *file));
|
|---|
| 69 | static void remake_file PARAMS ((struct file *file));
|
|---|
| 70 | static FILE_TIMESTAMP name_mtime PARAMS ((char *name));
|
|---|
| 71 | static int library_search PARAMS ((char **lib, FILE_TIMESTAMP *mtime_ptr));
|
|---|
| 72 |
|
|---|
| 73 | |
|---|
| 74 |
|
|---|
| 75 | /* Remake all the goals in the `struct dep' chain GOALS. Return -1 if nothing
|
|---|
| 76 | was done, 0 if all goals were updated successfully, or 1 if a goal failed.
|
|---|
| 77 | If MAKEFILES is nonzero, these goals are makefiles, so -t, -q, and -n should
|
|---|
| 78 | be disabled for them unless they were also command-line targets, and we
|
|---|
| 79 | should only make one goal at a time and return as soon as one goal whose
|
|---|
| 80 | `changed' member is nonzero is successfully made. */
|
|---|
| 81 |
|
|---|
| 82 | int
|
|---|
| 83 | update_goal_chain (struct dep *goals, int makefiles)
|
|---|
| 84 | {
|
|---|
| 85 | int t = touch_flag, q = question_flag, n = just_print_flag;
|
|---|
| 86 | unsigned int j = job_slots;
|
|---|
| 87 | int status = -1;
|
|---|
| 88 |
|
|---|
| 89 | #define MTIME(file) (makefiles ? file_mtime_no_search (file) \
|
|---|
| 90 | : file_mtime (file))
|
|---|
| 91 |
|
|---|
| 92 | /* Duplicate the chain so we can remove things from it. */
|
|---|
| 93 |
|
|---|
| 94 | goals = copy_dep_chain (goals);
|
|---|
| 95 |
|
|---|
| 96 | {
|
|---|
| 97 | /* Clear the `changed' flag of each goal in the chain.
|
|---|
| 98 | We will use the flag below to notice when any commands
|
|---|
| 99 | have actually been run for a target. When no commands
|
|---|
| 100 | have been run, we give an "up to date" diagnostic. */
|
|---|
| 101 |
|
|---|
| 102 | struct dep *g;
|
|---|
| 103 | for (g = goals; g != 0; g = g->next)
|
|---|
| 104 | g->changed = 0;
|
|---|
| 105 | }
|
|---|
| 106 |
|
|---|
| 107 | /* All files start with the considered bit 0, so the global value is 1. */
|
|---|
| 108 | considered = 1;
|
|---|
| 109 |
|
|---|
| 110 | /* Update all the goals until they are all finished. */
|
|---|
| 111 |
|
|---|
| 112 | while (goals != 0)
|
|---|
| 113 | {
|
|---|
| 114 | register struct dep *g, *lastgoal;
|
|---|
| 115 |
|
|---|
| 116 | /* Start jobs that are waiting for the load to go down. */
|
|---|
| 117 |
|
|---|
| 118 | start_waiting_jobs ();
|
|---|
| 119 |
|
|---|
| 120 | /* Wait for a child to die. */
|
|---|
| 121 |
|
|---|
| 122 | reap_children (1, 0);
|
|---|
| 123 |
|
|---|
| 124 | lastgoal = 0;
|
|---|
| 125 | g = goals;
|
|---|
| 126 | while (g != 0)
|
|---|
| 127 | {
|
|---|
| 128 | /* Iterate over all double-colon entries for this file. */
|
|---|
| 129 | struct file *file;
|
|---|
| 130 | int stop = 0, any_not_updated = 0;
|
|---|
| 131 |
|
|---|
| 132 | for (file = g->file->double_colon ? g->file->double_colon : g->file;
|
|---|
| 133 | file != NULL;
|
|---|
| 134 | file = file->prev)
|
|---|
| 135 | {
|
|---|
| 136 | unsigned int ocommands_started;
|
|---|
| 137 | int x;
|
|---|
| 138 | check_renamed (file);
|
|---|
| 139 | if (makefiles)
|
|---|
| 140 | {
|
|---|
| 141 | if (file->cmd_target)
|
|---|
| 142 | {
|
|---|
| 143 | touch_flag = t;
|
|---|
| 144 | question_flag = q;
|
|---|
| 145 | just_print_flag = n;
|
|---|
| 146 | }
|
|---|
| 147 | else
|
|---|
| 148 | touch_flag = question_flag = just_print_flag = 0;
|
|---|
| 149 | }
|
|---|
| 150 |
|
|---|
| 151 | /* Save the old value of `commands_started' so we can compare
|
|---|
| 152 | later. It will be incremented when any commands are
|
|---|
| 153 | actually run. */
|
|---|
| 154 | ocommands_started = commands_started;
|
|---|
| 155 |
|
|---|
| 156 | x = update_file (file, makefiles ? 1 : 0);
|
|---|
| 157 | check_renamed (file);
|
|---|
| 158 |
|
|---|
| 159 | /* Set the goal's `changed' flag if any commands were started
|
|---|
| 160 | by calling update_file above. We check this flag below to
|
|---|
| 161 | decide when to give an "up to date" diagnostic. */
|
|---|
| 162 | g->changed += commands_started - ocommands_started;
|
|---|
| 163 |
|
|---|
| 164 | /* If we updated a file and STATUS was not already 1, set it to
|
|---|
| 165 | 1 if updating failed, or to 0 if updating succeeded. Leave
|
|---|
| 166 | STATUS as it is if no updating was done. */
|
|---|
| 167 |
|
|---|
| 168 | stop = 0;
|
|---|
| 169 | if ((x != 0 || file->updated) && status < 1)
|
|---|
| 170 | {
|
|---|
| 171 | if (file->update_status != 0)
|
|---|
| 172 | {
|
|---|
| 173 | /* Updating failed, or -q triggered. The STATUS value
|
|---|
| 174 | tells our caller which. */
|
|---|
| 175 | status = file->update_status;
|
|---|
| 176 | /* If -q just triggered, stop immediately. It doesn't
|
|---|
| 177 | matter how much more we run, since we already know
|
|---|
| 178 | the answer to return. */
|
|---|
| 179 | stop = (!keep_going_flag && !question_flag
|
|---|
| 180 | && !makefiles);
|
|---|
| 181 | }
|
|---|
| 182 | else
|
|---|
| 183 | {
|
|---|
| 184 | FILE_TIMESTAMP mtime = MTIME (file);
|
|---|
| 185 | check_renamed (file);
|
|---|
| 186 |
|
|---|
| 187 | if (file->updated && g->changed &&
|
|---|
| 188 | mtime != file->mtime_before_update)
|
|---|
| 189 | {
|
|---|
| 190 | /* Updating was done. If this is a makefile and
|
|---|
| 191 | just_print_flag or question_flag is set (meaning
|
|---|
| 192 | -n or -q was given and this file was specified
|
|---|
| 193 | as a command-line target), don't change STATUS.
|
|---|
| 194 | If STATUS is changed, we will get re-exec'd, and
|
|---|
| 195 | enter an infinite loop. */
|
|---|
| 196 | if (!makefiles
|
|---|
| 197 | || (!just_print_flag && !question_flag))
|
|---|
| 198 | status = 0;
|
|---|
| 199 | if (makefiles && file->dontcare)
|
|---|
| 200 | /* This is a default makefile; stop remaking. */
|
|---|
| 201 | stop = 1;
|
|---|
| 202 | }
|
|---|
| 203 | }
|
|---|
| 204 | }
|
|---|
| 205 |
|
|---|
| 206 | /* Keep track if any double-colon entry is not finished.
|
|---|
| 207 | When they are all finished, the goal is finished. */
|
|---|
| 208 | any_not_updated |= !file->updated;
|
|---|
| 209 |
|
|---|
| 210 | if (stop)
|
|---|
| 211 | break;
|
|---|
| 212 | }
|
|---|
| 213 |
|
|---|
| 214 | /* Reset FILE since it is null at the end of the loop. */
|
|---|
| 215 | file = g->file;
|
|---|
| 216 |
|
|---|
| 217 | if (stop || !any_not_updated)
|
|---|
| 218 | {
|
|---|
| 219 | /* If we have found nothing whatever to do for the goal,
|
|---|
| 220 | print a message saying nothing needs doing. */
|
|---|
| 221 |
|
|---|
| 222 | if (!makefiles
|
|---|
| 223 | /* If the update_status is zero, we updated successfully
|
|---|
| 224 | or not at all. G->changed will have been set above if
|
|---|
| 225 | any commands were actually started for this goal. */
|
|---|
| 226 | && file->update_status == 0 && !g->changed
|
|---|
| 227 | /* Never give a message under -s or -q. */
|
|---|
| 228 | && !silent_flag && !question_flag)
|
|---|
| 229 | message (1, ((file->phony || file->cmds == 0)
|
|---|
| 230 | ? _("Nothing to be done for `%s'.")
|
|---|
| 231 | : _("`%s' is up to date.")),
|
|---|
| 232 | file->name);
|
|---|
| 233 |
|
|---|
| 234 | /* This goal is finished. Remove it from the chain. */
|
|---|
| 235 | if (lastgoal == 0)
|
|---|
| 236 | goals = g->next;
|
|---|
| 237 | else
|
|---|
| 238 | lastgoal->next = g->next;
|
|---|
| 239 |
|
|---|
| 240 | /* Free the storage. */
|
|---|
| 241 | free ((char *) g);
|
|---|
| 242 |
|
|---|
| 243 | g = lastgoal == 0 ? goals : lastgoal->next;
|
|---|
| 244 |
|
|---|
| 245 | if (stop)
|
|---|
| 246 | break;
|
|---|
| 247 | }
|
|---|
| 248 | else
|
|---|
| 249 | {
|
|---|
| 250 | lastgoal = g;
|
|---|
| 251 | g = g->next;
|
|---|
| 252 | }
|
|---|
| 253 | }
|
|---|
| 254 |
|
|---|
| 255 | /* If we reached the end of the dependency graph toggle the considered
|
|---|
| 256 | flag for the next pass. */
|
|---|
| 257 | if (g == 0)
|
|---|
| 258 | considered = !considered;
|
|---|
| 259 | }
|
|---|
| 260 |
|
|---|
| 261 | if (makefiles)
|
|---|
| 262 | {
|
|---|
| 263 | touch_flag = t;
|
|---|
| 264 | question_flag = q;
|
|---|
| 265 | just_print_flag = n;
|
|---|
| 266 | job_slots = j;
|
|---|
| 267 | }
|
|---|
| 268 | return status;
|
|---|
| 269 | }
|
|---|
| 270 | |
|---|
| 271 |
|
|---|
| 272 | /* If FILE is not up to date, execute the commands for it.
|
|---|
| 273 | Return 0 if successful, 1 if unsuccessful;
|
|---|
| 274 | but with some flag settings, just call `exit' if unsuccessful.
|
|---|
| 275 |
|
|---|
| 276 | DEPTH is the depth in recursions of this function.
|
|---|
| 277 | We increment it during the consideration of our dependencies,
|
|---|
| 278 | then decrement it again after finding out whether this file
|
|---|
| 279 | is out of date.
|
|---|
| 280 |
|
|---|
| 281 | If there are multiple double-colon entries for FILE,
|
|---|
| 282 | each is considered in turn. */
|
|---|
| 283 |
|
|---|
| 284 | static int
|
|---|
| 285 | update_file (struct file *file, unsigned int depth)
|
|---|
| 286 | {
|
|---|
| 287 | register int status = 0;
|
|---|
| 288 | register struct file *f;
|
|---|
| 289 |
|
|---|
| 290 | f = file->double_colon ? file->double_colon : file;
|
|---|
| 291 |
|
|---|
| 292 | /* Prune the dependency graph: if we've already been here on _this_
|
|---|
| 293 | pass through the dependency graph, we don't have to go any further.
|
|---|
| 294 | We won't reap_children until we start the next pass, so no state
|
|---|
| 295 | change is possible below here until then. */
|
|---|
| 296 | if (f->considered == considered)
|
|---|
| 297 | {
|
|---|
| 298 | DBF (DB_VERBOSE, _("Pruning file `%s'.\n"));
|
|---|
| 299 | return f->command_state == cs_finished ? f->update_status : 0;
|
|---|
| 300 | }
|
|---|
| 301 |
|
|---|
| 302 | /* This loop runs until we start commands for a double colon rule, or until
|
|---|
| 303 | the chain is exhausted. */
|
|---|
| 304 | for (; f != 0; f = f->prev)
|
|---|
| 305 | {
|
|---|
| 306 | f->considered = considered;
|
|---|
| 307 |
|
|---|
| 308 | status |= update_file_1 (f, depth);
|
|---|
| 309 | check_renamed (f);
|
|---|
| 310 |
|
|---|
| 311 | if (status != 0 && !keep_going_flag)
|
|---|
| 312 | break;
|
|---|
| 313 |
|
|---|
| 314 | if (f->command_state == cs_running
|
|---|
| 315 | || f->command_state == cs_deps_running)
|
|---|
| 316 | {
|
|---|
| 317 | /* Don't run the other :: rules for this
|
|---|
| 318 | file until this rule is finished. */
|
|---|
| 319 | status = 0;
|
|---|
| 320 | break;
|
|---|
| 321 | }
|
|---|
| 322 | }
|
|---|
| 323 |
|
|---|
| 324 | /* Process the remaining rules in the double colon chain so they're marked
|
|---|
| 325 | considered. Start their prerequisites, too. */
|
|---|
| 326 | for (; f != 0 ; f = f->prev)
|
|---|
| 327 | {
|
|---|
| 328 | struct dep *d;
|
|---|
| 329 |
|
|---|
| 330 | f->considered = considered;
|
|---|
| 331 |
|
|---|
| 332 | for (d = f->deps; d != 0; d = d->next)
|
|---|
| 333 | status |= update_file (d->file, depth + 1);
|
|---|
| 334 | }
|
|---|
| 335 |
|
|---|
| 336 | return status;
|
|---|
| 337 | }
|
|---|
| 338 | |
|---|
| 339 |
|
|---|
| 340 | /* Consider a single `struct file' and update it as appropriate. */
|
|---|
| 341 |
|
|---|
| 342 | static int
|
|---|
| 343 | update_file_1 (struct file *file, unsigned int depth)
|
|---|
| 344 | {
|
|---|
| 345 | register FILE_TIMESTAMP this_mtime;
|
|---|
| 346 | int noexist, must_make, deps_changed;
|
|---|
| 347 | int dep_status = 0;
|
|---|
| 348 | register struct dep *d, *lastd;
|
|---|
| 349 | int running = 0;
|
|---|
| 350 |
|
|---|
| 351 | DBF (DB_VERBOSE, _("Considering target file `%s'.\n"));
|
|---|
| 352 |
|
|---|
| 353 | if (file->updated)
|
|---|
| 354 | {
|
|---|
| 355 | if (file->update_status > 0)
|
|---|
| 356 | {
|
|---|
| 357 | DBF (DB_VERBOSE,
|
|---|
| 358 | _("Recently tried and failed to update file `%s'.\n"));
|
|---|
| 359 | return file->update_status;
|
|---|
| 360 | }
|
|---|
| 361 |
|
|---|
| 362 | DBF (DB_VERBOSE, _("File `%s' was considered already.\n"));
|
|---|
| 363 | return 0;
|
|---|
| 364 | }
|
|---|
| 365 |
|
|---|
| 366 | switch (file->command_state)
|
|---|
| 367 | {
|
|---|
| 368 | case cs_not_started:
|
|---|
| 369 | case cs_deps_running:
|
|---|
| 370 | break;
|
|---|
| 371 | case cs_running:
|
|---|
| 372 | DBF (DB_VERBOSE, _("Still updating file `%s'.\n"));
|
|---|
| 373 | return 0;
|
|---|
| 374 | case cs_finished:
|
|---|
| 375 | DBF (DB_VERBOSE, _("Finished updating file `%s'.\n"));
|
|---|
| 376 | return file->update_status;
|
|---|
| 377 | default:
|
|---|
| 378 | abort ();
|
|---|
| 379 | }
|
|---|
| 380 |
|
|---|
| 381 | ++depth;
|
|---|
| 382 |
|
|---|
| 383 | /* Notice recursive update of the same file. */
|
|---|
| 384 | start_updating (file);
|
|---|
| 385 |
|
|---|
| 386 | /* Looking at the file's modtime beforehand allows the possibility
|
|---|
| 387 | that its name may be changed by a VPATH search, and thus it may
|
|---|
| 388 | not need an implicit rule. If this were not done, the file
|
|---|
| 389 | might get implicit commands that apply to its initial name, only
|
|---|
| 390 | to have that name replaced with another found by VPATH search. */
|
|---|
| 391 |
|
|---|
| 392 | this_mtime = file_mtime (file);
|
|---|
| 393 | check_renamed (file);
|
|---|
| 394 | noexist = this_mtime == NONEXISTENT_MTIME;
|
|---|
| 395 | if (noexist)
|
|---|
| 396 | DBF (DB_BASIC, _("File `%s' does not exist.\n"));
|
|---|
| 397 | else if (ORDINARY_MTIME_MIN <= this_mtime && this_mtime <= ORDINARY_MTIME_MAX
|
|---|
| 398 | && file->low_resolution_time)
|
|---|
| 399 | {
|
|---|
| 400 | /* Avoid spurious rebuilds due to low resolution time stamps. */
|
|---|
| 401 | int ns = FILE_TIMESTAMP_NS (this_mtime);
|
|---|
| 402 | if (ns != 0)
|
|---|
| 403 | error (NILF, _("*** Warning: .LOW_RESOLUTION_TIME file `%s' has a high resolution time stamp"),
|
|---|
| 404 | file->name);
|
|---|
| 405 | this_mtime += FILE_TIMESTAMPS_PER_S - 1 - ns;
|
|---|
| 406 | }
|
|---|
| 407 |
|
|---|
| 408 | must_make = noexist;
|
|---|
| 409 |
|
|---|
| 410 | /* If file was specified as a target with no commands,
|
|---|
| 411 | come up with some default commands. */
|
|---|
| 412 |
|
|---|
| 413 | if (!file->phony && file->cmds == 0 && !file->tried_implicit)
|
|---|
| 414 | {
|
|---|
| 415 | if (try_implicit_rule (file, depth))
|
|---|
| 416 | DBF (DB_IMPLICIT, _("Found an implicit rule for `%s'.\n"));
|
|---|
| 417 | else
|
|---|
| 418 | DBF (DB_IMPLICIT, _("No implicit rule found for `%s'.\n"));
|
|---|
| 419 | file->tried_implicit = 1;
|
|---|
| 420 | }
|
|---|
| 421 | if (file->cmds == 0 && !file->is_target
|
|---|
| 422 | && default_file != 0 && default_file->cmds != 0)
|
|---|
| 423 | {
|
|---|
| 424 | DBF (DB_IMPLICIT, _("Using default commands for `%s'.\n"));
|
|---|
| 425 | file->cmds = default_file->cmds;
|
|---|
| 426 | }
|
|---|
| 427 |
|
|---|
| 428 | /* Update all non-intermediate files we depend on, if necessary,
|
|---|
| 429 | and see whether any of them is more recent than this file. */
|
|---|
| 430 |
|
|---|
| 431 | lastd = 0;
|
|---|
| 432 | d = file->deps;
|
|---|
| 433 | while (d != 0)
|
|---|
| 434 | {
|
|---|
| 435 | FILE_TIMESTAMP mtime;
|
|---|
| 436 | int maybe_make;
|
|---|
| 437 |
|
|---|
| 438 | check_renamed (d->file);
|
|---|
| 439 |
|
|---|
| 440 | mtime = file_mtime (d->file);
|
|---|
| 441 | check_renamed (d->file);
|
|---|
| 442 |
|
|---|
| 443 | if (is_updating (d->file))
|
|---|
| 444 | {
|
|---|
| 445 | error (NILF, _("Circular %s <- %s dependency dropped."),
|
|---|
| 446 | file->name, d->file->name);
|
|---|
| 447 | /* We cannot free D here because our the caller will still have
|
|---|
| 448 | a reference to it when we were called recursively via
|
|---|
| 449 | check_dep below. */
|
|---|
| 450 | if (lastd == 0)
|
|---|
| 451 | file->deps = d->next;
|
|---|
| 452 | else
|
|---|
| 453 | lastd->next = d->next;
|
|---|
| 454 | d = d->next;
|
|---|
| 455 | continue;
|
|---|
| 456 | }
|
|---|
| 457 |
|
|---|
| 458 | d->file->parent = file;
|
|---|
| 459 | maybe_make = must_make;
|
|---|
| 460 | dep_status |= check_dep (d->file, depth, this_mtime, &maybe_make);
|
|---|
| 461 | if (! d->ignore_mtime)
|
|---|
| 462 | must_make = maybe_make;
|
|---|
| 463 |
|
|---|
| 464 | check_renamed (d->file);
|
|---|
| 465 |
|
|---|
| 466 | {
|
|---|
| 467 | register struct file *f = d->file;
|
|---|
| 468 | if (f->double_colon)
|
|---|
| 469 | f = f->double_colon;
|
|---|
| 470 | do
|
|---|
| 471 | {
|
|---|
| 472 | running |= (f->command_state == cs_running
|
|---|
| 473 | || f->command_state == cs_deps_running);
|
|---|
| 474 | f = f->prev;
|
|---|
| 475 | }
|
|---|
| 476 | while (f != 0);
|
|---|
| 477 | }
|
|---|
| 478 |
|
|---|
| 479 | if (dep_status != 0 && !keep_going_flag)
|
|---|
| 480 | break;
|
|---|
| 481 |
|
|---|
| 482 | if (!running)
|
|---|
| 483 | d->changed = file_mtime (d->file) != mtime;
|
|---|
| 484 |
|
|---|
| 485 | lastd = d;
|
|---|
| 486 | d = d->next;
|
|---|
| 487 | }
|
|---|
| 488 |
|
|---|
| 489 | /* Now we know whether this target needs updating.
|
|---|
| 490 | If it does, update all the intermediate files we depend on. */
|
|---|
| 491 |
|
|---|
| 492 | if (must_make || always_make_flag)
|
|---|
| 493 | {
|
|---|
| 494 | for (d = file->deps; d != 0; d = d->next)
|
|---|
| 495 | if (d->file->intermediate)
|
|---|
| 496 | {
|
|---|
| 497 | FILE_TIMESTAMP mtime = file_mtime (d->file);
|
|---|
| 498 | check_renamed (d->file);
|
|---|
| 499 | d->file->parent = file;
|
|---|
| 500 | dep_status |= update_file (d->file, depth);
|
|---|
| 501 | check_renamed (d->file);
|
|---|
| 502 |
|
|---|
| 503 | {
|
|---|
| 504 | register struct file *f = d->file;
|
|---|
| 505 | if (f->double_colon)
|
|---|
| 506 | f = f->double_colon;
|
|---|
| 507 | do
|
|---|
| 508 | {
|
|---|
| 509 | running |= (f->command_state == cs_running
|
|---|
| 510 | || f->command_state == cs_deps_running);
|
|---|
| 511 | f = f->prev;
|
|---|
| 512 | }
|
|---|
| 513 | while (f != 0);
|
|---|
| 514 | }
|
|---|
| 515 |
|
|---|
| 516 | if (dep_status != 0 && !keep_going_flag)
|
|---|
| 517 | break;
|
|---|
| 518 |
|
|---|
| 519 | if (!running)
|
|---|
| 520 | d->changed = ((file->phony && file->cmds != 0)
|
|---|
| 521 | || file_mtime (d->file) != mtime);
|
|---|
| 522 | }
|
|---|
| 523 | }
|
|---|
| 524 |
|
|---|
| 525 | finish_updating (file);
|
|---|
| 526 |
|
|---|
| 527 | DBF (DB_VERBOSE, _("Finished prerequisites of target file `%s'.\n"));
|
|---|
| 528 |
|
|---|
| 529 | if (running)
|
|---|
| 530 | {
|
|---|
| 531 | set_command_state (file, cs_deps_running);
|
|---|
| 532 | --depth;
|
|---|
| 533 | DBF (DB_VERBOSE, _("The prerequisites of `%s' are being made.\n"));
|
|---|
| 534 | return 0;
|
|---|
| 535 | }
|
|---|
| 536 |
|
|---|
| 537 | /* If any dependency failed, give up now. */
|
|---|
| 538 |
|
|---|
| 539 | if (dep_status != 0)
|
|---|
| 540 | {
|
|---|
| 541 | file->update_status = dep_status;
|
|---|
| 542 | notice_finished_file (file);
|
|---|
| 543 |
|
|---|
| 544 | --depth;
|
|---|
| 545 |
|
|---|
| 546 | DBF (DB_VERBOSE, _("Giving up on target file `%s'.\n"));
|
|---|
| 547 |
|
|---|
| 548 | if (depth == 0 && keep_going_flag
|
|---|
| 549 | && !just_print_flag && !question_flag)
|
|---|
| 550 | error (NILF,
|
|---|
| 551 | _("Target `%s' not remade because of errors."), file->name);
|
|---|
| 552 |
|
|---|
| 553 | return dep_status;
|
|---|
| 554 | }
|
|---|
| 555 |
|
|---|
| 556 | if (file->command_state == cs_deps_running)
|
|---|
| 557 | /* The commands for some deps were running on the last iteration, but
|
|---|
| 558 | they have finished now. Reset the command_state to not_started to
|
|---|
| 559 | simplify later bookkeeping. It is important that we do this only
|
|---|
| 560 | when the prior state was cs_deps_running, because that prior state
|
|---|
| 561 | was definitely propagated to FILE's also_make's by set_command_state
|
|---|
| 562 | (called above), but in another state an also_make may have
|
|---|
| 563 | independently changed to finished state, and we would confuse that
|
|---|
| 564 | file's bookkeeping (updated, but not_started is bogus state). */
|
|---|
| 565 | set_command_state (file, cs_not_started);
|
|---|
| 566 |
|
|---|
| 567 | /* Now record which prerequisites are more
|
|---|
| 568 | recent than this file, so we can define $?. */
|
|---|
| 569 |
|
|---|
| 570 | deps_changed = 0;
|
|---|
| 571 | for (d = file->deps; d != 0; d = d->next)
|
|---|
| 572 | {
|
|---|
| 573 | FILE_TIMESTAMP d_mtime = file_mtime (d->file);
|
|---|
| 574 | check_renamed (d->file);
|
|---|
| 575 |
|
|---|
| 576 | if (! d->ignore_mtime)
|
|---|
| 577 | {
|
|---|
| 578 | #if 1
|
|---|
| 579 | /* %%% In version 4, remove this code completely to
|
|---|
| 580 | implement not remaking deps if their deps are newer
|
|---|
| 581 | than their parents. */
|
|---|
| 582 | if (d_mtime == NONEXISTENT_MTIME && !d->file->intermediate)
|
|---|
| 583 | /* We must remake if this dep does not
|
|---|
| 584 | exist and is not intermediate. */
|
|---|
| 585 | must_make = 1;
|
|---|
| 586 | #endif
|
|---|
| 587 |
|
|---|
| 588 | /* Set DEPS_CHANGED if this dep actually changed. */
|
|---|
| 589 | deps_changed |= d->changed;
|
|---|
| 590 | }
|
|---|
| 591 |
|
|---|
| 592 | /* Set D->changed if either this dep actually changed,
|
|---|
| 593 | or its dependent, FILE, is older or does not exist. */
|
|---|
| 594 | d->changed |= noexist || d_mtime > this_mtime;
|
|---|
| 595 |
|
|---|
| 596 | if (!noexist && ISDB (DB_BASIC|DB_VERBOSE))
|
|---|
| 597 | {
|
|---|
| 598 | const char *fmt = 0;
|
|---|
| 599 |
|
|---|
| 600 | if (d->ignore_mtime)
|
|---|
| 601 | {
|
|---|
| 602 | if (ISDB (DB_VERBOSE))
|
|---|
| 603 | fmt = _("Prerequisite `%s' is order-only for target `%s'.\n");
|
|---|
| 604 | }
|
|---|
| 605 | else if (d_mtime == NONEXISTENT_MTIME)
|
|---|
| 606 | {
|
|---|
| 607 | if (ISDB (DB_BASIC))
|
|---|
| 608 | fmt = _("Prerequisite `%s' of target `%s' does not exist.\n");
|
|---|
| 609 | }
|
|---|
| 610 | else if (d->changed)
|
|---|
| 611 | {
|
|---|
| 612 | if (ISDB (DB_BASIC))
|
|---|
| 613 | fmt = _("Prerequisite `%s' is newer than target `%s'.\n");
|
|---|
| 614 | }
|
|---|
| 615 | else if (ISDB (DB_VERBOSE))
|
|---|
| 616 | fmt = _("Prerequisite `%s' is older than target `%s'.\n");
|
|---|
| 617 |
|
|---|
| 618 | if (fmt)
|
|---|
| 619 | {
|
|---|
| 620 | print_spaces (depth);
|
|---|
| 621 | printf (fmt, dep_name (d), file->name);
|
|---|
| 622 | fflush (stdout);
|
|---|
| 623 | }
|
|---|
| 624 | }
|
|---|
| 625 | }
|
|---|
| 626 |
|
|---|
| 627 | /* Here depth returns to the value it had when we were called. */
|
|---|
| 628 | depth--;
|
|---|
| 629 |
|
|---|
| 630 | if (file->double_colon && file->deps == 0)
|
|---|
| 631 | {
|
|---|
| 632 | must_make = 1;
|
|---|
| 633 | DBF (DB_BASIC,
|
|---|
| 634 | _("Target `%s' is double-colon and has no prerequisites.\n"));
|
|---|
| 635 | }
|
|---|
| 636 | else if (!noexist && file->is_target && !deps_changed && file->cmds == 0
|
|---|
| 637 | && !always_make_flag)
|
|---|
| 638 | {
|
|---|
| 639 | must_make = 0;
|
|---|
| 640 | DBF (DB_VERBOSE,
|
|---|
| 641 | _("No commands for `%s' and no prerequisites actually changed.\n"));
|
|---|
| 642 | }
|
|---|
| 643 | else if (!must_make && file->cmds != 0 && always_make_flag)
|
|---|
| 644 | {
|
|---|
| 645 | must_make = 1;
|
|---|
| 646 | DBF (DB_VERBOSE, _("Making `%s' due to always-make flag.\n"));
|
|---|
| 647 | }
|
|---|
| 648 |
|
|---|
| 649 | if (!must_make)
|
|---|
| 650 | {
|
|---|
| 651 | if (ISDB (DB_VERBOSE))
|
|---|
| 652 | {
|
|---|
| 653 | print_spaces (depth);
|
|---|
| 654 | printf (_("No need to remake target `%s'"), file->name);
|
|---|
| 655 | if (!streq (file->name, file->hname))
|
|---|
| 656 | printf (_("; using VPATH name `%s'"), file->hname);
|
|---|
| 657 | puts (".");
|
|---|
| 658 | fflush (stdout);
|
|---|
| 659 | }
|
|---|
| 660 |
|
|---|
| 661 | notice_finished_file (file);
|
|---|
| 662 |
|
|---|
| 663 | /* Since we don't need to remake the file, convert it to use the
|
|---|
| 664 | VPATH filename if we found one. hfile will be either the
|
|---|
| 665 | local name if no VPATH or the VPATH name if one was found. */
|
|---|
| 666 |
|
|---|
| 667 | while (file)
|
|---|
| 668 | {
|
|---|
| 669 | file->name = file->hname;
|
|---|
| 670 | file = file->prev;
|
|---|
| 671 | }
|
|---|
| 672 |
|
|---|
| 673 | return 0;
|
|---|
| 674 | }
|
|---|
| 675 |
|
|---|
| 676 | DBF (DB_BASIC, _("Must remake target `%s'.\n"));
|
|---|
| 677 |
|
|---|
| 678 | /* It needs to be remade. If it's VPATH and not reset via GPATH, toss the
|
|---|
| 679 | VPATH. */
|
|---|
| 680 | if (!streq(file->name, file->hname))
|
|---|
| 681 | {
|
|---|
| 682 | DB (DB_BASIC, (_(" Ignoring VPATH name `%s'.\n"), file->hname));
|
|---|
| 683 | file->ignore_vpath = 1;
|
|---|
| 684 | }
|
|---|
| 685 |
|
|---|
| 686 | /* Now, take appropriate actions to remake the file. */
|
|---|
| 687 | remake_file (file);
|
|---|
| 688 |
|
|---|
| 689 | if (file->command_state != cs_finished)
|
|---|
| 690 | {
|
|---|
| 691 | DBF (DB_VERBOSE, _("Commands of `%s' are being run.\n"));
|
|---|
| 692 | return 0;
|
|---|
| 693 | }
|
|---|
| 694 |
|
|---|
| 695 | switch (file->update_status)
|
|---|
| 696 | {
|
|---|
| 697 | case 2:
|
|---|
| 698 | DBF (DB_BASIC, _("Failed to remake target file `%s'.\n"));
|
|---|
| 699 | break;
|
|---|
| 700 | case 0:
|
|---|
| 701 | DBF (DB_BASIC, _("Successfully remade target file `%s'.\n"));
|
|---|
| 702 | break;
|
|---|
| 703 | case 1:
|
|---|
| 704 | DBF (DB_BASIC, _("Target file `%s' needs remade under -q.\n"));
|
|---|
| 705 | break;
|
|---|
| 706 | default:
|
|---|
| 707 | assert (file->update_status >= 0 && file->update_status <= 2);
|
|---|
| 708 | break;
|
|---|
| 709 | }
|
|---|
| 710 |
|
|---|
| 711 | file->updated = 1;
|
|---|
| 712 | return file->update_status;
|
|---|
| 713 | }
|
|---|
| 714 | |
|---|
| 715 |
|
|---|
| 716 | /* Set FILE's `updated' flag and re-check its mtime and the mtime's of all
|
|---|
| 717 | files listed in its `also_make' member. Under -t, this function also
|
|---|
| 718 | touches FILE.
|
|---|
| 719 |
|
|---|
| 720 | On return, FILE->update_status will no longer be -1 if it was. */
|
|---|
| 721 |
|
|---|
| 722 | void
|
|---|
| 723 | notice_finished_file (struct file *file)
|
|---|
| 724 | {
|
|---|
| 725 | struct dep *d;
|
|---|
| 726 | int ran = file->command_state == cs_running;
|
|---|
| 727 | int touched = 0;
|
|---|
| 728 |
|
|---|
| 729 | file->command_state = cs_finished;
|
|---|
| 730 | file->updated = 1;
|
|---|
| 731 |
|
|---|
| 732 | if (touch_flag
|
|---|
| 733 | /* The update status will be:
|
|---|
| 734 | -1 if this target was not remade;
|
|---|
| 735 | 0 if 0 or more commands (+ or ${MAKE}) were run and won;
|
|---|
| 736 | 1 if some commands were run and lost.
|
|---|
| 737 | We touch the target if it has commands which either were not run
|
|---|
| 738 | or won when they ran (i.e. status is 0). */
|
|---|
| 739 | && file->update_status == 0)
|
|---|
| 740 | {
|
|---|
| 741 | if (file->cmds != 0 && file->cmds->any_recurse)
|
|---|
| 742 | {
|
|---|
| 743 | /* If all the command lines were recursive,
|
|---|
| 744 | we don't want to do the touching. */
|
|---|
| 745 | unsigned int i;
|
|---|
| 746 | for (i = 0; i < file->cmds->ncommand_lines; ++i)
|
|---|
| 747 | if (!(file->cmds->lines_flags[i] & COMMANDS_RECURSE))
|
|---|
| 748 | goto have_nonrecursing;
|
|---|
| 749 | }
|
|---|
| 750 | else
|
|---|
| 751 | {
|
|---|
| 752 | have_nonrecursing:
|
|---|
| 753 | if (file->phony)
|
|---|
| 754 | file->update_status = 0;
|
|---|
| 755 | /* According to POSIX, -t doesn't affect targets with no cmds. */
|
|---|
| 756 | else if (file->cmds != 0)
|
|---|
| 757 | {
|
|---|
| 758 | /* Should set file's modification date and do nothing else. */
|
|---|
| 759 | file->update_status = touch_file (file);
|
|---|
| 760 |
|
|---|
| 761 | /* Pretend we ran a real touch command, to suppress the
|
|---|
| 762 | "`foo' is up to date" message. */
|
|---|
| 763 | commands_started++;
|
|---|
| 764 |
|
|---|
| 765 | /* Request for the timestamp to be updated (and distributed
|
|---|
| 766 | to the double-colon entries). Simply setting ran=1 would
|
|---|
| 767 | almost have done the trick, but messes up with the also_make
|
|---|
| 768 | updating logic below. */
|
|---|
| 769 | touched = 1;
|
|---|
| 770 | }
|
|---|
| 771 | }
|
|---|
| 772 | }
|
|---|
| 773 |
|
|---|
| 774 | if (file->mtime_before_update == UNKNOWN_MTIME)
|
|---|
| 775 | file->mtime_before_update = file->last_mtime;
|
|---|
| 776 |
|
|---|
| 777 | if ((ran && !file->phony) || touched)
|
|---|
| 778 | {
|
|---|
| 779 | struct file *f;
|
|---|
| 780 | int i = 0;
|
|---|
| 781 |
|
|---|
| 782 | /* If -n, -t, or -q and all the commands are recursive, we ran them so
|
|---|
| 783 | really check the target's mtime again. Otherwise, assume the target
|
|---|
| 784 | would have been updated. */
|
|---|
| 785 |
|
|---|
| 786 | if (question_flag || just_print_flag || touch_flag)
|
|---|
| 787 | {
|
|---|
| 788 | for (i = file->cmds->ncommand_lines; i > 0; --i)
|
|---|
| 789 | if (! (file->cmds->lines_flags[i-1] & COMMANDS_RECURSE))
|
|---|
| 790 | break;
|
|---|
| 791 | }
|
|---|
| 792 |
|
|---|
| 793 | /* If there were no commands at all, it's always new. */
|
|---|
| 794 |
|
|---|
| 795 | else if (file->is_target && file->cmds == 0)
|
|---|
| 796 | i = 1;
|
|---|
| 797 |
|
|---|
| 798 | file->last_mtime = i == 0 ? UNKNOWN_MTIME : NEW_MTIME;
|
|---|
| 799 |
|
|---|
| 800 | /* Propagate the change of modification time to all the double-colon
|
|---|
| 801 | entries for this file. */
|
|---|
| 802 | for (f = file->double_colon; f != 0; f = f->prev)
|
|---|
| 803 | f->last_mtime = file->last_mtime;
|
|---|
| 804 | }
|
|---|
| 805 |
|
|---|
| 806 | if (ran && file->update_status != -1)
|
|---|
| 807 | /* We actually tried to update FILE, which has
|
|---|
| 808 | updated its also_make's as well (if it worked).
|
|---|
| 809 | If it didn't work, it wouldn't work again for them.
|
|---|
| 810 | So mark them as updated with the same status. */
|
|---|
| 811 | for (d = file->also_make; d != 0; d = d->next)
|
|---|
| 812 | {
|
|---|
| 813 | d->file->command_state = cs_finished;
|
|---|
| 814 | d->file->updated = 1;
|
|---|
| 815 | d->file->update_status = file->update_status;
|
|---|
| 816 |
|
|---|
| 817 | if (ran && !d->file->phony)
|
|---|
| 818 | /* Fetch the new modification time.
|
|---|
| 819 | We do this instead of just invalidating the cached time
|
|---|
| 820 | so that a vpath_search can happen. Otherwise, it would
|
|---|
| 821 | never be done because the target is already updated. */
|
|---|
| 822 | (void) f_mtime (d->file, 0);
|
|---|
| 823 | }
|
|---|
| 824 | else if (file->update_status == -1)
|
|---|
| 825 | /* Nothing was done for FILE, but it needed nothing done.
|
|---|
| 826 | So mark it now as "succeeded". */
|
|---|
| 827 | file->update_status = 0;
|
|---|
| 828 | }
|
|---|
| 829 | |
|---|
| 830 |
|
|---|
| 831 | /* Check whether another file (whose mtime is THIS_MTIME)
|
|---|
| 832 | needs updating on account of a dependency which is file FILE.
|
|---|
| 833 | If it does, store 1 in *MUST_MAKE_PTR.
|
|---|
| 834 | In the process, update any non-intermediate files
|
|---|
| 835 | that FILE depends on (including FILE itself).
|
|---|
| 836 | Return nonzero if any updating failed. */
|
|---|
| 837 |
|
|---|
| 838 | static int
|
|---|
| 839 | check_dep (struct file *file, unsigned int depth,
|
|---|
| 840 | FILE_TIMESTAMP this_mtime, int *must_make_ptr)
|
|---|
| 841 | {
|
|---|
| 842 | struct dep *d;
|
|---|
| 843 | int dep_status = 0;
|
|---|
| 844 |
|
|---|
| 845 | ++depth;
|
|---|
| 846 | start_updating (file);
|
|---|
| 847 |
|
|---|
| 848 | if (!file->intermediate)
|
|---|
| 849 | /* If this is a non-intermediate file, update it and record
|
|---|
| 850 | whether it is newer than THIS_MTIME. */
|
|---|
| 851 | {
|
|---|
| 852 | FILE_TIMESTAMP mtime;
|
|---|
| 853 | dep_status = update_file (file, depth);
|
|---|
| 854 | check_renamed (file);
|
|---|
| 855 | mtime = file_mtime (file);
|
|---|
| 856 | check_renamed (file);
|
|---|
| 857 | if (mtime == NONEXISTENT_MTIME || mtime > this_mtime)
|
|---|
| 858 | *must_make_ptr = 1;
|
|---|
| 859 | }
|
|---|
| 860 | else
|
|---|
| 861 | {
|
|---|
| 862 | /* FILE is an intermediate file. */
|
|---|
| 863 | FILE_TIMESTAMP mtime;
|
|---|
| 864 |
|
|---|
| 865 | if (!file->phony && file->cmds == 0 && !file->tried_implicit)
|
|---|
| 866 | {
|
|---|
| 867 | if (try_implicit_rule (file, depth))
|
|---|
| 868 | DBF (DB_IMPLICIT, _("Found an implicit rule for `%s'.\n"));
|
|---|
| 869 | else
|
|---|
| 870 | DBF (DB_IMPLICIT, _("No implicit rule found for `%s'.\n"));
|
|---|
| 871 | file->tried_implicit = 1;
|
|---|
| 872 | }
|
|---|
| 873 | if (file->cmds == 0 && !file->is_target
|
|---|
| 874 | && default_file != 0 && default_file->cmds != 0)
|
|---|
| 875 | {
|
|---|
| 876 | DBF (DB_IMPLICIT, _("Using default commands for `%s'.\n"));
|
|---|
| 877 | file->cmds = default_file->cmds;
|
|---|
| 878 | }
|
|---|
| 879 |
|
|---|
| 880 | /* If the intermediate file actually exists
|
|---|
| 881 | and is newer, then we should remake from it. */
|
|---|
| 882 | check_renamed (file);
|
|---|
| 883 | mtime = file_mtime (file);
|
|---|
| 884 | check_renamed (file);
|
|---|
| 885 | if (mtime != NONEXISTENT_MTIME && mtime > this_mtime)
|
|---|
| 886 | *must_make_ptr = 1;
|
|---|
| 887 | /* Otherwise, update all non-intermediate files we depend on,
|
|---|
| 888 | if necessary, and see whether any of them is more
|
|---|
| 889 | recent than the file on whose behalf we are checking. */
|
|---|
| 890 | else
|
|---|
| 891 | {
|
|---|
| 892 | struct dep *lastd;
|
|---|
| 893 |
|
|---|
| 894 | lastd = 0;
|
|---|
| 895 | d = file->deps;
|
|---|
| 896 | while (d != 0)
|
|---|
| 897 | {
|
|---|
| 898 | int maybe_make;
|
|---|
| 899 |
|
|---|
| 900 | if (is_updating (d->file))
|
|---|
| 901 | {
|
|---|
| 902 | error (NILF, _("Circular %s <- %s dependency dropped."),
|
|---|
| 903 | file->name, d->file->name);
|
|---|
| 904 | if (lastd == 0)
|
|---|
| 905 | {
|
|---|
| 906 | file->deps = d->next;
|
|---|
| 907 | free ((char *) d);
|
|---|
| 908 | d = file->deps;
|
|---|
| 909 | }
|
|---|
| 910 | else
|
|---|
| 911 | {
|
|---|
| 912 | lastd->next = d->next;
|
|---|
| 913 | free ((char *) d);
|
|---|
| 914 | d = lastd->next;
|
|---|
| 915 | }
|
|---|
| 916 | continue;
|
|---|
| 917 | }
|
|---|
| 918 |
|
|---|
| 919 | d->file->parent = file;
|
|---|
| 920 | maybe_make = *must_make_ptr;
|
|---|
| 921 | dep_status |= check_dep (d->file, depth, this_mtime,
|
|---|
| 922 | &maybe_make);
|
|---|
| 923 | if (! d->ignore_mtime)
|
|---|
| 924 | *must_make_ptr = maybe_make;
|
|---|
| 925 | check_renamed (d->file);
|
|---|
| 926 | if (dep_status != 0 && !keep_going_flag)
|
|---|
| 927 | break;
|
|---|
| 928 |
|
|---|
| 929 | if (d->file->command_state == cs_running
|
|---|
| 930 | || d->file->command_state == cs_deps_running)
|
|---|
| 931 | /* Record that some of FILE's deps are still being made.
|
|---|
| 932 | This tells the upper levels to wait on processing it until
|
|---|
| 933 | the commands are finished. */
|
|---|
| 934 | set_command_state (file, cs_deps_running);
|
|---|
| 935 |
|
|---|
| 936 | lastd = d;
|
|---|
| 937 | d = d->next;
|
|---|
| 938 | }
|
|---|
| 939 | }
|
|---|
| 940 | }
|
|---|
| 941 |
|
|---|
| 942 | finish_updating (file);
|
|---|
| 943 | return dep_status;
|
|---|
| 944 | }
|
|---|
| 945 | |
|---|
| 946 |
|
|---|
| 947 | /* Touch FILE. Return zero if successful, one if not. */
|
|---|
| 948 |
|
|---|
| 949 | #define TOUCH_ERROR(call) return (perror_with_name (call, file->name), 1)
|
|---|
| 950 |
|
|---|
| 951 | static int
|
|---|
| 952 | touch_file (struct file *file)
|
|---|
| 953 | {
|
|---|
| 954 | if (!silent_flag)
|
|---|
| 955 | message (0, "touch %s", file->name);
|
|---|
| 956 |
|
|---|
| 957 | #ifndef NO_ARCHIVES
|
|---|
| 958 | if (ar_name (file->name))
|
|---|
| 959 | return ar_touch (file->name);
|
|---|
| 960 | else
|
|---|
| 961 | #endif
|
|---|
| 962 | {
|
|---|
| 963 | int fd = open (file->name, O_RDWR | O_CREAT, 0666);
|
|---|
| 964 |
|
|---|
| 965 | if (fd < 0)
|
|---|
| 966 | TOUCH_ERROR ("touch: open: ");
|
|---|
| 967 | else
|
|---|
| 968 | {
|
|---|
| 969 | struct stat statbuf;
|
|---|
| 970 | char buf;
|
|---|
| 971 | int e;
|
|---|
| 972 |
|
|---|
| 973 | EINTRLOOP (e, fstat (fd, &statbuf));
|
|---|
| 974 | if (e < 0)
|
|---|
| 975 | TOUCH_ERROR ("touch: fstat: ");
|
|---|
| 976 | /* Rewrite character 0 same as it already is. */
|
|---|
| 977 | if (read (fd, &buf, 1) < 0)
|
|---|
| 978 | TOUCH_ERROR ("touch: read: ");
|
|---|
| 979 | if (lseek (fd, 0L, 0) < 0L)
|
|---|
| 980 | TOUCH_ERROR ("touch: lseek: ");
|
|---|
| 981 | if (write (fd, &buf, 1) < 0)
|
|---|
| 982 | TOUCH_ERROR ("touch: write: ");
|
|---|
| 983 | /* If file length was 0, we just
|
|---|
| 984 | changed it, so change it back. */
|
|---|
| 985 | if (statbuf.st_size == 0)
|
|---|
| 986 | {
|
|---|
| 987 | (void) close (fd);
|
|---|
| 988 | fd = open (file->name, O_RDWR | O_TRUNC, 0666);
|
|---|
| 989 | if (fd < 0)
|
|---|
| 990 | TOUCH_ERROR ("touch: open: ");
|
|---|
| 991 | }
|
|---|
| 992 | (void) close (fd);
|
|---|
| 993 | }
|
|---|
| 994 | }
|
|---|
| 995 |
|
|---|
| 996 | return 0;
|
|---|
| 997 | }
|
|---|
| 998 | |
|---|
| 999 |
|
|---|
| 1000 | /* Having checked and updated the dependencies of FILE,
|
|---|
| 1001 | do whatever is appropriate to remake FILE itself.
|
|---|
| 1002 | Return the status from executing FILE's commands. */
|
|---|
| 1003 |
|
|---|
| 1004 | static void
|
|---|
| 1005 | remake_file (struct file *file)
|
|---|
| 1006 | {
|
|---|
| 1007 | if (file->cmds == 0)
|
|---|
| 1008 | {
|
|---|
| 1009 | if (file->phony)
|
|---|
| 1010 | /* Phony target. Pretend it succeeded. */
|
|---|
| 1011 | file->update_status = 0;
|
|---|
| 1012 | else if (file->is_target)
|
|---|
| 1013 | /* This is a nonexistent target file we cannot make.
|
|---|
| 1014 | Pretend it was successfully remade. */
|
|---|
| 1015 | file->update_status = 0;
|
|---|
| 1016 | else
|
|---|
| 1017 | {
|
|---|
| 1018 | const char *msg_noparent
|
|---|
| 1019 | = _("%sNo rule to make target `%s'%s");
|
|---|
| 1020 | const char *msg_parent
|
|---|
| 1021 | = _("%sNo rule to make target `%s', needed by `%s'%s");
|
|---|
| 1022 |
|
|---|
| 1023 | /* This is a dependency file we cannot remake. Fail. */
|
|---|
| 1024 | if (!keep_going_flag && !file->dontcare)
|
|---|
| 1025 | {
|
|---|
| 1026 | if (file->parent == 0)
|
|---|
| 1027 | fatal (NILF, msg_noparent, "", file->name, "");
|
|---|
| 1028 |
|
|---|
| 1029 | fatal (NILF, msg_parent, "", file->name, file->parent->name, "");
|
|---|
| 1030 | }
|
|---|
| 1031 |
|
|---|
| 1032 | if (!file->dontcare)
|
|---|
| 1033 | {
|
|---|
| 1034 | if (file->parent == 0)
|
|---|
| 1035 | error (NILF, msg_noparent, "*** ", file->name, ".");
|
|---|
| 1036 | else
|
|---|
| 1037 | error (NILF, msg_parent, "*** ",
|
|---|
| 1038 | file->name, file->parent->name, ".");
|
|---|
| 1039 | }
|
|---|
| 1040 | file->update_status = 2;
|
|---|
| 1041 | }
|
|---|
| 1042 | }
|
|---|
| 1043 | else
|
|---|
| 1044 | {
|
|---|
| 1045 | chop_commands (file->cmds);
|
|---|
| 1046 |
|
|---|
| 1047 | /* The normal case: start some commands. */
|
|---|
| 1048 | if (!touch_flag || file->cmds->any_recurse)
|
|---|
| 1049 | {
|
|---|
| 1050 | execute_file_commands (file);
|
|---|
| 1051 | return;
|
|---|
| 1052 | }
|
|---|
| 1053 |
|
|---|
| 1054 | /* This tells notice_finished_file it is ok to touch the file. */
|
|---|
| 1055 | file->update_status = 0;
|
|---|
| 1056 | }
|
|---|
| 1057 |
|
|---|
| 1058 | /* This does the touching under -t. */
|
|---|
| 1059 | notice_finished_file (file);
|
|---|
| 1060 | }
|
|---|
| 1061 | |
|---|
| 1062 |
|
|---|
| 1063 | /* Return the mtime of a file, given a `struct file'.
|
|---|
| 1064 | Caches the time in the struct file to avoid excess stat calls.
|
|---|
| 1065 |
|
|---|
| 1066 | If the file is not found, and SEARCH is nonzero, VPATH searching and
|
|---|
| 1067 | replacement is done. If that fails, a library (-lLIBNAME) is tried and
|
|---|
| 1068 | the library's actual name (/lib/libLIBNAME.a, etc.) is substituted into
|
|---|
| 1069 | FILE. */
|
|---|
| 1070 |
|
|---|
| 1071 | FILE_TIMESTAMP
|
|---|
| 1072 | f_mtime (struct file *file, int search)
|
|---|
| 1073 | {
|
|---|
| 1074 | FILE_TIMESTAMP mtime;
|
|---|
| 1075 |
|
|---|
| 1076 | /* File's mtime is not known; must get it from the system. */
|
|---|
| 1077 |
|
|---|
| 1078 | #ifndef NO_ARCHIVES
|
|---|
| 1079 | if (ar_name (file->name))
|
|---|
| 1080 | {
|
|---|
| 1081 | /* This file is an archive-member reference. */
|
|---|
| 1082 |
|
|---|
| 1083 | char *arname, *memname;
|
|---|
| 1084 | struct file *arfile;
|
|---|
| 1085 | int arname_used = 0;
|
|---|
| 1086 | time_t member_date;
|
|---|
| 1087 |
|
|---|
| 1088 | /* Find the archive's name. */
|
|---|
| 1089 | ar_parse_name (file->name, &arname, &memname);
|
|---|
| 1090 |
|
|---|
| 1091 | /* Find the modification time of the archive itself.
|
|---|
| 1092 | Also allow for its name to be changed via VPATH search. */
|
|---|
| 1093 | arfile = lookup_file (arname);
|
|---|
| 1094 | if (arfile == 0)
|
|---|
| 1095 | {
|
|---|
| 1096 | arfile = enter_file (arname);
|
|---|
| 1097 | arname_used = 1;
|
|---|
| 1098 | }
|
|---|
| 1099 | mtime = f_mtime (arfile, search);
|
|---|
| 1100 | check_renamed (arfile);
|
|---|
| 1101 | if (search && strcmp (arfile->hname, arname))
|
|---|
| 1102 | {
|
|---|
| 1103 | /* The archive's name has changed.
|
|---|
| 1104 | Change the archive-member reference accordingly. */
|
|---|
| 1105 |
|
|---|
| 1106 | char *name;
|
|---|
| 1107 | unsigned int arlen, memlen;
|
|---|
| 1108 |
|
|---|
| 1109 | if (!arname_used)
|
|---|
| 1110 | {
|
|---|
| 1111 | free (arname);
|
|---|
| 1112 | arname_used = 1;
|
|---|
| 1113 | }
|
|---|
| 1114 |
|
|---|
| 1115 | arname = arfile->hname;
|
|---|
| 1116 | arlen = strlen (arname);
|
|---|
| 1117 | memlen = strlen (memname);
|
|---|
| 1118 |
|
|---|
| 1119 | /* free (file->name); */
|
|---|
| 1120 |
|
|---|
| 1121 | name = (char *) xmalloc (arlen + 1 + memlen + 2);
|
|---|
| 1122 | bcopy (arname, name, arlen);
|
|---|
| 1123 | name[arlen] = '(';
|
|---|
| 1124 | bcopy (memname, name + arlen + 1, memlen);
|
|---|
| 1125 | name[arlen + 1 + memlen] = ')';
|
|---|
| 1126 | name[arlen + 1 + memlen + 1] = '\0';
|
|---|
| 1127 |
|
|---|
| 1128 | /* If the archive was found with GPATH, make the change permanent;
|
|---|
| 1129 | otherwise defer it until later. */
|
|---|
| 1130 | if (arfile->name == arfile->hname)
|
|---|
| 1131 | rename_file (file, name);
|
|---|
| 1132 | else
|
|---|
| 1133 | rehash_file (file, name);
|
|---|
| 1134 | check_renamed (file);
|
|---|
| 1135 | }
|
|---|
| 1136 |
|
|---|
| 1137 | if (!arname_used)
|
|---|
| 1138 | free (arname);
|
|---|
| 1139 | free (memname);
|
|---|
| 1140 |
|
|---|
| 1141 | file->low_resolution_time = 1;
|
|---|
| 1142 |
|
|---|
| 1143 | if (mtime == NONEXISTENT_MTIME)
|
|---|
| 1144 | /* The archive doesn't exist, so its members don't exist either. */
|
|---|
| 1145 | return NONEXISTENT_MTIME;
|
|---|
| 1146 |
|
|---|
| 1147 | member_date = ar_member_date (file->hname);
|
|---|
| 1148 | mtime = (member_date == (time_t) -1
|
|---|
| 1149 | ? NONEXISTENT_MTIME
|
|---|
| 1150 | : file_timestamp_cons (file->hname, member_date, 0));
|
|---|
| 1151 | }
|
|---|
| 1152 | else
|
|---|
| 1153 | #endif
|
|---|
| 1154 | {
|
|---|
| 1155 | mtime = name_mtime (file->name);
|
|---|
| 1156 |
|
|---|
| 1157 | if (mtime == NONEXISTENT_MTIME && search && !file->ignore_vpath)
|
|---|
| 1158 | {
|
|---|
| 1159 | /* If name_mtime failed, search VPATH. */
|
|---|
| 1160 | char *name = file->name;
|
|---|
| 1161 | if (vpath_search (&name, &mtime)
|
|---|
| 1162 | /* Last resort, is it a library (-lxxx)? */
|
|---|
| 1163 | || (name[0] == '-' && name[1] == 'l'
|
|---|
| 1164 | && library_search (&name, &mtime)))
|
|---|
| 1165 | {
|
|---|
| 1166 | if (mtime != UNKNOWN_MTIME)
|
|---|
| 1167 | /* vpath_search and library_search store UNKNOWN_MTIME
|
|---|
| 1168 | if they didn't need to do a stat call for their work. */
|
|---|
| 1169 | file->last_mtime = mtime;
|
|---|
| 1170 |
|
|---|
| 1171 | /* If we found it in VPATH, see if it's in GPATH too; if so,
|
|---|
| 1172 | change the name right now; if not, defer until after the
|
|---|
| 1173 | dependencies are updated. */
|
|---|
| 1174 | if (gpath_search (name, strlen(name) - strlen(file->name) - 1))
|
|---|
| 1175 | {
|
|---|
| 1176 | rename_file (file, name);
|
|---|
| 1177 | check_renamed (file);
|
|---|
| 1178 | return file_mtime (file);
|
|---|
| 1179 | }
|
|---|
| 1180 |
|
|---|
| 1181 | rehash_file (file, name);
|
|---|
| 1182 | check_renamed (file);
|
|---|
| 1183 | mtime = name_mtime (name);
|
|---|
| 1184 | }
|
|---|
| 1185 | }
|
|---|
| 1186 | }
|
|---|
| 1187 |
|
|---|
| 1188 | {
|
|---|
| 1189 | /* Files can have bogus timestamps that nothing newly made will be
|
|---|
| 1190 | "newer" than. Updating their dependents could just result in loops.
|
|---|
| 1191 | So notify the user of the anomaly with a warning.
|
|---|
| 1192 |
|
|---|
| 1193 | We only need to do this once, for now. */
|
|---|
| 1194 |
|
|---|
| 1195 | if (!clock_skew_detected
|
|---|
| 1196 | && mtime != NONEXISTENT_MTIME
|
|---|
| 1197 | && !file->updated)
|
|---|
| 1198 | {
|
|---|
| 1199 | static FILE_TIMESTAMP adjusted_now;
|
|---|
| 1200 |
|
|---|
| 1201 | FILE_TIMESTAMP adjusted_mtime = mtime;
|
|---|
| 1202 |
|
|---|
| 1203 | #if defined(WINDOWS32) || defined(__MSDOS__)
|
|---|
| 1204 | /* Experimentation has shown that FAT filesystems can set file times
|
|---|
| 1205 | up to 3 seconds into the future! Play it safe. */
|
|---|
| 1206 |
|
|---|
| 1207 | #define FAT_ADJ_OFFSET (FILE_TIMESTAMP) 3
|
|---|
| 1208 |
|
|---|
| 1209 | FILE_TIMESTAMP adjustment = FAT_ADJ_OFFSET << FILE_TIMESTAMP_LO_BITS;
|
|---|
| 1210 | if (ORDINARY_MTIME_MIN + adjustment <= adjusted_mtime)
|
|---|
| 1211 | adjusted_mtime -= adjustment;
|
|---|
| 1212 | #elif defined(__EMX__)
|
|---|
| 1213 | /* FAT filesystems round time to the nearest even second!
|
|---|
| 1214 | Allow for any file (NTFS or FAT) to perhaps suffer from this
|
|---|
| 1215 | brain damage. */
|
|---|
| 1216 | FILE_TIMESTAMP adjustment = (((FILE_TIMESTAMP_S (adjusted_mtime) & 1) == 0
|
|---|
| 1217 | && FILE_TIMESTAMP_NS (adjusted_mtime) == 0)
|
|---|
| 1218 | ? (FILE_TIMESTAMP) 1 << FILE_TIMESTAMP_LO_BITS
|
|---|
| 1219 | : 0);
|
|---|
| 1220 | #endif
|
|---|
| 1221 |
|
|---|
| 1222 | /* If the file's time appears to be in the future, update our
|
|---|
| 1223 | concept of the present and try once more. */
|
|---|
| 1224 | if (adjusted_now < adjusted_mtime)
|
|---|
| 1225 | {
|
|---|
| 1226 | int resolution;
|
|---|
| 1227 | FILE_TIMESTAMP now = file_timestamp_now (&resolution);
|
|---|
| 1228 | adjusted_now = now + (resolution - 1);
|
|---|
| 1229 | if (adjusted_now < adjusted_mtime)
|
|---|
| 1230 | {
|
|---|
| 1231 | #ifdef NO_FLOAT
|
|---|
| 1232 | error (NILF, _("Warning: File `%s' has modification time in the future"),
|
|---|
| 1233 | file->name);
|
|---|
| 1234 | #else
|
|---|
| 1235 | double from_now =
|
|---|
| 1236 | (FILE_TIMESTAMP_S (mtime) - FILE_TIMESTAMP_S (now)
|
|---|
| 1237 | + ((FILE_TIMESTAMP_NS (mtime) - FILE_TIMESTAMP_NS (now))
|
|---|
| 1238 | / 1e9));
|
|---|
| 1239 | error (NILF, _("Warning: File `%s' has modification time %.2g s in the future"),
|
|---|
| 1240 | file->name, from_now);
|
|---|
| 1241 | #endif
|
|---|
| 1242 | clock_skew_detected = 1;
|
|---|
| 1243 | }
|
|---|
| 1244 | }
|
|---|
| 1245 | }
|
|---|
| 1246 | }
|
|---|
| 1247 |
|
|---|
| 1248 | /* Store the mtime into all the entries for this file. */
|
|---|
| 1249 | if (file->double_colon)
|
|---|
| 1250 | file = file->double_colon;
|
|---|
| 1251 |
|
|---|
| 1252 | do
|
|---|
| 1253 | {
|
|---|
| 1254 | /* If this file is not implicit but it is intermediate then it was
|
|---|
| 1255 | made so by the .INTERMEDIATE target. If this file has never
|
|---|
| 1256 | been built by us but was found now, it existed before make
|
|---|
| 1257 | started. So, turn off the intermediate bit so make doesn't
|
|---|
| 1258 | delete it, since it didn't create it. */
|
|---|
| 1259 | if (mtime != NONEXISTENT_MTIME && file->command_state == cs_not_started
|
|---|
| 1260 | && file->command_state == cs_not_started
|
|---|
| 1261 | && !file->tried_implicit && file->intermediate)
|
|---|
| 1262 | file->intermediate = 0;
|
|---|
| 1263 |
|
|---|
| 1264 | file->last_mtime = mtime;
|
|---|
| 1265 | file = file->prev;
|
|---|
| 1266 | }
|
|---|
| 1267 | while (file != 0);
|
|---|
| 1268 |
|
|---|
| 1269 | return mtime;
|
|---|
| 1270 | }
|
|---|
| 1271 |
|
|---|
| 1272 |
|
|---|
| 1273 | /* Return the mtime of the file or archive-member reference NAME. */
|
|---|
| 1274 |
|
|---|
| 1275 | static FILE_TIMESTAMP
|
|---|
| 1276 | name_mtime (char *name)
|
|---|
| 1277 | {
|
|---|
| 1278 | struct stat st;
|
|---|
| 1279 | int e;
|
|---|
| 1280 |
|
|---|
| 1281 | EINTRLOOP (e, stat (name, &st));
|
|---|
| 1282 | if (e != 0)
|
|---|
| 1283 | {
|
|---|
| 1284 | if (errno != ENOENT && errno != ENOTDIR)
|
|---|
| 1285 | perror_with_name ("stat:", name);
|
|---|
| 1286 | return NONEXISTENT_MTIME;
|
|---|
| 1287 | }
|
|---|
| 1288 |
|
|---|
| 1289 | return FILE_TIMESTAMP_STAT_MODTIME (name, st);
|
|---|
| 1290 | }
|
|---|
| 1291 |
|
|---|
| 1292 |
|
|---|
| 1293 | /* Search for a library file specified as -lLIBNAME, searching for a
|
|---|
| 1294 | suitable library file in the system library directories and the VPATH
|
|---|
| 1295 | directories. */
|
|---|
| 1296 |
|
|---|
| 1297 | static int
|
|---|
| 1298 | library_search (char **lib, FILE_TIMESTAMP *mtime_ptr)
|
|---|
| 1299 | {
|
|---|
| 1300 | static char *dirs[] =
|
|---|
| 1301 | {
|
|---|
| 1302 | #ifndef _AMIGA
|
|---|
| 1303 | "/lib",
|
|---|
| 1304 | "/usr/lib",
|
|---|
| 1305 | #endif
|
|---|
| 1306 | #if defined(WINDOWS32) && !defined(LIBDIR)
|
|---|
| 1307 | /*
|
|---|
| 1308 | * This is completely up to the user at product install time. Just define
|
|---|
| 1309 | * a placeholder.
|
|---|
| 1310 | */
|
|---|
| 1311 | #define LIBDIR "."
|
|---|
| 1312 | #endif
|
|---|
| 1313 | LIBDIR, /* Defined by configuration. */
|
|---|
| 1314 | 0
|
|---|
| 1315 | };
|
|---|
| 1316 |
|
|---|
| 1317 | static char *libpatterns = NULL;
|
|---|
| 1318 |
|
|---|
| 1319 | char *libname = &(*lib)[2]; /* Name without the `-l'. */
|
|---|
| 1320 | FILE_TIMESTAMP mtime;
|
|---|
| 1321 |
|
|---|
| 1322 | /* Loop variables for the libpatterns value. */
|
|---|
| 1323 | char *p, *p2;
|
|---|
| 1324 | unsigned int len;
|
|---|
| 1325 |
|
|---|
| 1326 | char *file, **dp;
|
|---|
| 1327 |
|
|---|
| 1328 | /* If we don't have libpatterns, get it. */
|
|---|
| 1329 | if (!libpatterns)
|
|---|
| 1330 | {
|
|---|
| 1331 | int save = warn_undefined_variables_flag;
|
|---|
| 1332 | warn_undefined_variables_flag = 0;
|
|---|
| 1333 |
|
|---|
| 1334 | libpatterns = xstrdup (variable_expand ("$(strip $(.LIBPATTERNS))"));
|
|---|
| 1335 |
|
|---|
| 1336 | warn_undefined_variables_flag = save;
|
|---|
| 1337 | }
|
|---|
| 1338 |
|
|---|
| 1339 | /* Loop through all the patterns in .LIBPATTERNS, and search on each one. */
|
|---|
| 1340 | p2 = libpatterns;
|
|---|
| 1341 | while ((p = find_next_token (&p2, &len)) != 0)
|
|---|
| 1342 | {
|
|---|
| 1343 | static char *buf = NULL;
|
|---|
| 1344 | static unsigned int buflen = 0;
|
|---|
| 1345 | static int libdir_maxlen = -1;
|
|---|
| 1346 | char *libbuf = variable_expand ("");
|
|---|
| 1347 |
|
|---|
| 1348 | /* Expand the pattern using LIBNAME as a replacement. */
|
|---|
| 1349 | {
|
|---|
| 1350 | char c = p[len];
|
|---|
| 1351 | char *p3, *p4;
|
|---|
| 1352 |
|
|---|
| 1353 | p[len] = '\0';
|
|---|
| 1354 | p3 = find_percent (p);
|
|---|
| 1355 | if (!p3)
|
|---|
| 1356 | {
|
|---|
| 1357 | /* Give a warning if there is no pattern, then remove the
|
|---|
| 1358 | pattern so it's ignored next time. */
|
|---|
| 1359 | error (NILF, _(".LIBPATTERNS element `%s' is not a pattern"), p);
|
|---|
| 1360 | for (; len; --len, ++p)
|
|---|
| 1361 | *p = ' ';
|
|---|
| 1362 | *p = c;
|
|---|
| 1363 | continue;
|
|---|
| 1364 | }
|
|---|
| 1365 | p4 = variable_buffer_output (libbuf, p, p3-p);
|
|---|
| 1366 | p4 = variable_buffer_output (p4, libname, strlen (libname));
|
|---|
| 1367 | p4 = variable_buffer_output (p4, p3+1, len - (p3-p));
|
|---|
| 1368 | p[len] = c;
|
|---|
| 1369 | }
|
|---|
| 1370 |
|
|---|
| 1371 | /* Look first for `libNAME.a' in the current directory. */
|
|---|
| 1372 | mtime = name_mtime (libbuf);
|
|---|
| 1373 | if (mtime != NONEXISTENT_MTIME)
|
|---|
| 1374 | {
|
|---|
| 1375 | *lib = xstrdup (libbuf);
|
|---|
| 1376 | if (mtime_ptr != 0)
|
|---|
| 1377 | *mtime_ptr = mtime;
|
|---|
| 1378 | return 1;
|
|---|
| 1379 | }
|
|---|
| 1380 |
|
|---|
| 1381 | /* Now try VPATH search on that. */
|
|---|
| 1382 |
|
|---|
| 1383 | file = libbuf;
|
|---|
| 1384 | if (vpath_search (&file, mtime_ptr))
|
|---|
| 1385 | {
|
|---|
| 1386 | *lib = file;
|
|---|
| 1387 | return 1;
|
|---|
| 1388 | }
|
|---|
| 1389 |
|
|---|
| 1390 | /* Now try the standard set of directories. */
|
|---|
| 1391 |
|
|---|
| 1392 | if (!buflen)
|
|---|
| 1393 | {
|
|---|
| 1394 | for (dp = dirs; *dp != 0; ++dp)
|
|---|
| 1395 | {
|
|---|
| 1396 | int l = strlen (*dp);
|
|---|
| 1397 | if (l > libdir_maxlen)
|
|---|
| 1398 | libdir_maxlen = l;
|
|---|
| 1399 | }
|
|---|
| 1400 | buflen = strlen (libbuf);
|
|---|
| 1401 | buf = xmalloc(libdir_maxlen + buflen + 2);
|
|---|
| 1402 | }
|
|---|
| 1403 | else if (buflen < strlen (libbuf))
|
|---|
| 1404 | {
|
|---|
| 1405 | buflen = strlen (libbuf);
|
|---|
| 1406 | buf = xrealloc (buf, libdir_maxlen + buflen + 2);
|
|---|
| 1407 | }
|
|---|
| 1408 |
|
|---|
| 1409 | for (dp = dirs; *dp != 0; ++dp)
|
|---|
| 1410 | {
|
|---|
| 1411 | sprintf (buf, "%s/%s", *dp, libbuf);
|
|---|
| 1412 | mtime = name_mtime (buf);
|
|---|
| 1413 | if (mtime != NONEXISTENT_MTIME)
|
|---|
| 1414 | {
|
|---|
| 1415 | *lib = xstrdup (buf);
|
|---|
| 1416 | if (mtime_ptr != 0)
|
|---|
| 1417 | *mtime_ptr = mtime;
|
|---|
| 1418 | return 1;
|
|---|
| 1419 | }
|
|---|
| 1420 | }
|
|---|
| 1421 | }
|
|---|
| 1422 |
|
|---|
| 1423 | return 0;
|
|---|
| 1424 | }
|
|---|