1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324
|
From: Masahiro TANAKA <masa16.tanaka@gmail.com>
Date: Tue, 5 Mar 2013 18:46:58 +0900
Subject: extconf.rb: * need to check extra-libs before auto-build. * need to
define $found_lib. * define methods to make program structure clear. * merge
extconf-auto.rb.
---
ext/extconf.rb | 280 +++++++++++++++++++++++++++++++++++----------------------
1 file changed, 171 insertions(+), 109 deletions(-)
diff --git a/ext/extconf.rb b/ext/extconf.rb
index 48d1c1b..02a1672 100644
--- a/ext/extconf.rb
+++ b/ext/extconf.rb
@@ -1,30 +1,67 @@
-# extconf.rb : Configure script for Ruby/PGPLOT
-#
-# Copyright (c) 2000,2001 Masahiro TANAKA <masa@ir.isas.ac.jp>
-#
-# This program is free software.
-# You can distribute/modify this program
-# under the same terms as Ruby itself.
-# NO WARRANTY.
-#
-# usage: ruby extconf.rb [configure options]
-
-# Narray is now Gem based, so require rubygems
-# so that we can use Gem class to find narray.
require "mkmf"
-#$DEBUG = true
+def main
+ extconf_start
+ check_narray
-# configure options:
-# --with-pgplot-dir=path
-# --with-pgplot-include=path
-# --with-pgplot-lib=path
-dir_config("pgplot")
+ $objs = %w(rb_pgplot.o kwarg.o)
+ $enable_autobuild = enable_config('autobuild', false)
+ $found_lib = []
+
+ # Check PGPLOT Header
+ if have_header("cpgplot.h")
+ if have_library("cpgplot","cpgbeg")
+ create_makefile("pgplot")
+ exit
+ end
+
+ # Check for extra libs then re-check for PGPLOT library
+ puts "First check for PGPLOT library failed."
+ check_extra_libs
+ $libs = append_library($libs, "pgplot")
+
+ if have_library("cpgplot","cpgbeg")
+ create_makefile("pgplot")
+ exit
+ end
+ elsif $enable_autobuild
+ check_extra_libs
+ end
+
+ if $enable_autobuild
+ autobuild_pgplot
+ else
+ puts "
+The PGPLOT library was not found. To auto-build PGPLOT library
+as part of installing Ruby/PGPLOT, pass the --enable-autobuild option.
+
+Examples:
+ Gem install: gem install pgplot -- --enable-autobuild
+ Manual install: ruby extconf.rb --enable-autobuild
+"
+ end
+end
+
+
+def extconf_start
+ # configure options:
+ # --with-pgplot-dir=path
+ # --with-pgplot-include=path
+ # --with-pgplot-lib=path
+ dir_config("pgplot")
+
+ # configure options:
+ # --with-x11-dir=path
+ # --with-x11-include=path
+ # --with-x11-lib=path
+ dir_config("x11")
+
+ # Otherwise you can also specify:
+ # --with-opt-dir=path
+ # --with-opt-include=path
+ # --with-opt-lib=path
+end
-# Otherwise you can also specify:
-# --with-opt-dir=path
-# --with-opt-include=path
-# --with-opt-lib=path
def find_dir_w_file(d,h)
g = Dir.glob(RbConfig.expand(d+"/"+h))
@@ -42,107 +79,132 @@ def find_dir_in_gemspec
nil
end
-# Check NArray
-gems_dir="$(rubylibprefix)/gems/$(ruby_version)/gems/"
-narray_d="narray-0.[56].*"
-narray_h="narray.h"
-if narray_h_dir =
- find_dir_in_gemspec ||
- find_dir_w_file("../"+narray_d,narray_h) ||
- find_dir_w_file(gems_dir+narray_d,narray_h) ||
- find_dir_w_file(CONFIG['vendorarchdir'],narray_h) ||
- find_dir_w_file(CONFIG['sitearchdir'],narray_h) ||
- find_dir_w_file(CONFIG['archdir'],narray_h)
- $CPPFLAGS = " -I#{narray_h_dir} " + $CPPFLAGS
-end
-exit unless have_header("narray.h")
-if RUBY_PLATFORM =~ /cygwin|mingw/
- $LDFLAGS = " -L#{CONFIG['sitearchdir']} "+$LDFLAGS
- exit unless have_library("narray","na_make_object")
-end
+def check_narray
+ gems_dir="$(rubylibprefix)/gems/$(ruby_version)/gems/"
+ narray_d="narray-0.[56].*"
+ narray_h="narray.h"
+ if narray_h_dir =
+ find_dir_in_gemspec ||
+ find_dir_w_file("../"+narray_d,narray_h) ||
+ find_dir_w_file(gems_dir+narray_d,narray_h) ||
+ find_dir_w_file(CONFIG['vendorarchdir'],narray_h) ||
+ find_dir_w_file(CONFIG['sitearchdir'],narray_h) ||
+ find_dir_w_file(CONFIG['archdir'],narray_h)
+ $CPPFLAGS = " -I#{narray_h_dir} " + $CPPFLAGS
+ end
+ exit unless have_header("narray.h")
-$have_pgplot = false
+ if RUBY_PLATFORM =~ /cygwin|mingw/
+ $LDFLAGS = " -L#{CONFIG['sitearchdir']} "+$LDFLAGS
+ exit unless have_library("narray","na_make_object")
+ end
+end
-# Check PGPLOT Header
-if have_header("cpgplot.h")
- # Check PGPLOT Library without extra libs
- if find_library("cpgplot","cpgbeg", "/usr/lib",
- "/usr/local/lib", "/usr/local/pgplot" )
- $have_pgplot = true
+def check_extra_libs
+ # Check FORTRAN Libraries
+ #
+ # SUN WorkShop FORTRAN 77 compiler ver5.0
+ # configure options: --with-sunws
+ if with_config("sunws")
+ $libs = "-lM77 -lsunmath "+$libs
+ exit unless find_library("F77", "f77_init", "/opt/SUNWspro/lib")
+ $defs.push "-DSPARC_FORTRAN"
+ #
+ # GNU FORTRAN v4
+ elsif have_library("gfortran")
+ $CFLAGS = "-Wall "+$CFLAGS
+ $defs.push "-DGNU_FORTRAN"
+ #
+ # GNU FORTRAN v3
+ elsif have_library("g77")
+ $CFLAGS = "-Wall "+$CFLAGS
+ $defs.push "-DGNU_FORTRAN"
else
- # Check for extra libs then re-check for PGPLOT library
- puts "First check for PGPLOT library failed,"
- puts "checking for auxiliary libraries and retrying."
-
- # Check FORTRAN Libraries
- #
- # SUN WorkShop FORTRAN 77 compiler ver5.0
- # configure options: --with-sunws
- if with_config("sunws")
- $libs = "-lM77 -lsunmath "+$libs
- exit unless find_library("F77", "f77_init", "/opt/SUNWspro/lib")
- $defs.push "-DSPARC_FORTRAN"
- #
- # GNU FORTRAN v4
- elsif have_library("gfortran")
- $CFLAGS = "-Wall "+$CFLAGS
- $defs.push "-DGNU_FORTRAN"
- #
- # GNU FORTRAN v3
- elsif have_library("g77")
- $CFLAGS = "-Wall "+$CFLAGS
- $defs.push "-DGNU_FORTRAN"
- else
- puts "failed"
- exit
- end
+ puts "failed"
+ exit
+ end
- # Check GrWin Library (for cygwin (and mingw32?))
- # configure options: --with-grwin
- if with_config("grwin")
- #$LDFLAGS = "-Wl,--subsystem,console "+$LDFLAGS
- if RUBY_PLATFORM =~ /cygwin|mingw/
- $libs += " -mwindows"
- end
- exit unless have_library("GrWin", "GWinit")
+ # Check GrWin Library (for cygwin (and mingw32?))
+ # configure options: --with-grwin
+ if with_config("grwin")
+ #$LDFLAGS = "-Wl,--subsystem,console "+$LDFLAGS
+ if RUBY_PLATFORM =~ /cygwin|mingw/
+ $libs += " -mwindows"
end
+ exit unless have_library("GrWin", "GWinit")
+ end
+
+ # Check X11 Library
+ if have_library("X11", "XOpenDisplay")
+ $found_lib << 'X11'
+ end
- $found_lib = []
+ # Check PNG Library
+ libs_save = $libs
+ $libs = append_library($libs, "z")
+ if have_library("png","png_create_write_struct")
+ $found_lib << 'png'
+ else
+ $libs = libs_save
+ end
+end
- # configure options:
- # --with-x11-dir=path
- # --with-x11-include=path
- # --with-x11-lib=path
- dir_config("x11")
- # Check X11 Library
- if have_library("X11", "XOpenDisplay")
- $found_lib << 'X11'
- end
+def autobuild_pgplot
+ # Exit unless a fortran compiler was found
+ exit unless %w[gfortran g77].any?{|cmd| system("which #{cmd}")}
+ puts "enabling auto-build PGPLOT Library..."
- # Check PNG Library
- libs_save = $libs
- $libs = append_library($libs, "z")
- if have_library("png","png_create_write_struct")
- $found_lib << 'png'
- else
- $libs = libs_save
- end
+ $subdir = 'build_lib'
+ $CFLAGS = "-I#{$subdir}/build "+$CFLAGS
+ $LDFLAGS = "-L#{$subdir}/build "+$LDFLAGS
+ $libs = append_library($libs, "cpgplot")
+ $defs.push '-DPGPLOT_DIR=\\"$(PGPLOT_DIR)\\"'
- $libs = append_library($libs, "pgplot")
+ # Generate Makefile
+ create_makefile("pgplot")
- if find_library("cpgplot","cpgbeg", "/usr/lib",
- "/usr/local/lib", "/usr/local/pgplot" )
- $have_pgplot = true
+ # Append PGPLOT install task to Makefile
+ exit unless $makefile_created
+ puts "appending extra install tasks to Makefile"
+ File.open("Makefile","a") do |w|
+ w.print "
+PGPLOT_DIR = $(RUBYARCHDIR)/pgplot
+PGPLOT_BUILD = #{$subdir}/build
+
+$(PGPLOT_BUILD)/libcpgplot.a:
+ (cd #{$subdir}; make build/libcpgplot.a)
+$(PGPLOT_BUILD)/cpgplot.h: $(PGPLOT_BUILD)/libcpgplot.a
+rb_pgplot.o: $(PGPLOT_BUILD)/cpgplot.h
+$(DLLIB): $(PGPLOT_BUILD)/libcpgplot.a
+
+install: install-pgplot
+install-pgplot:
+ $(MAKEDIRS) $(PGPLOT_DIR)
+ $(INSTALL_DATA) $(PGPLOT_BUILD)/grfont.dat $(PGPLOT_DIR)
+ $(INSTALL_DATA) $(PGPLOT_BUILD)/rgb.txt $(PGPLOT_DIR)
+"
+ if $found_lib.include? "X11"
+ w.print \
+" $(INSTALL_PROG) $(PGPLOT_BUILD)/pgxwin_server $(PGPLOT_DIR)
+
+$(PGPLOT_BUILD)/pgxwin_server: $(PGPLOT_BUILD)/cpgplot.h
+ (cd #{$subdir}; make build/pgxwin_server)
+$(DLLIB): $(PGPLOT_BUILD)/pgxwin_server
+"
end
end
-end
-$objs = %w(rb_pgplot.o kwarg.o)
+ puts "creating #{$subdir}/drivers.conf"
+ File.open("#{$subdir}/drivers.conf","w") do |w|
+ w.puts "GIDRIV PPDRIV PSDRIV"
+ w.puts "PNDRIV" if $found_lib.include? "png"
+ w.puts "WDDRIV XWDRIV" if $found_lib.include? "X11"
+ end
-if $have_pgplot
- # Generate Makefile
- create_makefile("pgplot")
+ puts "Ready to download and auto-build PGPLOT !!"
end
+
+main
|