Skip to content

Instantly share code, notes, and snippets.

@metajack
Created November 22, 2013 03:42
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save metajack/7594447 to your computer and use it in GitHub Desktop.
Save metajack/7594447 to your computer and use it in GitHub Desktop.
makefile-fu to determine rustc output filenames given consistent and computable hashes
RUSTC = rustc
RUSTFLAGS =
.PHONY : all
all: something
# create something's targets
$(eval $(call CRATE_LIB_TARGET, lib.rs))
# helper function to create crate targets for libraries
define CRATE_LIB_TARGET
INPUTS = $(1)
LIBFILE = $(firstword $(1))
PKGID = $$(shell sed -ne "s/^\#\[ *pkgid *= *\"\(.*\)\" *];$$$$/\1/p" $$(LIBFILE))
CRATE_NAME = $$(shell python -c 'import re; print re.sub("^(?:.*/)?([^\#]+).*$$$$", "\\1", "$$(PKGID)")')
CRATE_VERSION = $$(shell python -c 'import re; print re.sub("^(?:[^\#]*\#)?(.*)$$$$", "\\1", "$$(PKGID)")')
CRATE_HASH = $$(shell python -c 'import sha; print sha.new("$$(PKGID)").hexdigest()[:8]')
CRATE_OUTPUT = lib$$(CRATE_NAME)-$$(CRATE_HASH)-$$(CRATE_VERSION).dylib
.PHONY : $$(CRATE_NAME)
$$(CRATE_NAME) : $$(CRATE_OUTPUT)
$$(CRATE_OUTPUT) : $$(INPUTS)
$$(RUSTC) $$(RUSTFLAGS) --lib $$(LIBFILE)
INPUTS =
LIBFILE =
PKGID =
CRATE_NAME =
CRATE_VERSION =
CRATE_HASH =
CRATE_OUTPUT =
endef
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment