# Updated 6.16.93  variable "MAKE" is default was environment override
# For make 3.63 and above

$description = "The following test creates a makefile to verify\n"
              ."test the foreach function.";

$details = "This is a test of the foreach function in gnu make. \n"
          ."This function starts with a space separated list of\n"
          ."names and a variable. Each name in the list is subsituted\n"
          ."into the variable and the given text evaluated. The general\n"
          ."form of the command is $(foreach var,$list,$text). Several\n"
          ."types of foreach loops are tested\n";


open(MAKEFILE,"> $makefile");

# The Contents of the MAKEFILE ...

print MAKEFILE "foo = bletch null @ garf\n"
              ."null :=\n"
              ."space = ' '\n"
              ."auto_var = udef space CC null PATH MAKE foo CFLAGS WHITE @ <\n"
              ."av = \$(foreach var, \$(auto_var), \$(origin \$(var)) ) \n"
              ."override WHITE := BLACK\n"
              ."for_var = \$(addsuffix .c,foo \$(null) \$(foo) \$(space) \$(av) ) \n"
              ."fe = \$(foreach var2, \$(for_var),\$(subst .c,.o, \$(var2) ) )\n"
              ."all: auto for2\n"             
              ."auto : \n"
              ."\t\@echo \$(av) \n"
              ."for2: \n"
              ."\t\@echo \$(fe) \n";




# END of Contents of MAKEFILE
close(MAKEFILE);

&run_make_with_options($makefile,
                      "-e WHITE=WHITE CFLAGS=",
                      &get_logfile);

# Create the answer to what should be produced by this Makefile
$answer = "undefined file default file environment default file command line override automatic automatic\n"
         ."foo.o bletch.o null.o @.o garf.o .o    .o undefined.o file.o default.o file.o environment.o default.o file.o command.o line.o override.o automatic.o automatic.o\n";


&compare_output($answer,&get_logfile(1));

1;






