mkfiles.pl 4.7 KB

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