Borland makefile should now work sanely with the free-beer bcc55
[sgt/putty] / mkfiles.pl
1 #!/usr/bin/env perl
2 #
3 # Makefile generator.
4 # Produces the other PuTTY makefiles from the master one.
5
6 open IN,"Makefile";
7 @current = ();
8 while (<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 }
27 close IN;
28 @projects = keys %projects;
29
30 foreach $i (split '\n',$store{'gui-apps'}) {
31 $i =~ s/^# //;
32 $gui{$i} = 1;
33 }
34
35 foreach $i (split '\n',$store{'console-apps'}) {
36 $i =~ s/^# //;
37 $gui{$i} = -0;
38 }
39
40 sub 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
48 sub 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
57 open OUT, ">Makefile.cyg"; select OUT;
58 print
59 "# Makefile for PuTTY under cygwin.\n";
60 # gcc command line option is -D not /D
61 ($_ = $store{"help"}) =~ s/=\/D/=-D/gs;
62 print $_;
63 print
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".
73 "CFLAGS = -mno-cygwin -Wall -O2 -D_WINDOWS -DDEBUG -DWIN32S_COMPAT -D_NO_OLDNAMES -I.\n".
74 "LDFLAGS = -mno-cygwin -s\n".
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".
78 "RES=res.o\n".
79 "\n";
80 print $store{"objdefs"};
81 print
82 "\n".
83 ".SUFFIXES:\n".
84 "\n".
85 "%.o: %.c\n".
86 "\t\$(CC) \$(FWHACK) \$(CFLAGS) -c \$<\n".
87 "\n".
88 "%.res.o: %.rc\n".
89 "\t\$(RC) \$(FWHACK) \$(RCFL) \$(RCFLAGS) \$< \$\@\n".
90 "\n";
91 foreach $p (@projects) {
92 print $p, ".exe: ", &project($p), "\n";
93 my $mw = $gui{$p} ? " -mwindows" : "";
94 print "\t\$(CC)" . $mw . " \$(LDFLAGS) -o \$@ " . &project($p), " \$(LIBS)\n\n";
95 }
96 print $store{"dependencies"};
97 print
98 "\n".
99 "version.o: FORCE;\n".
100 "# Hack to force version.o to be rebuilt always\n".
101 "FORCE:\n".
102 "\t\$(CC) \$(FWHACK) \$(CFLAGS) \$(VER) -c version.c\n\n".
103 "clean:\n".
104 "\trm -f *.o *.exe *.res\n".
105 "\n";
106 select STDOUT; close OUT;
107
108 ##-- Borland makefile
109 open OUT, ">Makefile.bor"; select OUT;
110 print
111 "# Makefile for PuTTY under Borland C++.\n";
112 # bcc32 command line option is -D not /D
113 ($_ = $store{"help"}) =~ s/=\/D/=-D/gs;
114 print $_;
115 print
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".
132 "\tbrcc32 \$(FWHACK) \$(RCFL) -i \$(BCB)\\include \\\n".
133 "\t\t-r -DNO_WINRESRC_H -DWIN32 -D_WIN32 -DWINVER=0x0400 \$*.rc\n".
134 "\n".
135 "OBJ=obj\n".
136 "RES=res\n".
137 "\n";
138 print $store{"objdefs"};
139 print "\n";
140 print "all:";
141 print map { " $_.exe" } @projects;
142 print "\n\n";
143 foreach $p (@projects) {
144 print $p, ".exe: ", &project($p), " $p.rsp\n";
145 $ap = $gui{$p} ? "" : " -ap";
146 print "\tilink32$ap -Gn -L\$(BCB)\\lib \@$p.rsp\n\n";
147 }
148 foreach $p (@projects) {
149 print $p, ".rsp: \$(MAKEFILE)\n";
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";
156 }
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";
160 print "\n";
161 }
162 print $store{"dependencies"};
163 print
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".
175 "\tdel *.il*\n".
176 "\tdel *.pdb\n".
177 "\tdel *.rsp\n".
178 "\tdel *.tds\n".
179 "\tdel *.\$\$\$\$\$\$\n";
180 select STDOUT; close OUT;