File: updmake

package info (click to toggle)
c2man 2.41-11
  • links: PTS
  • area: main
  • in suites: potato
  • size: 800 kB
  • ctags: 863
  • sloc: ansic: 6,559; sh: 5,236; yacc: 839; lex: 621; makefile: 229; perl: 81
file content (99 lines) | stat: -rw-r--r-- 1,889 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#!/usr/local/bin/perl -w
# This script updates the MSDOS & OS/2 Makefile.pc automatically from the Unix
# one to minimise the possibility of me making a mistake.
# It's a gross hack, but it works.
open(MAKEFILE, "../Makefile") || die;
rename("Makefile.pc", "Makefile.old") || die;
open(PREVIOUS, "Makefile.old") || die;
open(OUTPUT, ">Makefile.pc") || die;

# skip the header from the Unix Makefile.
do { $_ = <MAKEFILE>; } until m/^SHELL=/o;

# retain the previous header from the PC Makefile.
while (<PREVIOUS>)
{
	print OUTPUT;
	last if /# DO NOT EDIT/;
}

while (<MAKEFILE>)
{
	if ($_ eq "MAKE=make\n")
	{
		while (<MAKEFILE>)
		{
			last unless $_ eq "\n";
		}
	}

	next if /chmod/o;
	s/\.o(\W)/\$O\1/go;
	s/\.o$/\$O/o;
	s/c2man([^.])/c2man.exe\1/ if (/:/ || /cp /);
	s/^(install:) all$/\1/;
	if (/\$\(LEX\) (.*)/)
	{
		print OUTPUT "\t\$(LEX) -t $1 > \$@";
		print OUTPUT "\n";
		$_ = "\tcp \$@ lex_yy.c\n";
	}
	print OUTPUT;
	print OUTPUT "\t\$(BIND)\n" if (/\$\(LDFLAGS\) /);
	last if m/^# y.tab.c dependancies/o;
}

# output dependancies grouped into lines.
sub output_depend
{
	return if $current eq "";

	$chars = length($current) + 1;
	$current =~ s/\.o$/\$O/o;
	print OUTPUT $current, ":";
	foreach $file (@depends)
	{
		$chars += 1 + length($file);
		if ($chars > 77)
		{
			print OUTPUT "\\\n\t";
			$chars = 8 + length($file);
		}
		else
		{
			print OUTPUT " ";
		}
		print OUTPUT $file;
	}
	print OUTPUT "\n\n";
	$current = "";
	undef @depends;
}

# process the dependancies a bit.
$current = "";
undef @depends;
while (<MAKEFILE>)
{
	if (m/^#/ || $_ eq "\n")
	{
		&output_depend;
		print OUTPUT;
		next;
	}

	# have we found a dependancy?
	if (($obj,$dep) = m/^(.*):\s*(.*)/)
	{
		next if ($dep =~ m!^/!);	# ignore /usr/include
		if ($obj ne $current)
		{
			&output_depend;
			$current = $obj;
		}
		$dep =~ s!^\./!!;
		push(@depends, $dep);
	}
}

close OUTPUT || die;