summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortomsmeding <tom.smeding@gmail.com>2019-12-05 11:56:15 +0100
committertomsmeding <tom.smeding@gmail.com>2019-12-05 11:56:15 +0100
commit3be84c5542e3392bbcf5cfe3e229fdcec4520235 (patch)
tree2f182ca4de3c16c19797a6c88c1dfae7e70e81b6
parent821c9a8c5209344538cadea879b3af6c8752e9bb (diff)
Better haskell dependency tracking in Makefile
-rw-r--r--2019/.gitignore1
-rw-r--r--2019/Makefile15
2 files changed, 13 insertions, 3 deletions
diff --git a/2019/.gitignore b/2019/.gitignore
index 3564178..ebbfb2e 100644
--- a/2019/.gitignore
+++ b/2019/.gitignore
@@ -1,4 +1,5 @@
obj/
+.depend_hs
1
2
3
diff --git a/2019/Makefile b/2019/Makefile
index a8383a3..ee0449e 100644
--- a/2019/Makefile
+++ b/2019/Makefile
@@ -5,7 +5,7 @@ CXXFLAGS = -Wall -Wextra -std=c++17 -O2
OBJDIR = obj
-HASKELL_AUX := Input.hs
+HASKELL_AUX := Input.hs IntCode.hs
CPP_AUX :=
HASKELL_SRC := $(filter-out $(HASKELL_AUX),$(wildcard *.hs))
CPP_SRC := $(filter-out $(CPP_AUX),$(wildcard *.cpp))
@@ -20,10 +20,10 @@ BINARIES := $(HASKELL_BIN) $(CPP_BIN)
all: $(BINARIES)
clean:
- rm -f $(BINARIES)
+ rm -f $(BINARIES) .depend_hs
rm -rf $(OBJDIR)
-$(HASKELL_BIN): %: %.hs $(HASKELL_AUX) | $(OBJDIR)/%
+$(HASKELL_BIN): %: %.hs | $(OBJDIR)/%
$(GHC) $(GHCFLAGS) -odir $(OBJDIR)/$* -hidir $(OBJDIR)/$* -o $@ $<
$(CPP_BIN): %: %.cpp $(CPP_AUX) | $(OBJDIR)
@@ -31,3 +31,12 @@ $(CPP_BIN): %: %.cpp $(CPP_AUX) | $(OBJDIR)
$(OBJDIR)/%:
mkdir -p $@
+
+
+.depend_hs: $(HASKELL_SRC) $(HASKELL_AUX)
+ ghc -dep-suffix '' -dep-makefile $@ -M $(HASKELL_SRC)
+ rm -f .depend_hs.bak
+ sed 's/\.o *:/:/; s/\.hi$$/.hs/g; s/\.hi[ \t]/.hs/g' <$@ >$@.tmp
+ mv $@.tmp $@
+
+-include .depend_hs