Created
November 22, 2013 03:42
-
-
Save metajack/7594447 to your computer and use it in GitHub Desktop.
makefile-fu to determine rustc output filenames given consistent and computable hashes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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