Finally remove this pile of obsoleteness
[u/mdw/putty] / mkfiles.pl
CommitLineData
3d541627 1#!/usr/bin/env perl
2#
3# Makefile generator.
4# Produces the other PuTTY makefiles from the master one.
5
6open IN,"Makefile";
7@current = ();
8while (<IN>) {
9 chomp;
10 if (/^##--/) {
11 @words = split /\s+/,$_;
12 shift @words; # remove ##--
13 $i = shift @words; # first word
14 if (!defined $i) { # no words
15 @current = ();
16 } elsif (!defined $words[0]) { # only one word
17 @current = ($i);
18 } else { # at least two words
19 @current = map { $i . "." . $_ } @words;
20 foreach $i (@words) { $projects{$i} = $i; }
21 push @current, "objdefs";
22 }
23 } else {
24 foreach $i (@current) { $store{$i} .= $_ . "\n"; }
25 }
26}
27close IN;
28@projects = keys %projects;
29
30foreach $i (split '\n',$store{'gui-apps'}) {
31 $i =~ s/^# //;
6d2d5e8d 32 $speciallibs = [split ' ', $i];
33 $i = shift @$speciallibs; # take off project name
3d541627 34 $gui{$i} = 1;
6d2d5e8d 35 $libs{$i} = $speciallibs;
3d541627 36}
37
38foreach $i (split '\n',$store{'console-apps'}) {
39 $i =~ s/^# //;
6d2d5e8d 40 $speciallibs = [split ' ', $i];
41 $i = shift @$speciallibs; # take off project name
42 $gui{$i} = 0;
43 $libs{$i} = $speciallibs;
3d541627 44}
45
46sub project {
47 my ($p) = @_;
48 my ($q) = $store{"$p"} . $store{"objects.$p"} . $store{"resources.$p"};
49 $q =~ s/(\S+)\s[^\n]*\n/\$($1) /gs;
50 $q =~ s/ $//;
51 $q;
52}
53
54sub projlist {
55 my ($p) = @_;
56 my ($q) = $store{"$p"} . $store{"objects.$p"} . $store{"resources.$p"};
57 $q =~ s/(\S+)\s[^\n]*\n/$1 /gs;
58 my (@q) = split ' ',$q;
59 @q;
60}
61
62##-- CygWin makefile
63open OUT, ">Makefile.cyg"; select OUT;
64print
65"# Makefile for PuTTY under cygwin.\n";
66# gcc command line option is -D not /D
67($_ = $store{"help"}) =~ s/=\/D/=-D/gs;
68print $_;
69print
70"\n".
71"# You can define this path to point at your tools if you need to\n".
72"# TOOLPATH = c:\\cygwin\\bin\\ # or similar, if you're running Windows\n".
73"# TOOLPATH = /pkg/mingw32msvc/i386-mingw32msvc/bin/\n".
74"CC = \$(TOOLPATH)gcc\n".
75"RC = \$(TOOLPATH)windres\n".
76"# You may also need to tell windres where to find include files:\n".
77"# RCINC = --include-dir c:\\cygwin\\include\\\n".
78"\n".
2871113a 79"CFLAGS = -mno-cygwin -Wall -O2 -D_WINDOWS -DDEBUG -DWIN32S_COMPAT".
80 " -DNO_SECURITY -D_NO_OLDNAMES -I.\n".
f730b86a 81"LDFLAGS = -mno-cygwin -s\n".
83623b0a 82"RCFLAGS = \$(RCINC) --define WIN32=1 --define _WIN32=1 --define WINVER=0x0400 --define MINGW32_FIX=1\n".
1cc8558b 83"LIBS = -ladvapi32 -luser32 -lgdi32 -lwsock32 -lcomctl32 -lcomdlg32 -lwinmm -limm32\n".
3d541627 84"OBJ=o\n".
f730b86a 85"RES=res.o\n".
3d541627 86"\n";
87print $store{"objdefs"};
88print
89"\n".
90".SUFFIXES:\n".
91"\n".
201e9294 92"%.o: %.c\n".
cf03419b 93"\t\$(CC) \$(COMPAT) \$(FWHACK) \$(XFLAGS) \$(CFLAGS) -c \$<\n".
3d541627 94"\n".
f730b86a 95"%.res.o: %.rc\n".
6ed3635b 96"\t\$(RC) \$(FWHACK) \$(RCFL) \$(RCFLAGS) \$< \$\@\n".
3d541627 97"\n";
14232990 98print "all:";
99print map { " $_.exe" } @projects;
100print "\n\n";
3d541627 101foreach $p (@projects) {
102 print $p, ".exe: ", &project($p), "\n";
f730b86a 103 my $mw = $gui{$p} ? " -mwindows" : "";
6d2d5e8d 104 $libstr = "";
105 foreach $lib (@{$libs{$p}}) { $libstr .= " -l$lib"; }
106 print "\t\$(CC)" . $mw . " \$(LDFLAGS) -o \$@ " . &project($p), " \$(LIBS)$libstr\n\n";
3d541627 107}
108print $store{"dependencies"};
109print
110"\n".
74091dff 111"version.o: FORCE;\n".
3d541627 112"# Hack to force version.o to be rebuilt always\n".
113"FORCE:\n".
201e9294 114"\t\$(CC) \$(FWHACK) \$(CFLAGS) \$(VER) -c version.c\n\n".
3d541627 115"clean:\n".
116"\trm -f *.o *.exe *.res\n".
117"\n";
118select STDOUT; close OUT;
119
120##-- Borland makefile
121open OUT, ">Makefile.bor"; select OUT;
122print
a7088bde 123"# Makefile for PuTTY under Borland C++.\n";
3d541627 124# bcc32 command line option is -D not /D
125($_ = $store{"help"}) =~ s/=\/D/=-D/gs;
126print $_;
127print
128"\n".
129"# If you rename this file to `Makefile', you should change this line,\n".
130"# so that the .rsp files still depend on the correct makefile.\n".
131"MAKEFILE = Makefile.bor\n".
132"\n".
3d541627 133"# Get include directory for resource compiler\n".
134"!if !\$d(BCB)\n".
135"BCB = \$(MAKEDIR)\\..\n".
136"!endif\n".
137"\n".
138".c.obj:\n".
5b0ac8c3 139"\tbcc32 -w-aus -w-ccc -w-par \$(COMPAT) \$(FWHACK) \$(XFLAGS) \$(CFLAGS) /c \$*.c\n".
3d541627 140".rc.res:\n".
a7088bde 141"\tbrcc32 \$(FWHACK) \$(RCFL) -i \$(BCB)\\include \\\n".
142"\t\t-r -DNO_WINRESRC_H -DWIN32 -D_WIN32 -DWINVER=0x0400 \$*.rc\n".
3d541627 143"\n".
144"OBJ=obj\n".
145"RES=res\n".
146"\n";
147print $store{"objdefs"};
148print "\n";
149print "all:";
150print map { " $_.exe" } @projects;
151print "\n\n";
152foreach $p (@projects) {
153 print $p, ".exe: ", &project($p), " $p.rsp\n";
e2f8bc05 154 $ap = $gui{$p} ? " -aa" : " -ap";
a7088bde 155 print "\tilink32$ap -Gn -L\$(BCB)\\lib \@$p.rsp\n\n";
3d541627 156}
157foreach $p (@projects) {
158 print $p, ".rsp: \$(MAKEFILE)\n";
a7088bde 159 $c0w = $gui{$p} ? "c0w32" : "c0x32";
160 print "\techo $c0w + > $p.rsp\n";
161 @objlines = &projlist("objects.$p");
162 for ($i=0; $i<=$#objlines; $i++) {
163 $plus = ($i < $#objlines ? " +" : "");
164 print "\techo \$($objlines[$i])$plus >> $p.rsp\n";
3d541627 165 }
a7088bde 166 print "\techo $p.exe >> $p.rsp\n";
6d2d5e8d 167 @libs = @{$libs{$p}};
168 unshift @libs, "cw32", "import32";
169 $libstr = join ' ', @libs;
170 print "\techo nul,$libstr, >> $p.rsp\n";
a7088bde 171 print "\techo " . (join " ", &project("resources.$p")) . " >> $p.rsp\n";
3d541627 172 print "\n";
173}
174print $store{"dependencies"};
175print
176"\n".
177"version.o: FORCE\n".
178"# Hack to force version.o to be rebuilt always\n".
179"FORCE:\n".
180"\tbcc32 \$(FWHACK) \$(VER) \$(CFLAGS) /c version.c\n\n".
181"clean:\n".
182"\tdel *.obj\n".
183"\tdel *.exe\n".
184"\tdel *.res\n".
185"\tdel *.pch\n".
186"\tdel *.aps\n".
a7088bde 187"\tdel *.il*\n".
3d541627 188"\tdel *.pdb\n".
a7088bde 189"\tdel *.rsp\n".
190"\tdel *.tds\n".
191"\tdel *.\$\$\$\$\$\$\n";
3d541627 192select STDOUT; close OUT;