xref: /netbsd-src/external/gpl2/gmake/dist/tests/scripts/options/symlinks (revision 69606e3f5c9388e52aed8c120ad63c049ca45d8f)
1*69606e3fSchristos#                                                                    -*-perl-*-
2*69606e3fSchristos
3*69606e3fSchristos$description = "Test the -L option.";
4*69606e3fSchristos
5*69606e3fSchristos$details = "Verify that symlink handling with and without -L works properly.";
6*69606e3fSchristos
7*69606e3fSchristos# Only run these tests if the system sypports symlinks
8*69606e3fSchristos
9*69606e3fSchristos# Apparently the Windows port of Perl reports that it does support symlinks
10*69606e3fSchristos# (in that the symlink() function doesn't fail) but it really doesn't, so
11*69606e3fSchristos# check for it explicitly.
12*69606e3fSchristos
13*69606e3fSchristosif ($port_type eq 'W32' || !( eval { symlink("",""); 1 })) {
14*69606e3fSchristos  # This test is N/A
15*69606e3fSchristos  -1;
16*69606e3fSchristos} else {
17*69606e3fSchristos
18*69606e3fSchristos  # Set up a symlink sym -> dep
19*69606e3fSchristos  # We'll make both dep and targ older than sym
20*69606e3fSchristos  $pwd =~ m%/([^/]+)$%;
21*69606e3fSchristos  $dirnm = $1;
22*69606e3fSchristos  &utouch(-10, 'dep');
23*69606e3fSchristos  &utouch(-5, 'targ');
24*69606e3fSchristos  symlink("../$dirnm/dep", 'sym');
25*69606e3fSchristos
26*69606e3fSchristos  # Without -L, nothing should happen
27*69606e3fSchristos  # With -L, it should update targ
28*69606e3fSchristos  run_make_test('targ: sym ; @echo make $@ from $<', '',
29*69606e3fSchristos                "#MAKE#: `targ' is up to date.");
30*69606e3fSchristos  run_make_test(undef, '-L', "make targ from sym");
31*69606e3fSchristos
32*69606e3fSchristos  # Now update dep; in all cases targ should be out of date.
33*69606e3fSchristos  &touch('dep');
34*69606e3fSchristos  run_make_test(undef, '', "make targ from sym");
35*69606e3fSchristos  run_make_test(undef, '-L', "make targ from sym");
36*69606e3fSchristos
37*69606e3fSchristos  # Now update targ; in all cases targ should be up to date.
38*69606e3fSchristos  &touch('targ');
39*69606e3fSchristos  run_make_test(undef, '', "#MAKE#: `targ' is up to date.");
40*69606e3fSchristos  run_make_test(undef, '-L', "#MAKE#: `targ' is up to date.");
41*69606e3fSchristos
42*69606e3fSchristos  # Add in a new link between sym and dep.  Be sure it's newer than targ.
43*69606e3fSchristos  sleep(1);
44*69606e3fSchristos  rename('dep', 'dep1');
45*69606e3fSchristos  symlink('dep1', 'dep');
46*69606e3fSchristos
47*69606e3fSchristos  # Without -L, nothing should happen
48*69606e3fSchristos  # With -L, it should update targ
49*69606e3fSchristos  run_make_test(undef, '', "#MAKE#: `targ' is up to date.");
50*69606e3fSchristos  run_make_test(undef, '-L', "make targ from sym");
51*69606e3fSchristos
52*69606e3fSchristos  rmfiles('targ', 'dep', 'sym', 'dep1');
53*69606e3fSchristos
54*69606e3fSchristos  # Check handling when symlinks point to non-existent files.  Without -L we
55*69606e3fSchristos  # should get an error: with -L we should use the timestamp of the symlink.
56*69606e3fSchristos
57*69606e3fSchristos  symlink("../$dirname/dep", 'sym');
58*69606e3fSchristos  run_make_test('targ: sym ; @echo make $@ from $<', '',
59*69606e3fSchristos                "#MAKE#: *** No rule to make target `sym', needed by `targ'.  Stop.", 512);
60*69606e3fSchristos
61*69606e3fSchristos  run_make_test('targ: sym ; @echo make $@ from $<', '-L',
62*69606e3fSchristos                'make targ from sym');
63*69606e3fSchristos
64*69606e3fSchristos
65*69606e3fSchristos  rmfiles('targ', 'sym');
66*69606e3fSchristos
67*69606e3fSchristos  1;
68*69606e3fSchristos}
69