summaryrefslogtreecommitdiff
path: root/2021/Makefile
diff options
context:
space:
mode:
authorTom Smeding <tom@tomsmeding.com>2021-12-01 19:22:21 +0100
committerTom Smeding <tom@tomsmeding.com>2021-12-01 19:22:21 +0100
commit3dc0370ab576388b7fe6908ac73c4561551a494c (patch)
tree43276a34370552a7981946587c1f3df8b8f04020 /2021/Makefile
parent833fcf24d661ef600d00c017ce7796b2fc938a17 (diff)
2021
Diffstat (limited to '2021/Makefile')
-rw-r--r--2021/Makefile47
1 files changed, 47 insertions, 0 deletions
diff --git a/2021/Makefile b/2021/Makefile
new file mode 100644
index 0000000..7ad280f
--- /dev/null
+++ b/2021/Makefile
@@ -0,0 +1,47 @@
+GHC = ghc
+GHCBASEFLAGS = -package parsec -package array
+GHCFLAGS = $(GHCBASEFLAGS) -Wall -O2 -threaded -fdefer-typed-holes
+CXX = g++
+CXXFLAGS = -Wall -Wextra -std=c++17 -O2
+
+OBJDIR = obj
+
+HASKELL_AUX := Input.hs Util.hs Asm.hs
+CPP_AUX :=
+HASKELL_SRC := $(filter-out $(HASKELL_AUX),$(wildcard *.hs))
+CPP_SRC := $(filter-out $(CPP_AUX),$(wildcard *.cpp))
+HASKELL_BIN := $(HASKELL_SRC:.hs=)
+CPP_BIN := $(CPP_SRC:.cpp=)
+
+BINARIES := $(HASKELL_BIN) $(CPP_BIN)
+
+.PHONY: all clean depend
+
+
+all: $(BINARIES)
+
+clean:
+ rm -f $(BINARIES) .depend_hs
+ rm -rf $(OBJDIR)
+
+# Generate the .depend_hs file for correct Haskell dependency tracking
+depend:
+ ghc -dep-suffix '' -dep-makefile .depend_hs -M $(GHCBASEFLAGS) $(HASKELL_SRC)
+ sed -i 's/\.o *:/:/; s/\.hi$$/.hs/g; s/\.hi[ \t]/.hs/g' .depend_hs
+ rm -f .depend_hs.bak
+
+$(HASKELL_BIN): %: %.hs | $(OBJDIR)/%
+ $(GHC) $(GHCFLAGS) -odir $(OBJDIR)/$* -hidir $(OBJDIR)/$* -o $@ $<
+
+$(CPP_BIN): %: %.cpp $(CPP_AUX) | $(OBJDIR)
+ $(CXX) $(CXXFLAGS) -o $@ $<
+
+$(OBJDIR)/%:
+ mkdir -p $@
+
+
+# By default, if it's needed, just create an empty file (but don't truncate if it exists)
+.depend_hs:
+ touch $@
+
+-include .depend_hs