Bah. Add winspool.lib to libraries list. Maybe _now_ the nightly
[u/mdw/putty] / mkfiles.pl
... / ...
CommitLineData
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/^# //;
32 $speciallibs = [split ' ', $i];
33 $i = shift @$speciallibs; # take off project name
34 $gui{$i} = 1;
35 $libs{$i} = $speciallibs;
36}
37
38foreach $i (split '\n',$store{'console-apps'}) {
39 $i =~ s/^# //;
40 $speciallibs = [split ' ', $i];
41 $i = shift @$speciallibs; # take off project name
42 $gui{$i} = 0;
43 $libs{$i} = $speciallibs;
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".
79"CFLAGS = -mno-cygwin -Wall -O2 -D_WINDOWS -DDEBUG -DWIN32S_COMPAT".
80 " -DNO_SECURITY -D_NO_OLDNAMES -I.\n".
81"LDFLAGS = -mno-cygwin -s\n".
82"RCFLAGS = \$(RCINC) --define WIN32=1 --define _WIN32=1 --define WINVER=0x0400 --define MINGW32_FIX=1\n".
83"LIBS = -ladvapi32 -luser32 -lgdi32 -lwsock32 -lcomctl32 -lcomdlg32 -lwinmm -limm32 -lwinspool\n".
84"OBJ=o\n".
85"RES=res.o\n".
86"\n";
87print $store{"objdefs"};
88print
89"\n".
90".SUFFIXES:\n".
91"\n".
92"%.o: %.c\n".
93"\t\$(CC) \$(COMPAT) \$(FWHACK) \$(XFLAGS) \$(CFLAGS) -c \$<\n".
94"\n".
95"%.res.o: %.rc\n".
96"\t\$(RC) \$(FWHACK) \$(RCFL) \$(RCFLAGS) \$< \$\@\n".
97"\n";
98print "all:";
99print map { " $_.exe" } @projects;
100print "\n\n";
101foreach $p (@projects) {
102 print $p, ".exe: ", &project($p), "\n";
103 my $mw = $gui{$p} ? " -mwindows" : "";
104 $libstr = "";
105 foreach $lib (@{$libs{$p}}) { $libstr .= " -l$lib"; }
106 print "\t\$(CC)" . $mw . " \$(LDFLAGS) -o \$@ " . &project($p), " \$(LIBS)$libstr\n\n";
107}
108print $store{"dependencies"};
109print
110"\n".
111"version.o: FORCE;\n".
112"# Hack to force version.o to be rebuilt always\n".
113"FORCE:\n".
114"\t\$(CC) \$(FWHACK) \$(CFLAGS) \$(VER) -c version.c\n\n".
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
123"# Makefile for PuTTY under Borland C++.\n";
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".
133"# C compilation flags\n".
134"CFLAGS = -DWINVER=0x0401\n".
135"\n".
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".
142"\tbcc32 -w-aus -w-ccc -w-par \$(COMPAT) \$(FWHACK) \$(XFLAGS) \$(CFLAGS) /c \$*.c\n".
143".rc.res:\n".
144"\tbrcc32 \$(FWHACK) \$(RCFL) -i \$(BCB)\\include \\\n".
145"\t\t-r -DNO_WINRESRC_H -DWIN32 -D_WIN32 -DWINVER=0x0401 \$*.rc\n".
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";
157 $ap = $gui{$p} ? " -aa" : " -ap";
158 print "\tilink32$ap -Gn -L\$(BCB)\\lib \@$p.rsp\n\n";
159}
160foreach $p (@projects) {
161 print $p, ".rsp: \$(MAKEFILE)\n";
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";
168 }
169 print "\techo $p.exe >> $p.rsp\n";
170 @libs = @{$libs{$p}};
171 unshift @libs, "cw32", "import32";
172 $libstr = join ' ', @libs;
173 print "\techo nul,$libstr, >> $p.rsp\n";
174 print "\techo " . (join " ", &project("resources.$p")) . " >> $p.rsp\n";
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".
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";
195select STDOUT; close OUT;