Control characters are now allowed as part of the password, if
[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".
f730b86a 79"CFLAGS = -mno-cygwin -Wall -O2 -D_WINDOWS -DDEBUG -DWIN32S_COMPAT -D_NO_OLDNAMES -I.\n".
80"LDFLAGS = -mno-cygwin -s\n".
83623b0a 81"RCFLAGS = \$(RCINC) --define WIN32=1 --define _WIN32=1 --define WINVER=0x0400 --define MINGW32_FIX=1\n".
a58a1526 82"LIBS = -ladvapi32 -luser32 -lgdi32 -lwsock32 -lcomctl32 -lcomdlg32 -lwinmm\n".
3d541627 83"OBJ=o\n".
f730b86a 84"RES=res.o\n".
3d541627 85"\n";
86print $store{"objdefs"};
87print
88"\n".
89".SUFFIXES:\n".
90"\n".
201e9294 91"%.o: %.c\n".
3d541627 92"\t\$(CC) \$(FWHACK) \$(CFLAGS) -c \$<\n".
93"\n".
f730b86a 94"%.res.o: %.rc\n".
6ed3635b 95"\t\$(RC) \$(FWHACK) \$(RCFL) \$(RCFLAGS) \$< \$\@\n".
3d541627 96"\n";
14232990 97print "all:";
98print map { " $_.exe" } @projects;
99print "\n\n";
3d541627 100foreach $p (@projects) {
101 print $p, ".exe: ", &project($p), "\n";
f730b86a 102 my $mw = $gui{$p} ? " -mwindows" : "";
6d2d5e8d 103 $libstr = "";
104 foreach $lib (@{$libs{$p}}) { $libstr .= " -l$lib"; }
105 print "\t\$(CC)" . $mw . " \$(LDFLAGS) -o \$@ " . &project($p), " \$(LIBS)$libstr\n\n";
3d541627 106}
107print $store{"dependencies"};
108print
109"\n".
74091dff 110"version.o: FORCE;\n".
3d541627 111"# Hack to force version.o to be rebuilt always\n".
112"FORCE:\n".
201e9294 113"\t\$(CC) \$(FWHACK) \$(CFLAGS) \$(VER) -c version.c\n\n".
3d541627 114"clean:\n".
115"\trm -f *.o *.exe *.res\n".
116"\n";
117select STDOUT; close OUT;
118
119##-- Borland makefile
120open OUT, ">Makefile.bor"; select OUT;
121print
a7088bde 122"# Makefile for PuTTY under Borland C++.\n";
3d541627 123# bcc32 command line option is -D not /D
124($_ = $store{"help"}) =~ s/=\/D/=-D/gs;
125print $_;
126print
127"\n".
128"# If you rename this file to `Makefile', you should change this line,\n".
129"# so that the .rsp files still depend on the correct makefile.\n".
130"MAKEFILE = Makefile.bor\n".
131"\n".
3d541627 132"# Get include directory for resource compiler\n".
133"!if !\$d(BCB)\n".
134"BCB = \$(MAKEDIR)\\..\n".
135"!endif\n".
136"\n".
137".c.obj:\n".
138"\tbcc32 \$(COMPAT) \$(FWHACK) \$(CFLAGS) /c \$*.c\n".
139".rc.res:\n".
a7088bde 140"\tbrcc32 \$(FWHACK) \$(RCFL) -i \$(BCB)\\include \\\n".
141"\t\t-r -DNO_WINRESRC_H -DWIN32 -D_WIN32 -DWINVER=0x0400 \$*.rc\n".
3d541627 142"\n".
143"OBJ=obj\n".
144"RES=res\n".
145"\n";
146print $store{"objdefs"};
147print "\n";
148print "all:";
149print map { " $_.exe" } @projects;
150print "\n\n";
151foreach $p (@projects) {
152 print $p, ".exe: ", &project($p), " $p.rsp\n";
e2f8bc05 153 $ap = $gui{$p} ? " -aa" : " -ap";
a7088bde 154 print "\tilink32$ap -Gn -L\$(BCB)\\lib \@$p.rsp\n\n";
3d541627 155}
156foreach $p (@projects) {
157 print $p, ".rsp: \$(MAKEFILE)\n";
a7088bde 158 $c0w = $gui{$p} ? "c0w32" : "c0x32";
159 print "\techo $c0w + > $p.rsp\n";
160 @objlines = &projlist("objects.$p");
161 for ($i=0; $i<=$#objlines; $i++) {
162 $plus = ($i < $#objlines ? " +" : "");
163 print "\techo \$($objlines[$i])$plus >> $p.rsp\n";
3d541627 164 }
a7088bde 165 print "\techo $p.exe >> $p.rsp\n";
6d2d5e8d 166 @libs = @{$libs{$p}};
167 unshift @libs, "cw32", "import32";
168 $libstr = join ' ', @libs;
169 print "\techo nul,$libstr, >> $p.rsp\n";
a7088bde 170 print "\techo " . (join " ", &project("resources.$p")) . " >> $p.rsp\n";
3d541627 171 print "\n";
172}
173print $store{"dependencies"};
174print
175"\n".
176"version.o: FORCE\n".
177"# Hack to force version.o to be rebuilt always\n".
178"FORCE:\n".
179"\tbcc32 \$(FWHACK) \$(VER) \$(CFLAGS) /c version.c\n\n".
180"clean:\n".
181"\tdel *.obj\n".
182"\tdel *.exe\n".
183"\tdel *.res\n".
184"\tdel *.pch\n".
185"\tdel *.aps\n".
a7088bde 186"\tdel *.il*\n".
3d541627 187"\tdel *.pdb\n".
a7088bde 188"\tdel *.rsp\n".
189"\tdel *.tds\n".
190"\tdel *.\$\$\$\$\$\$\n";
3d541627 191select STDOUT; close OUT;