A Makefile for building ruby gems
This Makefile aids in developing a ruby gem. It's pretty opinionated to my workflow, but it might be useful to you, so here it goes.
- Assumes you use of
gst) for managing gemsets.
- Assumes you use
depfor installing dependencies. Because fuck Bundler.
- Assumes the directory in which the source code is located is named
after the gem. So
basename $(dirname $(pwd))would return
fooif you would
gem install foo.
- Assumes the existance of a
lib/*/version.rbthat has a line that defines a
If All those assumptions / prerequisites are met, then you can:
make test: run your tests. By default this Makefile assumes the use of [
cutest][cutest], but you can change that to whatever strikes your fancy.
make pkg/foo-1.0.0.gem: Build the gem. This will properly track any changes to the gemspec and to the
make all(or just
make): Run tests and then build all the gems.
make release: Build gems and then push them to https://rubygems.org.
make clean: Delete any built gems.
The tests will
dep install before running, but only if the
changed. In order to avoid polluting the global namespace and installing
gems in your root GEM_HOME, all the tasks in this Makefile will fail if
you're not inside a gemset (i.e.
GS_NAME isn't set).
The Makefile will also run tasks with
./test added to your
ruby include path (via expanding the
RUBYLIB env var). This should allow
you to work without needing to touch the
$LOAD_PATH inside your project,
which is a horrible practice.
In case your directory doesn't exactly match the gem name, you can just
PACKAGES variable to list the names of the package(s) to be
You can also change the
VERSION_FILE variable in order to change the
pattern to find the
version.rb file. This defaults to