forked from ahmadia/homebrew-science
-
Notifications
You must be signed in to change notification settings - Fork 0
/
asl.rb
72 lines (60 loc) · 2.14 KB
/
asl.rb
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
require 'formula'
class Asl < Formula
url 'http://www.ampl.com/netlib/ampl/solvers.tgz'
sha1 "7aab62aa64c5fc824d9032e94ea88129d9e65f5d"
version "20141106"
homepage 'http://www.ampl.com/hooking.html'
option 'with-matlab', 'Build MEX file for use with Matlab'
option 'with-mex-path=', 'Path to MEX executable, e.g., /Applications/Matlab/MATLAB_R2013b.app/bin/mex (default: mex)'
resource 'spamfunc' do
url 'http://netlib.org/ampl/solvers/examples/spamfunc.c'
sha1 '429a79fc54facc5ef99219fe460280a883c75dfa'
end
def install
ENV.universal_binary if OS.mac?
cflags = %w[-I. -O -fPIC]
if OS.mac?
cflags += ["-arch", "#{Hardware::CPU.arch_32_bit}"]
soname = "dylib"
libtool_cmd = ["libtool", "-dynamic", "-undefined", "dynamic_lookup",
"-install_name", "#{lib}/libasl.#{soname}"]
else
soname = "so"
libtool_cmd = ["ld", "-shared"]
end
# Dynamic libraries are more user friendly.
(buildpath / 'makefile.brew').write <<-EOS.undent
include makefile.u
libasl.#{soname}: ${a:.c=.o}
\t#{libtool_cmd.join(" ")} -o $@ $?
libfuncadd0.#{soname}: funcadd0.o
\t#{libtool_cmd.join(" ")} -o $@ $?
EOS
ENV.deparallelize
targets = ["arith.h", "stdio1.h"]
libs = ["libasl.#{soname}", "libfuncadd0.#{soname}"]
system "make", "-f", "makefile.brew", "CC=#{ENV.cc}",
"CFLAGS=#{cflags.join(' ')}", *(targets + libs)
lib.install *libs
(include / 'asl').install Dir["*.h"]
(include / 'asl').install Dir["*.hd"]
doc.install 'README'
if build.with? "matlab"
mex = ARGV.value("with-mex-path") || "mex"
resource("spamfunc").stage do
system mex, "-f", File.join(File.dirname(mex), "mexopts.sh"),
"-I#{include}/asl", "spamfunc.c", "-largeArrayDims",
"-L#{lib}", "-lasl", "-lfuncadd0", "-outdir", bin
end
end
end
def caveats
s = <<-EOS.undent
Include files are in #{include}/asl.
To link with the ASL, you may simply use
-L#{lib} -lasl -lfuncadd0
EOS
s += "\nAdd #{bin} to your MATLABPATH." if build.with? "matlab"
s
end
end