Hurl is a C++ library for decoding and encoding URLs.
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 8.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261
  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 Hurl)
  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.2 2003/09/17 19:49:53 pjones Exp $';
  52. ################################################################################
  53. #
  54. # Global Variables
  55. #
  56. ################################################################################
  57. my $cwd = cwd();
  58. my %clo;
  59. my $mkmf = "${cwd}/tools/mkmf";
  60. my $cxxflags = "${cwd}/tools/cxxflags";
  61. my $genconfig = "${cwd}/tools/genconfig";
  62. my $master_inc = "${cwd}/include";
  63. my $mkmf_flags;
  64. my $libname = "hurl";
  65. my $install_spec= "docs/install.spec";
  66. my $hurl_ver;
  67. my $hurl_mjr;
  68. my @source_files = qw(
  69. url.cxx
  70. qs.cxx
  71. encode.cxx
  72. );
  73. ################################################################################
  74. #
  75. # Code Start
  76. #
  77. ################################################################################
  78. $|++;
  79. GetOptions(
  80. \%clo,
  81. 'help|h',
  82. 'developer',
  83. 'prefix=s',
  84. 'bindir=s',
  85. 'libdir=s',
  86. 'incdir=s',
  87. 'disable-shared',
  88. 'disable-examples',
  89. 'contrib',
  90. ) or usage();
  91. $clo{'help'} && usage();
  92. sub usage {
  93. print "Usage: $0 [options]\n", <<EOT;
  94. -h, --help This message
  95. --developer Turn on features for a hurl developer
  96. --contrib Configure for being bundled inside another project
  97. --disable-shared Don't build a shared library
  98. --disable-examples Don't build the example programs
  99. --prefix path Set install prefix to path [/usr/local]
  100. --bindir path Set bin install location to path [PREFIX/bin]
  101. --libdir path Set lib install location to path [PREFIX/lib]
  102. --incdir path Set include install location to path [PREFIX/include]
  103. EOT
  104. exit 1;
  105. }
  106. # set some defaults
  107. $ENV{'CXX'} ||= "g++";
  108. $clo{'prefix'} ||= "/usr/local";
  109. $clo{'bindir'} ||= "$clo{'prefix'}/bin";
  110. $clo{'libdir'} ||= "$clo{'prefix'}/lib";
  111. $clo{'incdir'} ||= "$clo{'prefix'}/include";
  112. $clo{'disable-shared'} = 1 if $clo{'contrib'};
  113. if ($clo{'contrib'}) {
  114. $clo{'disable-shared'} = 1;
  115. $clo{'disable-examples'} = 1;
  116. }
  117. # setup defaults for mkmf
  118. $mkmf_flags = "--include $master_inc --cxxflags $cxxflags --quiet ";
  119. if ($clo{'developer'}) {$mkmf_flags .= " --developer";}
  120. # find out the current version
  121. parse_version_file();
  122. # generate the config script
  123. generate_config_script();
  124. # start generating makefiles
  125. print "Creating $libname Makefiles ";
  126. generate_top_makefile();
  127. #generate_test_makefiles();
  128. #generate_example_makefiles();
  129. generate_src_makefiles();
  130. print "\n";
  131. if (!$clo{'contrib'}) {
  132. print "+-----------------------------------------------------------+\n";
  133. print "| Everything looks good. Happy compiling. |\n";
  134. print "| While you wait, why not drop a note to software\@pmade.org |\n";
  135. print "+-----------------------------------------------------------+\n";
  136. }
  137. ################################################################################
  138. sub parse_version_file {
  139. unless (open(VERSION, "docs/VERSION")) {
  140. print STDERR "$0: can't open VERSION file 'docs/VERSION': $!\n";
  141. exit 1;
  142. }
  143. my $first_line = <VERSION>;
  144. close VERSION;
  145. ($hurl_ver, $hurl_mjr, undef) = split(/\s+/, $first_line, 3);
  146. }
  147. ################################################################################
  148. sub generate_top_makefile {
  149. my $extra_dirs = '';
  150. #$extra_dirs .= " examples" if not $clo{'disable-examples'};
  151. unless (open(SPEC, ">$install_spec")) {
  152. print STDERR "\n$0: can't open $install_spec: $!\n";
  153. exit 1;
  154. }
  155. # set some install paths
  156. print SPEC "bindir=$clo{'bindir'}\n";
  157. print SPEC "libdir=$clo{'libdir'}\n";
  158. print SPEC "includedir=$clo{'incdir'}\n";
  159. # add files
  160. print SPEC "binary $libname-config\n";
  161. print SPEC "include-dir include/$libname $libname\n";
  162. print SPEC "static-lib src $libname\n";
  163. print SPEC "shared-lib src $libname $hurl_mjr\n" unless $clo{'disable-shared'};
  164. close SPEC;
  165. system("$^X $mkmf $mkmf_flags --install $install_spec --wrapper src $extra_dirs");
  166. unlink($install_spec);
  167. print ".";
  168. }
  169. ################################################################################
  170. sub generate_src_makefiles {
  171. my $extra_flags = '';
  172. ##
  173. # src/Makefile
  174. if (! chdir("$cwd/src")) {
  175. print STDERR "\n**** hey, I can't cd into my src directory: $!\n";
  176. exit 1;
  177. }
  178. $extra_flags .= "--shared-lib $libname --major $hurl_mjr " unless $clo{'disable-shared'};
  179. $extra_flags .= "--append url_delims.mk --clean-target gen_url_clean ";
  180. $extra_flags .= "--fake-header url_delims.h ";
  181. $extra_flags .= join(' ', @source_files) . ' ';
  182. system("$^X $mkmf $mkmf_flags --static-lib $libname $extra_flags");
  183. print ".";
  184. chdir($cwd);
  185. }
  186. ################################################################################
  187. sub generate_example_makefiles {
  188. return if $clo{'disable-examples'};
  189. unless (chdir("examples")) {
  190. print "\n"; print STDERR "$0: can't chdir to examples: $!\n";
  191. exit 1;
  192. }
  193. my $extra_flags = "--slinkwith '$cwd/src,$libname' ";
  194. system("$^X $mkmf $mkmf_flags $extra_flags --many-exec *.cxx");
  195. chdir($cwd);
  196. print ".";
  197. }
  198. ################################################################################
  199. sub generate_config_script {
  200. my ($all_incs, $all_libs);
  201. if ($clo{'contrib'}) {
  202. $all_incs = "-I$cwd/include ";
  203. $all_libs = "";
  204. my $full_libname = `$^X $cxxflags --static-lib-prefix`;
  205. $full_libname =~ s/^\s+//; $full_libname =~ s/\s+$//;
  206. $full_libname .= $libname;
  207. $full_libname .= `$^X $cxxflags --static-lib-extension`;
  208. $full_libname =~ s/^\s+//; $full_libname =~ s/\s+$//;
  209. $all_libs .= "$cwd/src/$full_libname ";
  210. } else {
  211. $all_incs = "-I$clo{'incdir'} ";
  212. $all_libs .= `$^X $cxxflags --linkwith $clo{'libdir'},$libname`;
  213. }
  214. # clean and encode
  215. foreach ($all_incs, $all_libs) {
  216. s/^\s+//; s/\s+$//; s/\s+/ /g; s/-/^/g;
  217. }
  218. my $command = "$^X $genconfig --version $hurl_ver --name $libname";
  219. $command .= " --libs \"$all_libs\" --cxxflags \"$all_incs\"";
  220. $command .= " -o $libname-config";
  221. print "Creating hurl-config script ... \n";
  222. system("$command");
  223. }
  224. ################################################################################