summaryrefslogtreecommitdiff
path: root/2020/Makefile
blob: 0b1c54faeb7b4ac76643437d5968673085c38a09 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
GHC = ghc
GHCBASEFLAGS = -package parsec -package array
GHCFLAGS = $(GHCBASEFLAGS) -Wall -O2 -threaded
CXX = g++
CXXFLAGS = -Wall -Wextra -std=c++17 -O2

OBJDIR = obj

HASKELL_AUX := Input.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


all: $(BINARIES)

clean:
	rm -f $(BINARIES) .depend_hs
	rm -rf $(OBJDIR)

$(HASKELL_BIN): %: %.hs | $(OBJDIR)/%
	$(GHC) $(GHCFLAGS) -odir $(OBJDIR)/$* -hidir $(OBJDIR)/$* -o $@ $<

$(CPP_BIN): %: %.cpp $(CPP_AUX) | $(OBJDIR)
	$(CXX) $(CXXFLAGS) -o $@ $<

$(OBJDIR)/%:
	mkdir -p $@


.depend_hs: $(HASKELL_SRC) $(HASKELL_AUX)
	ghc -dep-suffix '' -dep-makefile $@ -M $(GHCBASEFLAGS) $(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