Skip to content

Instantly share code, notes, and snippets.

@wenkokke
Last active June 24, 2016 13:19
Show Gist options
  • Save wenkokke/ef9fc9d9cf8ef48865ba to your computer and use it in GitHub Desktop.
Save wenkokke/ef9fc9d9cf8ef48865ba to your computer and use it in GitHub Desktop.
A simple makefile which delegates every task to a Shake build file.
BUILDFILE := ./buildfile.hs
BUILD := ./_build/build
BUILDDIR := $(dir $(BUILD))
SOURCES := $(shell find .)
SOURCES := $(filter-out ./Makefile,$(SOURCES))
SOURCES := $(filter-out $(BUILD),$(SOURCES))
SOURCES := $(filter-out $(BUILDFILE),$(SOURCES))
# Delegate the default task.
default:
@$(MAKE) $(BUILD)
@$(BUILD)
# Delegate all file tasks for existing files.
$(SOURCES):
@$(MAKE) $(BUILD)
@$(BUILD) "$@"
.PHONY: $(SOURCES)
# Delegate all other tasks.
.DEFAULT:
@$(MAKE) $(BUILD)
@$(BUILD) "$@"
# Compile buildfile.hs.
$(BUILD): $(BUILDFILE)
cabal install shake
mkdir -p $(BUILDDIR)
ghc --make $(BUILDFILE) -rtsopts -with-rtsopts=-I0 -outputdir=$(BUILDDIR) -o $(BUILD)
# Clean up the _build directory.
clean:
@rm -rf $(BUILDDIR)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment