Command-line parser generator for C++
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

configure.pl 7.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  1. #! /usr/bin/perl
  2. ######################################################################
  3. # Copyright (C) 2002-2006 Peter J Jones (pjones@pmade.org)
  4. # All Rights Reserved
  5. #
  6. # Redistribution and use in source and binary forms, with or without
  7. # modification, are permitted provided that the following conditions
  8. # are met:
  9. #
  10. # 1. Redistributions of source code must retain the above copyright
  11. # notice, this list of conditions and the following disclaimer.
  12. # 2. Redistributions in binary form must reproduce the above copyright
  13. # notice, this list of conditions and the following disclaimer in
  14. # the documentation and/or other materials provided with the
  15. # distribution.
  16. # 3. Neither the name of the Author nor the names of its contributors
  17. # may be used to endorse or promote products derived from this software
  18. # without specific prior written permission.
  19. #
  20. # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS''
  21. # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
  22. # TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
  23. # PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR
  24. # OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  25. # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  26. # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
  27. # USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
  28. # AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  29. # OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
  30. # OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  31. # SUCH DAMAGE.
  32. ################################################################################
  33. #
  34. # configure.pl (bootstrap clo++)
  35. # Peter J Jones (pjones@pmade.org)
  36. #
  37. ################################################################################
  38. #
  39. # Includes
  40. #
  41. ################################################################################
  42. use strict;
  43. use Getopt::Long;
  44. use Cwd qw(cwd chdir);
  45. ################################################################################
  46. #
  47. # Constants
  48. #
  49. ################################################################################
  50. use constant DATE => 'Tue Jan 15 08:56:06 2002';
  51. use constant ID => '$Id: configure.pl,v 1.1.1.1 2003/08/04 04:28:10 pjones Exp $';
  52. ################################################################################
  53. #
  54. # Global Variables
  55. #
  56. ################################################################################
  57. my $cwd = cwd();
  58. my %clo;
  59. my $dirsep = "/";
  60. my $mkmf = "${cwd}${dirsep}tools${dirsep}mkmf";
  61. my $cxxflags = "${cwd}${dirsep}tools${dirsep}cxxflags";
  62. my $mkmf_flags = "--cxxflags '$cxxflags' --quiet ";
  63. my $libname = "cloxx";
  64. my $contrib_dir = "${cwd}${dirsep}src${dirsep}contrib";
  65. my $install_spec= "${cwd}${dirsep}docs${dirsep}install.spec";
  66. my $includes = "--include '${cwd}${dirsep}src${dirsep}include' ";
  67. my $libraries = "--slinkwith '${cwd}${dirsep}src${dirsep}library,$libname' ";
  68. my @extra_compile = (
  69. "${cwd}${dirsep}src${dirsep}library",
  70. "${cwd}${dirsep}src${dirsep}cmdline",
  71. );
  72. ################################################################################
  73. #
  74. # Code Start
  75. #
  76. ################################################################################
  77. $|++;
  78. if (not defined $ENV{'CXX'}) {
  79. print STDERR "**** your CXX environment variable is not set. clo++ needs this ****\n";
  80. print STDERR "**** variable to find your C++ compiler. Please set it to the ****\n";
  81. print STDERR "**** path to your compiler and re-run configure.pl. Thanks. ****\n";
  82. exit 1;
  83. }
  84. GetOptions(
  85. \%clo,
  86. 'help',
  87. 'developer',
  88. 'xml2-config=s',
  89. 'prefix=s',
  90. 'bindir=s',
  91. 'mandir=s',
  92. ) or usage();
  93. $clo{'help'} && usage();
  94. sub usage {
  95. print "Usage: $0 [options]\n", <<EOT;
  96. --developer Turn on developer mode
  97. --prefix path Set the install prefix to path [/usr/local]
  98. --bindir path Set the install bin dir to path [PREFIX/bin]
  99. --mandir path Set the install man dir to path [PREFIX/man]
  100. --xml2-config path Use the xml2-config script given by path.
  101. EOT
  102. exit;
  103. }
  104. $clo{'prefix'} ||= "/usr/local";
  105. $clo{'bindir'} ||= "$clo{'prefix'}/bin";
  106. $clo{'mandir'} ||= "$clo{'prefix'}/man";
  107. if ($clo{'developer'}) {
  108. $mkmf_flags .= "--developer ";
  109. }
  110. find_contrib_libs();
  111. print "Generating clo++ Makefiles ";
  112. generate_toplevel_makefile();
  113. generate_library_makefile();
  114. generate_cmdline_makefile();
  115. print "\n";
  116. print "+---------------------------------------------------------------+\n";
  117. print "| Join the announcement mailing list for release annoucements |\n";
  118. print "| http://pmade.org/mailman/listinfo/cloxx-announce |\n";
  119. print "| |\n";
  120. print "| Join the users mailing list for help with clo++ |\n";
  121. print "| http://pmade.org/mailman/listinfo/cloxx-users |\n";
  122. print "+---------------------------------------------------------------+\n";
  123. ################################################################################
  124. sub find_contrib_libs {
  125. my @files = glob("$contrib_dir${dirsep}*");
  126. my ($xmlwrapp, $libtpt);
  127. foreach my $file (@files) {
  128. if ($file =~ /xmlwrapp/) {
  129. $xmlwrapp = $file;
  130. } elsif ($file =~ /libtpt/) {
  131. $libtpt = $file;
  132. }
  133. }
  134. if (not defined $xmlwrapp) {
  135. print STDERR "$0: can't locate xmlwrapp, your package is incomplete\n";
  136. exit 1;
  137. }
  138. my $xmlextra = ''; if ($clo{'xml2-config'}) {$xmlextra = "--xml2-config '$clo{'xml2-config'}'";}
  139. system("cd $xmlwrapp ; $^X configure.pl --contrib --disable-xslt $xmlextra") and exit 1;
  140. my $xmlwrapp_config = "$xmlwrapp${dirsep}xmlwrapp-config";
  141. if (not -e $xmlwrapp_config) {
  142. print STDERR "$0: failed to configure xmlwrapp\n";
  143. exit 1;
  144. }
  145. my ($xmlwrapp_includes, $xmlwrapp_libraries);
  146. chomp($xmlwrapp_includes = `$xmlwrapp_config --cxxflags`);
  147. chomp($xmlwrapp_libraries = `$xmlwrapp_config --libs`);
  148. if (not defined $libtpt) {
  149. print STDERR "$0: can't locate libtpt, your package is incomplete\n";
  150. exit 1;
  151. }
  152. print "Configuring libtpt ...\n";
  153. system("cd $libtpt ; $^X configure.pl --bundle") and exit 1;
  154. $ENV{'CXXFLAGS'} .= " $xmlwrapp_includes";
  155. $ENV{'LDFLAGS'} .= " $xmlwrapp_libraries";
  156. unshift(@extra_compile, $xmlwrapp);
  157. $includes .= "--include '$libtpt${dirsep}inc' ";
  158. $libraries .= "--slinkwith '$libtpt${dirsep}src${dirsep}lib,tpt' ";
  159. unshift(@extra_compile, "$libtpt${dirsep}src${dirsep}lib");
  160. }
  161. ################################################################################
  162. sub generate_toplevel_makefile {
  163. unless (open(SPEC, ">$install_spec")) {
  164. print STDERR "\n$0: can't open $install_spec: $!\n";
  165. exit 1;
  166. }
  167. print SPEC "bindir=$clo{'bindir'}\n";
  168. print SPEC "mandir=$clo{'mandir'}\n";
  169. print SPEC "binary src${dirsep}cmdline${dirsep}clo++\n";
  170. print SPEC "man 1 src${dirsep}cmdline${dirsep}clo++.1\n";
  171. close SPEC;
  172. system("$^X $mkmf $mkmf_flags --with-test '$cwd${dirsep}tests' --install $install_spec --wrapper @extra_compile");
  173. print ".";
  174. }
  175. ################################################################################
  176. sub generate_library_makefile {
  177. if (not chdir("$cwd${dirsep}src${dirsep}library")) {
  178. print STDERR "\n$0: can't chdir to src${dirsep}library: $!\n";
  179. exit 1;
  180. }
  181. system("$^X $mkmf $mkmf_flags $includes --static-lib $libname *.cxx");
  182. print ".";
  183. chdir $cwd;
  184. }
  185. #################################################################################
  186. sub generate_cmdline_makefile {
  187. if (not chdir("$cwd${dirsep}src${dirsep}cmdline")) {
  188. print STDERR "\n$0: can't chdir to src${dirsep}cmdline: $!\n";
  189. exit 1;
  190. }
  191. system("$^X $mkmf $mkmf_flags $includes $libraries --one-exec clo++ *.cxx");
  192. print ".";
  193. chdir $cwd;
  194. }