Changeset 1701 for trunk/src/kmk/file.c


Ignore:
Timestamp:
Sep 2, 2008, 4:06:18 AM (17 years ago)
Author:
bird
Message:

kmk: Implemented secondary target expansion. Fixes #42.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/kmk/file.c

    r934 r1701  
    189189      f->last = new;
    190190    }
     191
     192#ifdef CONFIG_WITH_2ND_TARGET_EXPANSION
     193  /* Check if the name needs 2nd expansion or not. */
     194  if (second_target_expansion && strchr (name, '$') != NULL)
     195    new->need_2nd_target_expansion = 1;
     196#endif
    191197
    192198  return new;
     
    333339    }
    334340}
     341
     342
     343#ifdef CONFIG_WITH_2ND_TARGET_EXPANSION
     344/* Performs secondary target name expansion and then renames
     345   the file using rename_file. */
     346static void
     347do_2nd_target_expansion (struct file *f)
     348{
     349   char *tmp_name = allocated_variable_expand (f->name);
     350   const char *name = strcache_add (tmp_name);
     351   free (tmp_name);
     352   rename_file (f, name);
     353}
     354#endif /* CONFIG_WITH_2ND_TARGET_EXPANSION */
    335355
    336356
     
    654674    expand_deps (f);
    655675
     676#ifdef CONFIG_WITH_2ND_TARGET_EXPANSION
     677  /* Perform 2nd target expansion on files which requires this. This will
     678     be re-inserting (delete+insert) hash table entries so we have to use
     679     hash_dump(). */
     680  file_slot_0 = (struct file **) hash_dump (&files, 0, 0);
     681  file_end = file_slot_0 + files.ht_fill;
     682  for (file_slot = file_slot_0; file_slot < file_end; file_slot++)
     683    for (f = *file_slot; f != 0; f = f->prev)
     684      if (f->need_2nd_target_expansion)
     685        do_2nd_target_expansion (f);
     686  free (file_slot_0);
     687
     688  /* Disable second target expansion now since we won't expand files
     689     entered after this point. (saves CPU cycles in enter_file()). */
     690  second_target_expansion = 0;
     691#endif /* CONFIG_WITH_2ND_TARGET_EXPANSION */
     692
    656693  /* For every target that's not .SUFFIXES, expand its dependencies.
    657694     We must use hash_dump (), because within this loop we might add new files
Note: See TracChangeset for help on using the changeset viewer.