Fix multi-monitor / full-screen problems and clean up the code a
[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".
c21335cd 83"LIBS = -ladvapi32 -luser32 -lgdi32 -lwsock32 -lcomctl32 -lcomdlg32 -lwinmm -limm32 -lwinspool\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".
a401e5f3 133"# C compilation flags\n".
134"CFLAGS = -DWINVER=0x0401\n".
135"\n".
3d541627 136"# Get include directory for resource compiler\n".
137"!if !\$d(BCB)\n".
138"BCB = \$(MAKEDIR)\\..\n".
139"!endif\n".
140"\n".
141".c.obj:\n".
5b0ac8c3 142"\tbcc32 -w-aus -w-ccc -w-par \$(COMPAT) \$(FWHACK) \$(XFLAGS) \$(CFLAGS) /c \$*.c\n".
3d541627 143".rc.res:\n".
a7088bde 144"\tbrcc32 \$(FWHACK) \$(RCFL) -i \$(BCB)\\include \\\n".
a401e5f3 145"\t\t-r -DNO_WINRESRC_H -DWIN32 -D_WIN32 -DWINVER=0x0401 \$*.rc\n".
3d541627 146"\n".
147"OBJ=obj\n".
148"RES=res\n".
149"\n";
150print $store{"objdefs"};
151print "\n";
152print "all:";
153print map { " $_.exe" } @projects;
154print "\n\n";
155foreach $p (@projects) {
156 print $p, ".exe: ", &project($p), " $p.rsp\n";
e2f8bc05 157 $ap = $gui{$p} ? " -aa" : " -ap";
a7088bde 158 print "\tilink32$ap -Gn -L\$(BCB)\\lib \@$p.rsp\n\n";
3d541627 159}
160foreach $p (@projects) {
161 print $p, ".rsp: \$(MAKEFILE)\n";
a7088bde 162 $c0w = $gui{$p} ? "c0w32" : "c0x32";
163 print "\techo $c0w + > $p.rsp\n";
164 @objlines = &projlist("objects.$p");
165 for ($i=0; $i<=$#objlines; $i++) {
166 $plus = ($i < $#objlines ? " +" : "");
167 print "\techo \$($objlines[$i])$plus >> $p.rsp\n";
3d541627 168 }
a7088bde 169 print "\techo $p.exe >> $p.rsp\n";
6d2d5e8d 170 @libs = @{$libs{$p}};
171 unshift @libs, "cw32", "import32";
172 $libstr = join ' ', @libs;
173 print "\techo nul,$libstr, >> $p.rsp\n";
a7088bde 174 print "\techo " . (join " ", &project("resources.$p")) . " >> $p.rsp\n";
3d541627 175 print "\n";
176}
177print $store{"dependencies"};
178print
179"\n".
180"version.o: FORCE\n".
181"# Hack to force version.o to be rebuilt always\n".
182"FORCE:\n".
183"\tbcc32 \$(FWHACK) \$(VER) \$(CFLAGS) /c version.c\n\n".
184"clean:\n".
2e792012 185"\t-del *.obj\n".
186"\t-del *.exe\n".
187"\t-del *.res\n".
188"\t-del *.pch\n".
189"\t-del *.aps\n".
190"\t-del *.il*\n".
191"\t-del *.pdb\n".
192"\t-del *.rsp\n".
193"\t-del *.tds\n".
194"\t-del *.\$\$\$\$\$\$\n";
3d541627 195select STDOUT; close OUT;