Jacob Nevins provided this workaround for a bug in mingw32's resource
[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/^# //;
32 $gui{$i} = 1;
33}
34
35foreach $i (split '\n',$store{'console-apps'}) {
36 $i =~ s/^# //;
37 $gui{$i} = -0;
38}
39
40sub project {
41 my ($p) = @_;
42 my ($q) = $store{"$p"} . $store{"objects.$p"} . $store{"resources.$p"};
43 $q =~ s/(\S+)\s[^\n]*\n/\$($1) /gs;
44 $q =~ s/ $//;
45 $q;
46}
47
48sub projlist {
49 my ($p) = @_;
50 my ($q) = $store{"$p"} . $store{"objects.$p"} . $store{"resources.$p"};
51 $q =~ s/(\S+)\s[^\n]*\n/$1 /gs;
52 my (@q) = split ' ',$q;
53 @q;
54}
55
56##-- CygWin makefile
57open OUT, ">Makefile.cyg"; select OUT;
58print
59"# Makefile for PuTTY under cygwin.\n";
60# gcc command line option is -D not /D
61($_ = $store{"help"}) =~ s/=\/D/=-D/gs;
62print $_;
63print
64"\n".
65"# You can define this path to point at your tools if you need to\n".
66"# TOOLPATH = c:\\cygwin\\bin\\ # or similar, if you're running Windows\n".
67"# TOOLPATH = /pkg/mingw32msvc/i386-mingw32msvc/bin/\n".
68"CC = \$(TOOLPATH)gcc\n".
69"RC = \$(TOOLPATH)windres\n".
70"# You may also need to tell windres where to find include files:\n".
71"# RCINC = --include-dir c:\\cygwin\\include\\\n".
72"\n".
f730b86a 73"CFLAGS = -mno-cygwin -Wall -O2 -D_WINDOWS -DDEBUG -DWIN32S_COMPAT -D_NO_OLDNAMES -I.\n".
74"LDFLAGS = -mno-cygwin -s\n".
3d541627 75"RCFLAGS = \$(RCINC) --define WIN32=1 --define _WIN32=1 --define WINVER=0x0400\n".
76"LIBS = -ladvapi32 -luser32 -lgdi32 -lwsock32 -lcomctl32 -lcomdlg32\n".
77"OBJ=o\n".
f730b86a 78"RES=res.o\n".
3d541627 79"\n";
80print $store{"objdefs"};
81print
82"\n".
83".SUFFIXES:\n".
84"\n".
201e9294 85"%.o: %.c\n".
3d541627 86"\t\$(CC) \$(FWHACK) \$(CFLAGS) -c \$<\n".
87"\n".
f730b86a 88"%.res.o: %.rc\n".
6ed3635b 89"\t\$(RC) \$(FWHACK) \$(RCFL) \$(RCFLAGS) \$< \$\@\n".
3d541627 90"\n";
91foreach $p (@projects) {
92 print $p, ".exe: ", &project($p), "\n";
f730b86a 93 my $mw = $gui{$p} ? " -mwindows" : "";
94 print "\t\$(CC)" . $mw . " \$(LDFLAGS) -o \$@ " . &project($p), " \$(LIBS)\n\n";
3d541627 95}
96print $store{"dependencies"};
97print
98"\n".
74091dff 99"version.o: FORCE;\n".
3d541627 100"# Hack to force version.o to be rebuilt always\n".
101"FORCE:\n".
201e9294 102"\t\$(CC) \$(FWHACK) \$(CFLAGS) \$(VER) -c version.c\n\n".
3d541627 103"clean:\n".
104"\trm -f *.o *.exe *.res\n".
105"\n";
106select STDOUT; close OUT;
107
108##-- Borland makefile
109open OUT, ">Makefile.bor"; select OUT;
110print
a7088bde 111"# Makefile for PuTTY under Borland C++.\n";
3d541627 112# bcc32 command line option is -D not /D
113($_ = $store{"help"}) =~ s/=\/D/=-D/gs;
114print $_;
115print
116"\n".
117"# If you rename this file to `Makefile', you should change this line,\n".
118"# so that the .rsp files still depend on the correct makefile.\n".
119"MAKEFILE = Makefile.bor\n".
120"\n".
121"# Stop windows.h including winsock2.h which would conflict with winsock 1\n".
122"CFLAGS = -DWIN32_LEAN_AND_MEAN\n".
123"\n".
124"# Get include directory for resource compiler\n".
125"!if !\$d(BCB)\n".
126"BCB = \$(MAKEDIR)\\..\n".
127"!endif\n".
128"\n".
129".c.obj:\n".
130"\tbcc32 \$(COMPAT) \$(FWHACK) \$(CFLAGS) /c \$*.c\n".
131".rc.res:\n".
a7088bde 132"\tbrcc32 \$(FWHACK) \$(RCFL) -i \$(BCB)\\include \\\n".
133"\t\t-r -DNO_WINRESRC_H -DWIN32 -D_WIN32 -DWINVER=0x0400 \$*.rc\n".
3d541627 134"\n".
135"OBJ=obj\n".
136"RES=res\n".
137"\n";
138print $store{"objdefs"};
139print "\n";
140print "all:";
141print map { " $_.exe" } @projects;
142print "\n\n";
143foreach $p (@projects) {
144 print $p, ".exe: ", &project($p), " $p.rsp\n";
e2f8bc05 145 $ap = $gui{$p} ? " -aa" : " -ap";
a7088bde 146 print "\tilink32$ap -Gn -L\$(BCB)\\lib \@$p.rsp\n\n";
3d541627 147}
148foreach $p (@projects) {
149 print $p, ".rsp: \$(MAKEFILE)\n";
a7088bde 150 $c0w = $gui{$p} ? "c0w32" : "c0x32";
151 print "\techo $c0w + > $p.rsp\n";
152 @objlines = &projlist("objects.$p");
153 for ($i=0; $i<=$#objlines; $i++) {
154 $plus = ($i < $#objlines ? " +" : "");
155 print "\techo \$($objlines[$i])$plus >> $p.rsp\n";
3d541627 156 }
a7088bde 157 print "\techo $p.exe >> $p.rsp\n";
158 print "\techo nul,cw32 import32, >> $p.rsp\n";
159 print "\techo " . (join " ", &project("resources.$p")) . " >> $p.rsp\n";
3d541627 160 print "\n";
161}
162print $store{"dependencies"};
163print
164"\n".
165"version.o: FORCE\n".
166"# Hack to force version.o to be rebuilt always\n".
167"FORCE:\n".
168"\tbcc32 \$(FWHACK) \$(VER) \$(CFLAGS) /c version.c\n\n".
169"clean:\n".
170"\tdel *.obj\n".
171"\tdel *.exe\n".
172"\tdel *.res\n".
173"\tdel *.pch\n".
174"\tdel *.aps\n".
a7088bde 175"\tdel *.il*\n".
3d541627 176"\tdel *.pdb\n".
a7088bde 177"\tdel *.rsp\n".
178"\tdel *.tds\n".
179"\tdel *.\$\$\$\$\$\$\n";
3d541627 180select STDOUT; close OUT;