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/^# //; |
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 = -g -O2 -D_WINDOWS -DDEBUG\n". |
74 | "RCFLAGS = \$(RCINC) --define WIN32=1 --define _WIN32=1 --define WINVER=0x0400\n". |
75 | "LIBS = -ladvapi32 -luser32 -lgdi32 -lwsock32 -lcomctl32 -lcomdlg32\n". |
76 | "OBJ=o\n". |
77 | "RES=res\n". |
78 | "\n"; |
79 | print $store{"objdefs"}; |
80 | print |
81 | "\n". |
82 | ".SUFFIXES:\n". |
83 | "\n". |
84 | "%.o %.obj: %.c\n". |
85 | "\t\$(CC) \$(FWHACK) \$(CFLAGS) -c \$<\n". |
86 | "\n". |
87 | "%.res: %.rc\n". |
88 | "\t\$(RC) \$(FWHACK) \$(RCFLAGS) \$<\n". |
89 | "\n"; |
90 | foreach $p (@projects) { |
91 | print $p, ".exe: ", &project($p), "\n"; |
92 | print "\t\$(CC) \$(LDFLAGS) -o \$@ " . &project($p), " \$(LIBS)\n\n"; |
93 | } |
94 | print $store{"dependencies"}; |
95 | print |
96 | "\n". |
97 | "version.o: FORCE\n". |
98 | "# Hack to force version.o to be rebuilt always\n". |
99 | "FORCE:\n". |
100 | "\t\$(CC) \$(FWHACK) \$(CFLAGS) \$(VER) -c \$<\n\n". |
101 | "clean:\n". |
102 | "\trm -f *.o *.exe *.res\n". |
103 | "\n"; |
104 | select STDOUT; close OUT; |
105 | |
106 | ##-- Borland makefile |
107 | open OUT, ">Makefile.bor"; select OUT; |
108 | print |
109 | "# Makefile for PuTTY under Borland C.\n"; |
110 | # bcc32 command line option is -D not /D |
111 | ($_ = $store{"help"}) =~ s/=\/D/=-D/gs; |
112 | print $_; |
113 | print |
114 | "\n". |
115 | "# If you rename this file to `Makefile', you should change this line,\n". |
116 | "# so that the .rsp files still depend on the correct makefile.\n". |
117 | "MAKEFILE = Makefile.bor\n". |
118 | "\n". |
119 | "# Stop windows.h including winsock2.h which would conflict with winsock 1\n". |
120 | "CFLAGS = -DWIN32_LEAN_AND_MEAN\n". |
121 | "\n". |
122 | "# Get include directory for resource compiler\n". |
123 | "!if !\$d(BCB)\n". |
124 | "BCB = \$(MAKEDIR)\\..\n". |
125 | "!endif\n". |
126 | "\n". |
127 | ".c.obj:\n". |
128 | "\tbcc32 \$(COMPAT) \$(FWHACK) \$(CFLAGS) /c \$*.c\n". |
129 | ".rc.res:\n". |
130 | "\tbrc32 \$(FWHACK) -i \$(BCB)\\include \\\n". |
131 | "\t\t-r -DWIN32 -D_WIN32 -DWINVER=0x0400 \$*.rc\n". |
132 | "\n". |
133 | "OBJ=obj\n". |
134 | "RES=res\n". |
135 | "\n"; |
136 | print $store{"objdefs"}; |
137 | print "\n"; |
138 | print "all:"; |
139 | print map { " $_.exe" } @projects; |
140 | print "\n\n"; |
141 | foreach $p (@projects) { |
142 | print $p, ".exe: ", &project($p), " $p.rsp\n"; |
143 | $tw = $gui{$p} ? " -tW" : ""; |
144 | print "\tbcc32$tw -e$p.exe \@$p.rsp\n"; |
145 | print "\tbrc32 -fe$p.exe " . (join " ", &project("resources.$p")) . "\n\n"; |
146 | } |
147 | foreach $p (@projects) { |
148 | print $p, ".rsp: \$(MAKEFILE)\n"; |
149 | $arrow = ">"; |
150 | foreach $i (&projlist("objects.$p")) { |
151 | print "\techo \$($i) $arrow $p.rsp\n"; |
152 | $arrow = ">>"; |
153 | } |
154 | print "\n"; |
155 | } |
156 | print $store{"dependencies"}; |
157 | print |
158 | "\n". |
159 | "version.o: FORCE\n". |
160 | "# Hack to force version.o to be rebuilt always\n". |
161 | "FORCE:\n". |
162 | "\tbcc32 \$(FWHACK) \$(VER) \$(CFLAGS) /c version.c\n\n". |
163 | "clean:\n". |
164 | "\tdel *.obj\n". |
165 | "\tdel *.exe\n". |
166 | "\tdel *.res\n". |
167 | "\tdel *.pch\n". |
168 | "\tdel *.aps\n". |
169 | "\tdel *.ilk\n". |
170 | "\tdel *.pdb\n". |
171 | "\tdel *.rsp\n"; |
172 | select STDOUT; close OUT; |