Add multi-makefile management system
[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".
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";
79print $store{"objdefs"};
80print
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";
90foreach $p (@projects) {
91 print $p, ".exe: ", &project($p), "\n";
92 print "\t\$(CC) \$(LDFLAGS) -o \$@ " . &project($p), " \$(LIBS)\n\n";
93}
94print $store{"dependencies"};
95print
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";
104select STDOUT; close OUT;
105
106##-- Borland makefile
107open OUT, ">Makefile.bor"; select OUT;
108print
109"# Makefile for PuTTY under Borland C.\n";
110# bcc32 command line option is -D not /D
111($_ = $store{"help"}) =~ s/=\/D/=-D/gs;
112print $_;
113print
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";
136print $store{"objdefs"};
137print "\n";
138print "all:";
139print map { " $_.exe" } @projects;
140print "\n\n";
141foreach $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}
147foreach $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}
156print $store{"dependencies"};
157print
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";
172select STDOUT; close OUT;