-
Notifications
You must be signed in to change notification settings - Fork 0
/
autodep.mk
60 lines (46 loc) · 1.75 KB
/
autodep.mk
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# This defines build rules for c/c++/cuda sources with automatic dependency generation
SRCS ?= *.c *.cpp *.cc *.cxx *.cu
DEPDIR := .deps
$(shell mkdir -p $(DEPDIR) >/dev/null)
DEPFLAGS = -MT $@ -MMD -MP -MF $(DEPDIR)/$*.Td
GCCFLAGS += -fmessage-length=80 #-fdiagnostics-color=auto
DEPBUILD.c = $(CC) -x c $(DEPFLAGS) $(CFLAGS) $(CPPFLAGS) -E
DEPBUILD.cc = $(CXX) -x c++ $(DEPFLAGS) $(CXXFLAGS) $(CPPFLAGS) -E
COMPILE.c = $(CC) $(CFLAGS) $(CPPFLAGS) $(GCCFLAGS) $(TARGET_ARCH) -c
COMPILE.cc = $(CXX) $(CXXFLAGS) $(CPPFLAGS) $(GCCFLAGS) $(TARGET_ARCH) -c
COMPILE.nvcc = $(NVCC) $(NVCCFLAGS) $(CPPFLAGS) -Xcompiler "$(GCCFLAGS)" $(TARGET_ARCH) -c
POSTCOMPILE = mv -f $(DEPDIR)/$*.Td $(DEPDIR)/$*.d
CLEAR_LINE = tput el && echo -n "\033[2K" || true # Clears the current line
%.o : %.c
%.o : %.c $(DEPDIR)/%.d
@$(CLEAR_LINE); echo -n "Building C source file $<\r"
@$(DEPBUILD.c) $< > /dev/null
$(COMPILE.c) $(OUTPUT_OPTION) $<
@$(POSTCOMPILE)
%.o : %.cpp
%.o : %.cpp $(DEPDIR)/%.d
@$(CLEAR_LINE); echo -n "Building C++ source file $<\r"
$(DEPBUILD.cc) $< > /dev/null
$(COMPILE.cc) $(OUTPUT_OPTION) $<
$(POSTCOMPILE)
%.o : %.cc
%.o : %.cc $(DEPDIR)/%.d
@$(CLEAR_LINE); echo -n "Building C++ source file $<\r"
@$(DEPBUILD.cc) $< > /dev/null
$(COMPILE.cc) $(OUTPUT_OPTION) $<
@$(POSTCOMPILE)
%.o : %.cxx
%.o : %.cxx $(DEPDIR)/%.d
@$(CLEAR_LINE); echo -n "Building C++ source file $<\r"
@$(DEPBUILD.cc) $< > /dev/null
$(COMPILE.cc) $(OUTPUT_OPTION) $<
@$(POSTCOMPILE)
%.o : %.cu
%.o : %.cu $(DEPDIR)/%.d
@$(CLEAR_LINE); echo -n "Building CUDA source file $<\r"
@$(DEPBUILD.cc) $< > /dev/null
$(COMPILE.nvcc) $(OUTPUT_OPTION) $<
@$(POSTCOMPILE)
$(DEPDIR)/%.d: ;
.PRECIOUS: $(DEPDIR)/%.d
-include $(patsubst %,$(DEPDIR)/%.d,$(basename $(SRCS)))