Changeset 1701 for trunk/src/kmk


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

kmk: Implemented secondary target expansion. Fixes #42.

Location:
trunk/src/kmk
Files:
1 added
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/kmk/Makefile.am

    r1598 r1701  
    102102        -DCONFIG_WITH_PREPEND_ASSIGNMENT \
    103103        -DCONFIG_WITH_LOCAL_VARIABLES \
     104        -DCONFIG_WITH_2ND_TARGET_EXPANSION \
    104105        \
    105106        -DKMK \
  • trunk/src/kmk/Makefile.kmk

    r1694 r1701  
    137137        CONFIG_WITH_PREPEND_ASSIGNMENT \
    138138        CONFIG_WITH_LOCAL_VARIABLES \
     139        CONFIG_WITH_2ND_TARGET_EXPANSION \
    139140        \
    140141        KMK \
     
    476477        $(MAKE) -f $(kmk_PATH)/testcase-includedep.kmk
    477478
     479test_2ndtargetexp:
     480        $(MAKE) -f $(kmk_PATH)/testcase-2ndtargetexp.kmk
     481
    478482test_30_continued_on_failure_worker:
    479483        this_executable_does_not_exist.exe
     
    491495
    492496
    493 test_all:       test_math test_stack test_shell test_if1of test_local test_includedep test_30_continued_on_failure
    494 
     497test_all:       test_math test_stack test_shell test_if1of test_local test_includedep test_2ndtargetexp test_30_continued_on_failure
     498
  • 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
  • trunk/src/kmk/filedef.h

    r922 r1701  
    107107                                   by the explicit multi target rule. */
    108108#endif
     109#ifdef CONFIG_WITH_2ND_TARGET_EXPANSION   
     110    unsigned int need_2nd_target_expansion:1; /* Nonzero if this file needs
     111                                  second expansion of its name. Whether it
     112                                  can receive this is decided at parse time,
     113                                  and the expanding done in snap_deps. */
     114#endif
    109115
    110116  };
  • trunk/src/kmk/main.c

    r1535 r1701  
    562562int second_expansion;
    563563
     564#ifdef CONFIG_WITH_2ND_TARGET_EXPANSION
     565/* Nonzero if we have seen the '.SECONDTARGETEXPANSION' target.
     566   This turns on secondary expansion of targets.  */
     567
     568int second_target_expansion;
     569#endif
     570
    564571#ifndef CONFIG_WITH_EXTENDED_NOTPARALLEL
    565572/* Nonzero if we have seen the `.NOTPARALLEL' target.
  • trunk/src/kmk/make.h

    r1535 r1701  
    500500extern int warn_undefined_variables_flag, posix_pedantic, not_parallel;
    501501extern int second_expansion, clock_skew_detected, rebuilding_makefiles;
     502#ifdef CONFIG_WITH_2ND_TARGET_EXPANSION
     503extern int second_target_expansion;
     504#endif
    502505#ifdef CONFIG_PRETTY_COMMAND_PRINTING
    503506extern int pretty_command_printing;
  • trunk/src/kmk/read.c

    r1693 r1701  
    25302530      else if (streq (name, ".SECONDEXPANSION"))
    25312531        second_expansion = 1;
     2532#ifdef CONFIG_WITH_2ND_TARGET_EXPANSION
     2533      else if (streq (name, ".SECONDTARGETEXPANSION"))
     2534        second_target_expansion = 1;
     2535#endif
    25322536
    25332537      implicit_percent = find_percent_cached (&name);
Note: See TracChangeset for help on using the changeset viewer.