-
Notifications
You must be signed in to change notification settings - Fork 29
/
autodep.mk
65 lines (47 loc) · 1.6 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
60
61
62
63
64
65
# Common phony targets
.PHONY: all clean
#
# C, C++, Assembly autodependencies and compilation
#
# Directory to store auto-generated dependency makefile fragments
DEPDIR := .d
# Make sure dependency file directory exists
$(shell mkdir -p $(DEPDIR) >/dev/null)
# Flags to use when generating autodependencies
DEPFLAGS = -MMD -MP -MF $(DEPDIR)/$(notdir $*).Td
#-MT $@
DEPFLAGS.nasm = -MD $(DEPDIR)/$(notdir $*).Td
OUTPUT_OPTION = -o $@
# Compile commands for C and C++
COMPILE.c = $(CC) $(DEPFLAGS) $(CFLAGS) $(CPPFLAGS) $(TARGET_ARCH) $(OUTPUT_OPTION) -c
COMPILE.cc = $(CXX) $(DEPFLAGS) $(CXXFLAGS) $(CPPFLAGS) $(TARGET_ARCH) $(OUTPUT_OPTION) -c
COMPILE.s = $(AS) $(ASFLAGS) $(TARGET_ARCH_AS) $(OUTPUT_OPTION) -c
COMPILE.asm = $(NASM) $(NASMFLAGS) $(TARGET_ARCH_NASM)
COMPILE.as = $(AS) $(DEPFLAGS) $(ASFLAGS) $(OUTPUT_OPTION) -c
# Command to move generated dependency files into separate directory
POSTCOMPILE = mv -f $(DEPDIR)/$(notdir $*).Td $(DEPDIR)/$(notdir $*).d
.s.o:
$(COMPILE.as) $<
.asm.o:
$(COMPILE.asm) $(OUTPUT_OPTION) $(DEPFLAGS.nasm) $<
$(POSTCOMPILE)
.c.o:
$(COMPILE.c) $<
$(POSTCOMPILE)
.SUFFIXES: .asm
ifdef DISASSEMBLEFLAGS
# Disassemble
$(DUMPDIR)/%.dis : $(BINDIR)/%.bin
$(DUMPDIR)/%.dis : $(BINDIR)/%.bin
objdump $(DISASSEMBLEFLAGS) $< > $@
endif
# Hex Dump
$(DUMPDIR)/%.hex : $(BINDIR)/%.bin
$(DUMPDIR)/%.hex : $(BINDIR)/%.bin
hexdump -C $< > $@
# Tolerate the dependency files being missing
$(DEPDIR)/%.d: ;
# Prevent deletion of generated dependencies
.PRECIOUS: $(DEPDIR)/%.d
# Include the generated makefile fragments
-include $(patsubst %,$(DEPDIR)/%.d,$(notdir $(basename $(CSRCS))))