3d541627 |
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/^# //; |
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 | |
38 | foreach $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 | |
46 | sub 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 | |
54 | sub 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 |
63 | open OUT, ">Makefile.cyg"; select OUT; |
64 | print |
65 | "# Makefile for PuTTY under cygwin.\n"; |
66 | # gcc command line option is -D not /D |
67 | ($_ = $store{"help"}) =~ s/=\/D/=-D/gs; |
68 | print $_; |
69 | print |
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". |
1cc8558b |
83 | "LIBS = -ladvapi32 -luser32 -lgdi32 -lwsock32 -lcomctl32 -lcomdlg32 -lwinmm -limm32\n". |
3d541627 |
84 | "OBJ=o\n". |
f730b86a |
85 | "RES=res.o\n". |
3d541627 |
86 | "\n"; |
87 | print $store{"objdefs"}; |
88 | print |
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 |
98 | print "all:"; |
99 | print map { " $_.exe" } @projects; |
100 | print "\n\n"; |
3d541627 |
101 | foreach $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 | } |
108 | print $store{"dependencies"}; |
109 | print |
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"; |
118 | select STDOUT; close OUT; |
119 | |
120 | ##-- Borland makefile |
121 | open OUT, ">Makefile.bor"; select OUT; |
122 | print |
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; |
126 | print $_; |
127 | print |
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"; |
150 | print $store{"objdefs"}; |
151 | print "\n"; |
152 | print "all:"; |
153 | print map { " $_.exe" } @projects; |
154 | print "\n\n"; |
155 | foreach $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 | } |
160 | foreach $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 | } |
177 | print $store{"dependencies"}; |
178 | print |
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 |
195 | select STDOUT; close OUT; |