Home | History | Annotate | Line # | Download | only in variables
      1  1.1  christos #                                                                    -*-perl-*-
      2  1.1  christos 
      3  1.1  christos $description = "Test various flavors of make variable setting.";
      4  1.1  christos 
      5  1.1  christos $details = "";
      6  1.1  christos 
      7  1.1  christos open(MAKEFILE, "> $makefile");
      8  1.1  christos 
      9  1.1  christos # The Contents of the MAKEFILE ...
     10  1.1  christos 
     11  1.1  christos print MAKEFILE <<'EOF';
     12  1.1  christos foo = $(bar)
     13  1.1  christos bar = ${ugh}
     14  1.1  christos ugh = Hello
     15  1.1  christos 
     16  1.1  christos all: multi ; @echo $(foo)
     17  1.1  christos 
     18  1.1  christos multi: ; $(multi)
     19  1.1  christos 
     20  1.1  christos x := foo
     21  1.1  christos y := $(x) bar
     22  1.1  christos x := later
     23  1.1  christos 
     24  1.1  christos nullstring :=
     25  1.1  christos space := $(nullstring) $(nullstring)
     26  1.1  christos 
     27  1.1  christos next: ; @echo $x$(space)$y
     28  1.1  christos 
     29  1.1  christos define multi
     30  1.1  christos @echo hi
     31  1.1  christos echo there
     32  1.1  christos endef
     33  1.1  christos 
     34  1.1  christos ifdef BOGUS
     35  1.1  christos define
     36  1.1  christos @echo error
     37  1.1  christos endef
     38  1.1  christos endif
     39  1.1  christos 
     40  1.1  christos define outer
     41  1.1  christos  define inner
     42  1.1  christos   A = B
     43  1.1  christos  endef
     44  1.1  christos endef
     45  1.1  christos 
     46  1.1  christos $(eval $(outer))
     47  1.1  christos 
     48  1.1  christos outer: ; @echo $(inner)
     49  1.1  christos 
     50  1.1  christos EOF
     51  1.1  christos 
     52  1.1  christos # END of Contents of MAKEFILE
     53  1.1  christos 
     54  1.1  christos close(MAKEFILE);
     55  1.1  christos 
     56  1.1  christos # TEST #1
     57  1.1  christos # -------
     58  1.1  christos 
     59  1.1  christos &run_make_with_options($makefile, "", &get_logfile);
     60  1.1  christos $answer = "hi\necho there\nthere\nHello\n";
     61  1.1  christos &compare_output($answer, &get_logfile(1));
     62  1.1  christos 
     63  1.1  christos # TEST #2
     64  1.1  christos # -------
     65  1.1  christos 
     66  1.1  christos &run_make_with_options($makefile, "next", &get_logfile);
     67  1.1  christos $answer = "later foo bar\n";
     68  1.1  christos &compare_output($answer, &get_logfile(1));
     69  1.1  christos 
     70  1.1  christos # TEST #3
     71  1.1  christos # -------
     72  1.1  christos 
     73  1.1  christos &run_make_with_options($makefile, "BOGUS=true", &get_logfile, 512);
     74  1.1  christos $answer = "$makefile:24: *** empty variable name.  Stop.\n";
     75  1.1  christos &compare_output($answer, &get_logfile(1));
     76  1.1  christos 
     77  1.1  christos # TEST #4
     78  1.1  christos # -------
     79  1.1  christos 
     80  1.1  christos &run_make_with_options($makefile, "outer", &get_logfile);
     81  1.1  christos $answer = "A = B\n";
     82  1.1  christos &compare_output($answer, &get_logfile(1));
     83  1.1  christos 
     84  1.1  christos # Clean up from "old style" testing.  If all the above tests are converted to
     85  1.1  christos # run_make_test() syntax than this line can be removed.
     86  1.1  christos $makefile = undef;
     87  1.1  christos 
     88  1.1  christos # -------------------------
     89  1.1  christos # Make sure that prefix characters apply properly to define/endef values.
     90  1.1  christos #
     91  1.1  christos # There's a bit of oddness here if you try to use a variable to hold the
     92  1.1  christos # prefix character for a define.  Even though something like this:
     93  1.1  christos #
     94  1.1  christos #       define foo
     95  1.1  christos #       echo bar
     96  1.1  christos #       endef
     97  1.1  christos #
     98  1.1  christos #       all: ; $(V)$(foo)
     99  1.1  christos #
    100  1.1  christos # (where V=@) can be seen by the user to be obviously different than this:
    101  1.1  christos #
    102  1.1  christos #       define foo
    103  1.1  christos #       $(V)echo bar
    104  1.1  christos #       endef
    105  1.1  christos #
    106  1.1  christos #       all: ; $(foo)
    107  1.1  christos #
    108  1.1  christos # and the user thinks it should behave the same as when the "@" is literal
    109  1.1  christos # instead of in a variable, that can't happen because by the time make
    110  1.1  christos # expands the variables for the command line and sees it begins with a "@" it
    111  1.1  christos # can't know anymore whether the prefix character came before the variable
    112  1.1  christos # reference or was included in the first line of the variable reference.
    113  1.1  christos 
    114  1.1  christos # TEST #5
    115  1.1  christos # -------
    116  1.1  christos 
    117  1.1  christos run_make_test('
    118  1.1  christos define FOO
    119  1.1  christos $(V1)echo hello
    120  1.1  christos $(V2)echo world
    121  1.1  christos endef
    122  1.1  christos all: ; @$(FOO)
    123  1.1  christos ', '', 'hello
    124  1.1  christos world');
    125  1.1  christos 
    126  1.1  christos # TEST #6
    127  1.1  christos # -------
    128  1.1  christos 
    129  1.1  christos run_make_test(undef, 'V1=@ V2=@', 'hello
    130  1.1  christos world');
    131  1.1  christos 
    132  1.1  christos # TEST #7
    133  1.1  christos # -------
    134  1.1  christos 
    135  1.1  christos run_make_test('
    136  1.1  christos define FOO
    137  1.1  christos $(V1)echo hello
    138  1.1  christos $(V2)echo world
    139  1.1  christos endef
    140  1.1  christos all: ; $(FOO)
    141  1.1  christos ', 'V1=@', 'hello
    142  1.1  christos echo world
    143  1.1  christos world');
    144  1.1  christos 
    145  1.1  christos # TEST #8
    146  1.1  christos # -------
    147  1.1  christos 
    148  1.1  christos run_make_test(undef, 'V2=@', 'echo hello
    149  1.1  christos hello
    150  1.1  christos world');
    151  1.1  christos 
    152  1.1  christos # TEST #9
    153  1.1  christos # -------
    154  1.1  christos 
    155  1.1  christos run_make_test(undef, 'V1=@ V2=@', 'hello
    156  1.1  christos world');
    157  1.1  christos 
    158  1.1  christos # TEST #10
    159  1.1  christos # -------
    160  1.1  christos # Test the basics; a "@" internally to the variable applies to only one line.
    161  1.1  christos # A "@" before the variable applies to the entire variable.
    162  1.1  christos 
    163  1.1  christos run_make_test('
    164  1.1  christos define FOO
    165  1.1  christos @echo hello
    166  1.1  christos echo world
    167  1.1  christos endef
    168  1.1  christos define BAR
    169  1.1  christos echo hello
    170  1.1  christos echo world
    171  1.1  christos endef
    172  1.1  christos 
    173  1.1  christos all: foo bar
    174  1.1  christos foo: ; $(FOO)
    175  1.1  christos bar: ; @$(BAR)
    176  1.1  christos ', '', 'hello
    177  1.1  christos echo world
    178  1.1  christos world
    179  1.1  christos hello
    180  1.1  christos world
    181  1.1  christos ');
    182  1.1  christos 
    183  1.1  christos 1;
    184