2014-03-22 08:23:08 +00:00
|
|
|
require "formula"
|
2013-03-18 16:25:35 +01:00
|
|
|
|
|
|
|
# This is a non-functional example formula to showcase all features and
|
2014-07-11 20:36:56 -07:00
|
|
|
# therefore, it's overly complex and dupes stuff just to comment on it.
|
2013-03-18 16:25:35 +01:00
|
|
|
# You may want to use `brew create` to start your own new formula!
|
2014-10-26 14:54:36 +00:00
|
|
|
# Documentation: https://github.com/Homebrew/homebrew/blob/master/share/doc/homebrew/Formula-Cookbook.md
|
2013-03-18 16:25:35 +01:00
|
|
|
|
|
|
|
## Naming -- Every Homebrew formula is a class of the type `Formula`.
|
|
|
|
# Ruby classes have to start Upper case and dashes are not allowed.
|
|
|
|
# So we transform: `example-formula.rb` into `ExampleFormula`. Further,
|
|
|
|
# Homebrew does enforce that the name of the file and the class correspond.
|
2014-03-03 18:15:21 -06:00
|
|
|
# Check with `brew search` that the name is free.
|
2013-03-18 16:25:35 +01:00
|
|
|
class ExampleFormula < Formula
|
2014-11-18 03:53:32 +00:00
|
|
|
homepage "https://www.example.com" # used by `brew home example-formula`.
|
|
|
|
revision 1 # This is used when there's no new version but it needs recompiling for another reason.
|
|
|
|
# 0 is default & unwritten.
|
2013-03-18 16:25:35 +01:00
|
|
|
|
|
|
|
# The url of the archive. Prefer https (security and proxy issues):
|
2014-03-22 08:23:08 +00:00
|
|
|
url "https://packed.sources.and.we.prefer.https.example.com/archive-1.2.3.tar.bz2"
|
|
|
|
mirror "https://in.case.the.host.is.down.example.com" # `mirror` is optional.
|
2014-11-18 03:53:32 +00:00
|
|
|
mirror "https://in.case.the.mirror.is.down.example.com" # Mirrors are limitless, but don't go too wild.
|
2013-03-18 16:25:35 +01:00
|
|
|
|
|
|
|
# Optionally specify the download strategy `:using => ...`
|
|
|
|
# `:git`, `:hg`, `:svn`, `:bzr`, `:cvs`,
|
|
|
|
# `:curl` (normal file download. Will also extract.)
|
|
|
|
# `:nounzip` (without extracting)
|
|
|
|
# `:post` (download via an HTTP POST)
|
2013-09-24 01:34:28 -07:00
|
|
|
# `S3DownloadStrategy` (download from S3 using signed request)
|
2014-03-22 08:23:08 +00:00
|
|
|
url "https://some.dont.provide.archives.example.com", :using => :git, :tag => "1.2.3"
|
2013-03-18 16:25:35 +01:00
|
|
|
|
2014-07-11 20:36:56 -07:00
|
|
|
# version is seldom needed, because it's usually autodetected from the URL/tag.
|
2014-03-22 08:23:08 +00:00
|
|
|
version "1.2-final"
|
2013-03-18 16:25:35 +01:00
|
|
|
|
|
|
|
# For integrity and security, we verify the hash (`openssl dgst -sha1 <FILE>`)
|
|
|
|
# You may also use sha256 if the software uses sha256 on their homepage.
|
|
|
|
# Leave it empty at first and `brew install` will tell you the expected.
|
2014-03-22 08:23:08 +00:00
|
|
|
sha1 "cafebabe78901234567890123456789012345678"
|
2013-03-18 16:25:35 +01:00
|
|
|
|
2014-02-24 22:44:30 -05:00
|
|
|
# Stable-only dependencies should be nested inside a `stable` block rather than
|
|
|
|
# using a conditional. It is preferrable to also pull the URL and checksum into
|
|
|
|
# the block if one is necessary.
|
|
|
|
stable do
|
|
|
|
url "https://example.com/foo-1.0.tar.gz"
|
|
|
|
sha1 "cafebabe78901234567890123456789012345678"
|
|
|
|
|
|
|
|
depends_on "libxml2"
|
|
|
|
depends_on "libffi"
|
|
|
|
end
|
|
|
|
|
2013-03-18 16:25:35 +01:00
|
|
|
# Optionally, specify a repository to be used. Brew then generates a
|
|
|
|
# `--HEAD` option. Remember to also test it.
|
|
|
|
# The download strategies (:using =>) are the same as for `url`.
|
2014-03-22 08:23:08 +00:00
|
|
|
head "https://we.prefer.https.over.git.example.com/.git"
|
|
|
|
head "https://example.com/.git", :branch => "name_of_branch", :revision => "abc123"
|
|
|
|
head "https://hg.is.awesome.but.git.has.won.example.com/", :using => :hg # If autodetect fails.
|
2013-03-18 16:25:35 +01:00
|
|
|
|
2014-02-24 22:41:21 -05:00
|
|
|
head do
|
|
|
|
url "https://example.com/repo.git"
|
|
|
|
|
2014-05-08 20:20:27 -05:00
|
|
|
depends_on "autoconf" => :build
|
|
|
|
depends_on "automake" => :build
|
|
|
|
depends_on "libtool" => :build
|
2014-02-24 22:41:21 -05:00
|
|
|
end
|
|
|
|
|
2013-03-18 16:25:35 +01:00
|
|
|
# The optional devel block is only executed if the user passes `--devel`.
|
|
|
|
# Use this to specify a not-yet-released version of a software.
|
|
|
|
devel do
|
2014-02-24 22:41:21 -05:00
|
|
|
url "https://example.com/archive-2.0-beta.tar.gz"
|
|
|
|
sha1 "1234567890123456789012345678901234567890"
|
|
|
|
|
|
|
|
depends_on "cairo"
|
|
|
|
depends_on "pixman"
|
2013-03-18 16:25:35 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
## Options
|
|
|
|
|
2014-03-22 08:23:08 +00:00
|
|
|
# Options can be used as arguments to `brew install`.
|
|
|
|
# To switch features on/off: `"with-something"` or `"with-otherthing"`.
|
|
|
|
# To use another software: `"with-other-software"` or `"without-foo"`
|
2013-03-18 16:25:35 +01:00
|
|
|
# Note, that for dependencies that are `:optional` or `:recommended`, options
|
|
|
|
# are generated automatically.
|
|
|
|
# Build a universal (On newer intel Macs this means a combined 32bit and
|
2014-03-22 08:23:08 +00:00
|
|
|
# 64bit binary/library). TODO: better explain what this means for PPC.
|
2013-03-18 16:25:35 +01:00
|
|
|
option :universal
|
2014-03-22 08:23:08 +00:00
|
|
|
option "with-spam", "The description goes here without a dot at the end"
|
|
|
|
option "with-qt", "Text here overwrites the autogenerated one from `depends_on "qt"`"
|
2013-03-18 16:25:35 +01:00
|
|
|
|
|
|
|
## Bottles
|
|
|
|
|
|
|
|
# Bottles are pre-built and added by the Homebrew maintainers for you.
|
|
|
|
# If you maintain your own repository, you can add your own bottle links.
|
2014-10-26 14:54:36 +00:00
|
|
|
# https://github.com/Homebrew/homebrew/blob/master/share/doc/homebrew/Bottles.md
|
2013-03-18 16:25:35 +01:00
|
|
|
bottle do
|
2014-03-22 08:23:08 +00:00
|
|
|
root_url "http://mikemcquaid.com" # Optional root to calculate bottle URLs
|
|
|
|
prefix "/opt/homebrew" # Optional HOMEBREW_PREFIX in which the bottles were built.
|
|
|
|
cellar "/opt/homebrew/Cellar" # Optional HOMEBREW_CELLAR in which the bottles were built.
|
2013-03-18 16:25:35 +01:00
|
|
|
revision 1 # Making the old bottle outdated without bumping the version of the formula.
|
2014-11-18 03:53:32 +00:00
|
|
|
sha1 "d3d13fe6f42416765207503a946db01378131d7b" => :yosemite
|
|
|
|
sha1 "cdc48e79de2dee796bb4ba1ad987f6b35ce1c1ee" => :mavericks
|
|
|
|
sha1 "a19b544c8c645d7daad1d39a070a0eb86dfe9b9c" => :mountain_lion
|
2013-03-18 16:25:35 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def pour_bottle?
|
|
|
|
# Only needed if this formula has to check if using the pre-built
|
2013-12-12 21:04:07 +00:00
|
|
|
# bottle is fine.
|
2013-03-18 16:25:35 +01:00
|
|
|
true
|
|
|
|
end
|
|
|
|
|
|
|
|
## keg_only
|
|
|
|
|
|
|
|
# Software that will not be sym-linked into the `brew --prefix` will only
|
|
|
|
# live in it's Cellar. Other formulae can depend on it and then brew will
|
|
|
|
# add the necessary includes and libs (etc.) during the brewing of that
|
|
|
|
# other formula. But generally, keg_only formulae are not in your PATH
|
|
|
|
# and not seen by compilers if you build your own software outside of
|
|
|
|
# Homebrew. This way, we don't shadow software provided by OS X.
|
|
|
|
keg_only :provided_by_osx
|
|
|
|
keg_only "because I want it so"
|
|
|
|
|
|
|
|
|
|
|
|
## Dependencies
|
|
|
|
|
|
|
|
# The dependencies for this formula. Use strings for the names of other
|
|
|
|
# formulae. Homebrew provides some :special dependencies for stuff that
|
|
|
|
# requires certain extra handling (often changing some ENV vars or
|
|
|
|
# deciding if to use the system provided version or not.)
|
|
|
|
|
|
|
|
# `:build` means this dep is only needed during build.
|
2014-03-22 08:23:08 +00:00
|
|
|
depends_on "cmake" => :build
|
|
|
|
# Explictly name formulae in other taps. Non-optional tap dependencies won't
|
|
|
|
# be accepted in core.
|
|
|
|
depends_on "homebrew/dupes/tcl-tk"
|
2013-03-18 16:25:35 +01:00
|
|
|
# `:recommended` dependencies are built by default. But a `--without-...`
|
|
|
|
# option is generated to opt-out.
|
2014-03-22 08:23:08 +00:00
|
|
|
depends_on "readline" => :recommended
|
2013-03-18 16:25:35 +01:00
|
|
|
# `:optional` dependencies are NOT built by default but a `--with-...`
|
|
|
|
# options is generated.
|
2014-03-22 08:23:08 +00:00
|
|
|
depends_on "glib" => :optional
|
2013-03-18 16:25:35 +01:00
|
|
|
# If you need to specify that another formula has to be built with/out
|
|
|
|
# certain options (note, no `--` needed before the option):
|
2014-03-22 08:23:08 +00:00
|
|
|
depends_on "zeromq" => "with-pgm"
|
|
|
|
depends_on "qt" => ["with-qtdbus", "developer"] # Multiple options.
|
2013-03-18 16:25:35 +01:00
|
|
|
# Optional and enforce that boost is built with `--with-c++11`.
|
2014-03-22 08:23:08 +00:00
|
|
|
depends_on "boost" => [:optional, "with-c++11"]
|
2013-03-18 16:25:35 +01:00
|
|
|
# If a dependency is only needed in certain cases:
|
2014-03-22 08:23:08 +00:00
|
|
|
depends_on "sqlite" if MacOS.version == :leopard
|
2013-03-18 16:25:35 +01:00
|
|
|
depends_on :xcode # If the formula really needs full Xcode.
|
|
|
|
depends_on :tex # Homebrew does not provide a Tex Distribution.
|
|
|
|
depends_on :fortran # Checks that `gfortran` is available or `FC` is set.
|
|
|
|
depends_on :mpi => :cc # Needs MPI with `cc`
|
|
|
|
depends_on :mpi => [:cc, :cxx, :optional] # Is optional. MPI with `cc` and `cxx`.
|
|
|
|
depends_on :macos => :lion # Needs at least Mac OS X "Lion" aka. 10.7.
|
|
|
|
depends_on :arch => :intel # If this formula only builds on intel architecture.
|
|
|
|
depends_on :arch => :x86_64 # If this formula only build on intel x86 64bit.
|
|
|
|
depends_on :arch => :ppc # Only builds on PowerPC?
|
|
|
|
depends_on :ld64 # Sometimes ld fails on `MacOS.version < :leopard`. Then use this.
|
|
|
|
depends_on :x11 # X11/XQuartz components.
|
2014-11-18 03:53:32 +00:00
|
|
|
depends_on :osxfuse # Permits the use of the upstream signed binary or our source package.
|
|
|
|
depends_on :tuntap # Does the same thing as above. This is vital for Yosemite and above.
|
2013-03-18 16:25:35 +01:00
|
|
|
depends_on :mysql => :recommended
|
|
|
|
# It is possible to only depend on something if
|
2014-03-22 08:23:08 +00:00
|
|
|
# `build.with?` or `build.without? "another_formula"`:
|
2013-03-18 16:25:35 +01:00
|
|
|
depends_on :mysql # allows brewed or external mysql to be used
|
2014-03-22 08:23:08 +00:00
|
|
|
depends_on :postgresql if build.without? "sqlite"
|
2013-03-18 16:25:35 +01:00
|
|
|
depends_on :hg # Mercurial (external or brewed) is needed
|
|
|
|
|
2014-03-22 08:23:08 +00:00
|
|
|
# If any Python >= 2.7 < 3.x is okay (either from OS X or brewed):
|
2013-03-18 16:25:35 +01:00
|
|
|
depends_on :python
|
|
|
|
# Python 3.x if the `--with-python3` is given to `brew install example`
|
|
|
|
depends_on :python3 => :optional
|
|
|
|
|
|
|
|
# Modules/Packages from other languages, such as :chicken, :jruby, :lua,
|
2013-12-12 21:04:07 +00:00
|
|
|
# :node, :ocaml, :perl, :python, :rbx, :ruby, can be specified by
|
2014-03-22 08:23:08 +00:00
|
|
|
depends_on "some_module" => :lua
|
2013-03-18 16:25:35 +01:00
|
|
|
|
|
|
|
## Conflicts
|
|
|
|
|
|
|
|
# If this formula conflicts with another one:
|
2014-03-22 08:23:08 +00:00
|
|
|
conflicts_with "imagemagick", :because => "because this is just a stupid example"
|
2013-03-18 16:25:35 +01:00
|
|
|
|
|
|
|
|
|
|
|
## Failing with a certain compiler?
|
|
|
|
|
|
|
|
# If it is failing for certain compiler:
|
|
|
|
fails_with :llvm do # :llvm is really llvm-gcc
|
|
|
|
build 2334
|
|
|
|
cause "Segmentation fault during linking."
|
|
|
|
end
|
|
|
|
|
|
|
|
fails_with :clang do
|
|
|
|
build 425
|
2014-03-22 08:23:08 +00:00
|
|
|
cause "multiple configure and compile errors"
|
2013-03-18 16:25:35 +01:00
|
|
|
end
|
|
|
|
|
2014-03-03 18:14:02 -06:00
|
|
|
## Resources
|
|
|
|
|
|
|
|
# Additional downloads can be defined as resources and accessed in the
|
|
|
|
# install method. Resources can also be defined inside a stable, devel, or
|
|
|
|
# head block. This mechanism replaces ad-hoc "subformula" classes.
|
|
|
|
resource "additional_files" do
|
2014-03-22 08:23:08 +00:00
|
|
|
url "https://example.com/additional-stuff.tar.gz"
|
|
|
|
sha1 "deadbeef7890123456789012345678901234567890"
|
2014-03-03 18:14:02 -06:00
|
|
|
end
|
|
|
|
|
2013-03-18 16:25:35 +01:00
|
|
|
|
|
|
|
## Patches
|
|
|
|
|
2014-03-13 19:51:23 -05:00
|
|
|
# External patches can be declared using resource-style blocks.
|
|
|
|
patch do
|
|
|
|
url "https://example.com/example_patch.diff"
|
|
|
|
sha1 "deadbeefdeadbeefdeadbeefdeadbeefdeadbeef"
|
2013-03-18 16:25:35 +01:00
|
|
|
end
|
|
|
|
|
2014-03-13 19:51:23 -05:00
|
|
|
# A strip level of -p1 is assumed. It can be overridden using a symbol
|
|
|
|
# argument:
|
|
|
|
patch :p0 do
|
|
|
|
url "https://example.com/example_patch.diff"
|
|
|
|
sha1 "deadbeefdeadbeefdeadbeefdeadbeefdeadbeef"
|
2013-03-18 16:25:35 +01:00
|
|
|
end
|
|
|
|
|
2014-03-13 19:51:23 -05:00
|
|
|
# Patches can be declared in stable, devel, and head blocks. This form is
|
|
|
|
# preferred over using conditionals.
|
|
|
|
stable do
|
|
|
|
patch do
|
|
|
|
url "https://example.com/example_patch.diff"
|
|
|
|
sha1 "deadbeefdeadbeefdeadbeefdeadbeefdeadbeef"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
# Embedded (__END__) patches are declared like so:
|
|
|
|
patch :DATA
|
|
|
|
patch :p0, :DATA
|
|
|
|
|
|
|
|
# Patches can also be embedded by passing a string. This makes it possible
|
|
|
|
# to provide multiple embedded patches while making only some of them
|
|
|
|
# conditional.
|
|
|
|
patch :p0, "..."
|
2013-03-18 16:25:35 +01:00
|
|
|
|
|
|
|
## The install method.
|
|
|
|
|
|
|
|
def install
|
|
|
|
# Now the sources (from `url`) are downloaded, hash-checked and
|
|
|
|
# Homebrew has changed into a temporary directory where the
|
2013-11-30 19:48:02 +05:30
|
|
|
# archive has been unpacked or the repository has been cloned.
|
2013-03-18 16:25:35 +01:00
|
|
|
|
|
|
|
# Print a warning (do this rarely)
|
2014-03-22 08:23:08 +00:00
|
|
|
opoo "Dtrace features are experimental!" if build.with? "dtrace"
|
2013-03-18 16:25:35 +01:00
|
|
|
|
|
|
|
# Sometimes we have to change a bit before we install. Mostly we
|
|
|
|
# prefer a patch but if you need the `prefix` of this formula in the
|
|
|
|
# patch you have to resort to `inreplace`, because in the patch
|
|
|
|
# you don't have access to any var defined by the formula. Only
|
|
|
|
# HOMEBREW_PREFIX is available in the embedded patch.
|
2014-06-18 19:22:38 -05:00
|
|
|
# inreplace supports regular expressions.
|
2014-03-22 08:23:08 +00:00
|
|
|
inreplace "somefile.cfg", /look[for]what?/, "replace by #{bin}/tool"
|
2013-03-18 16:25:35 +01:00
|
|
|
|
|
|
|
# To call out to the system, we use the `system` method and we prefer
|
|
|
|
# you give the args separately as in the line below, otherwise a subshell
|
|
|
|
# has to be opened first.
|
|
|
|
system "./bootstrap.sh", "--arg1", "--prefix=#{prefix}"
|
|
|
|
|
|
|
|
# For Cmake, we have some necessary defaults in `std_cmake_args`:
|
|
|
|
system "cmake", ".", *std_cmake_args
|
|
|
|
|
|
|
|
# If the arguments given to configure (or make or cmake) are depending
|
|
|
|
# on options defined above, we usually make a list first and then
|
|
|
|
# use the `args << if <condition>` to append to:
|
|
|
|
args = ["--option1", "--option2"]
|
2014-03-22 08:23:08 +00:00
|
|
|
args << "--i-want-spam" if build.with? "spam"
|
2013-03-18 16:25:35 +01:00
|
|
|
args << "--qt-gui" if build.with? "qt" # "--with-qt" ==> build.with? "qt"
|
|
|
|
args << "--some-new-stuff" if build.head? # if head is used instead of url.
|
2013-12-07 14:21:36 +01:00
|
|
|
args << "--universal-binary" if build.universal?
|
2013-03-18 16:25:35 +01:00
|
|
|
|
|
|
|
# The `build.with?` and `build.without?` are smart enough to do the
|
2014-06-04 15:59:21 -05:00
|
|
|
# right thing with respect to defaults defined via `:optional` and
|
2013-03-18 16:25:35 +01:00
|
|
|
# `:recommended` dependencies.
|
|
|
|
|
|
|
|
# If you need to give the path to lib/include of another brewed formula
|
|
|
|
# please use the `opt_prefix` instead of the `prefix` of that other
|
|
|
|
# formula. The reasoning behind this is that `prefix` has the exact
|
|
|
|
# version number and if you update that other formula, things might
|
|
|
|
# break if they remember that exact path. In contrast to that, the
|
|
|
|
# `$(brew --prefix)/opt/formula` is the same path for all future
|
|
|
|
# versions of the formula!
|
2014-02-27 14:00:42 -06:00
|
|
|
args << "--with-readline=#{Formula["readline"].opt_prefix}/lib" if build.with? "readline"
|
2013-03-18 16:25:35 +01:00
|
|
|
|
|
|
|
# Most software still uses `configure` and `make`.
|
|
|
|
# Check with `./configure --help` what our options are.
|
|
|
|
system "./configure", "--disable-debug", "--disable-dependency-tracking",
|
|
|
|
"--prefix=#{prefix}",
|
|
|
|
*args # our custom arg list (needs `*` to unpack)
|
|
|
|
|
|
|
|
# If your formula's build system is not thread safe:
|
|
|
|
ENV.deparallelize
|
|
|
|
|
|
|
|
# A general note: The commands here are executed line by line, so if
|
|
|
|
# you change some variable or call a method like ENV.deparallelize, it
|
|
|
|
# only affects the lines after that command.
|
|
|
|
|
|
|
|
# Do something only for clang
|
|
|
|
if ENV.compiler == :clang
|
|
|
|
# modify CFLAGS CXXFLAGS OBJCFLAGS OBJCXXFLAGS in one go:
|
2014-03-22 08:23:08 +00:00
|
|
|
ENV.append_to_cflags "-I ./missing/includes"
|
2013-03-18 16:25:35 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
# Overwriting any env var:
|
2014-03-22 08:23:08 +00:00
|
|
|
ENV["LDFLAGS"] = "--tag CC"
|
2013-03-18 16:25:35 +01:00
|
|
|
|
|
|
|
system "make", "install"
|
|
|
|
|
|
|
|
# We are in a temporary directory and don't have to care about cleanup.
|
|
|
|
|
|
|
|
# Instead of `system "cp"` or something, call `install` on the Pathname
|
|
|
|
# objects as they are smarter with respect to correcting access rights.
|
|
|
|
# (`install` is a Homebrew mixin into Ruby's Pathname)
|
|
|
|
|
|
|
|
# The pathnames defined in the formula
|
2014-03-22 08:23:08 +00:00
|
|
|
prefix # == HOMEBREW_PREFIX+"Cellar"+name+version
|
|
|
|
bin # == prefix+"bin"
|
|
|
|
doc # == share+"doc"+name
|
|
|
|
include # == prefix+"include"
|
|
|
|
info # == share+"info"
|
|
|
|
lib # == prefix+"lib"
|
|
|
|
libexec # == prefix+"libexec"
|
2014-02-09 18:21:43 -02:00
|
|
|
buildpath # The temporary directory where build occurs.
|
2013-03-18 16:25:35 +01:00
|
|
|
|
2014-03-22 08:23:08 +00:00
|
|
|
man # share+"man"
|
|
|
|
man1 # man+"man1"
|
|
|
|
man2 # man+"man2"
|
|
|
|
man3 # man+"man3"
|
|
|
|
man4 # man+"man4"
|
|
|
|
man5 # man+"man5"
|
|
|
|
man6 # man+"man6"
|
|
|
|
man7 # man+"man7"
|
|
|
|
man8 # man+"man8"
|
|
|
|
sbin # prefix+"sbin"
|
|
|
|
share # prefix+"share"
|
|
|
|
frameworks # prefix+"Frameworks"
|
|
|
|
kext_prefix # prefix+"Library/Extensions"
|
2013-03-18 16:25:35 +01:00
|
|
|
# Configuration stuff that will survive formula updates
|
2014-03-22 08:23:08 +00:00
|
|
|
etc # HOMEBREW_PREFIX+"etc"
|
2013-03-18 16:25:35 +01:00
|
|
|
# Generally we don't want var stuff inside the keg
|
2014-03-22 08:23:08 +00:00
|
|
|
var # HOMEBREW_PREFIX+"var"
|
|
|
|
bash_completion # prefix+"etc/bash_completion.d"
|
|
|
|
zsh_completion # share+"zsh/site-functions"
|
2013-03-18 16:25:35 +01:00
|
|
|
# Further possibilities with the pathnames:
|
|
|
|
# http://www.ruby-doc.org/stdlib-1.8.7/libdoc/pathname/rdoc/Pathname.html
|
|
|
|
|
2014-01-18 19:34:45 +01:00
|
|
|
# Copy `./example_code/simple/ones` to share/demos
|
2014-03-22 08:23:08 +00:00
|
|
|
(share/"demos").install "example_code/simple/ones"
|
2013-03-18 16:25:35 +01:00
|
|
|
# Copy `./example_code/simple/ones` to share/demos/examples
|
2014-03-22 08:23:08 +00:00
|
|
|
(share/"demos").install "example_code/simple/ones" => "examples"
|
2013-03-18 16:25:35 +01:00
|
|
|
|
2014-03-03 18:14:02 -06:00
|
|
|
# Additional downloads can be defined as resources (see above).
|
|
|
|
# The stage method will create a temporary directory and yield
|
|
|
|
# to a block.
|
2014-03-22 08:23:08 +00:00
|
|
|
resource("additional_files").stage { bin.install "my/extra/tool" }
|
2013-03-18 16:25:35 +01:00
|
|
|
|
|
|
|
# `name` and `version` are accessible too, if you need them.
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
## Caveats
|
|
|
|
|
|
|
|
def caveats
|
|
|
|
"Are optional. Something the user should know?"
|
|
|
|
end
|
|
|
|
|
|
|
|
def caveats
|
|
|
|
s = <<-EOS.undent
|
|
|
|
Print some important notice to the user when `brew info <formula>` is
|
|
|
|
called or when brewing a formula.
|
|
|
|
This is optional. You can use all the vars like #{version} here.
|
|
|
|
EOS
|
|
|
|
s += "Some issue only on older systems" if MacOS.version < :mountain_lion
|
|
|
|
s
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
## Test (is optional but makes us happy)
|
|
|
|
|
|
|
|
test do
|
|
|
|
# `test do` will create, run in, and delete a temporary directory.
|
|
|
|
|
|
|
|
# We are fine if the executable does not error out, so we know linking
|
|
|
|
# and building the software was ok.
|
2014-03-22 08:23:08 +00:00
|
|
|
system bin/"foobar", "--version"
|
2013-03-18 16:25:35 +01:00
|
|
|
|
2014-03-22 08:23:08 +00:00
|
|
|
(testpath/"Test.file").write <<-EOS.undent
|
2013-03-18 16:25:35 +01:00
|
|
|
writing some test file, if you need to
|
|
|
|
EOS
|
|
|
|
# To capture the output of a command, we use backtics:
|
2014-03-22 08:23:08 +00:00
|
|
|
assert_equal "OK", ` test.file`.strip
|
2013-03-18 16:25:35 +01:00
|
|
|
|
|
|
|
# Need complete control over stdin, stdout?
|
2014-03-22 08:23:08 +00:00
|
|
|
require "open3"
|
2014-06-04 16:41:07 -05:00
|
|
|
Open3.popen3("#{bin}/example", "argument") do |stdin, stdout, _|
|
|
|
|
stdin.write("some text")
|
2013-03-18 16:25:35 +01:00
|
|
|
stdin.close
|
2014-06-04 16:41:07 -05:00
|
|
|
assert_equal "result", stdout.read
|
2013-03-18 16:25:35 +01:00
|
|
|
end
|
|
|
|
|
2014-10-21 22:43:46 -05:00
|
|
|
# The test will fail if it returns false, or if an exception is raised.
|
|
|
|
# Failed assertions and failed `system` commands will raise exceptions.
|
2013-03-18 16:25:35 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
## Plist handling
|
|
|
|
|
2014-11-18 03:53:32 +00:00
|
|
|
# Does your plist need to be loaded at startup?
|
|
|
|
plist_options :startup => true
|
|
|
|
# Or only when necessary or desired by the user?
|
|
|
|
plist_options :manual => "foo"
|
|
|
|
# Or perhaps you'd like to give the user a choice? Ooh fancy.
|
|
|
|
plist_options :startup => "true", :manual => "foo start"
|
|
|
|
|
2013-03-18 16:25:35 +01:00
|
|
|
# Define this method to provide a plist.
|
2014-11-18 03:53:32 +00:00
|
|
|
# Looking for another example? Check out Apple's handy manpage =>
|
|
|
|
# https://developer.apple.com/library/mac/documentation/Darwin/Reference/ManPages/man5/plist.5.html
|
|
|
|
def plist; <<-EOS.undent
|
|
|
|
<?xml version="1.0" encoding="UTF-8"?>
|
|
|
|
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
|
|
|
<plist version="1.0">
|
|
|
|
<dict>
|
|
|
|
<key>Label</key>
|
|
|
|
<string>#{plist_name}</string>
|
|
|
|
<key>RunAtLoad</key>
|
|
|
|
<true/>
|
|
|
|
<key>KeepAlive</key>
|
|
|
|
<true/>
|
|
|
|
</plist>
|
|
|
|
EOS
|
|
|
|
end
|
2013-03-18 16:25:35 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
__END__
|
|
|
|
# Room for a patch after the `__END__`
|
2014-10-26 14:54:36 +00:00
|
|
|
# Read about how to get a patch in here:
|
|
|
|
# https://github.com/Homebrew/homebrew/blob/master/share/doc/homebrew/Formula-Cookbook.md
|
2013-03-18 16:25:35 +01:00
|
|
|
# In short, `brew install --interactive --git <formula>` and make your edits.
|
|
|
|
# Then `git diff >> path/to/your/formula.rb`
|
|
|
|
# Note, that HOMEBREW_PREFIX will be replaced in the path before it is
|
|
|
|
# applied. A patch can consit of several hunks.
|