summaryrefslogtreecommitdiff
path: root/target-rules.mk
blob: 5ef9dde704eb4efd0fb8da4e2be5906c477b8aea (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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
%.o: %.c
	$(E) "[TC]     Compiling $<"
	$(Q)$(TARGET_CC) -ffunction-sections -Wall -Werror $(addprefix -I, $(TARGET_INCLUDES)) $(TARGET_CFLAGS) $(TARGET_CPPFLAGS) -g -c -o $@ $<

%.o: %.cc
	$(E) "[TCXX]   Compiling $<"
	$(Q)$(TARGET_CXX) -ffunction-sections -Wall -Werror $(addprefix -I, $(TARGET_INCLUDES)) $(TARGET_CFLAGS) $(TARGET_CPPFLAGS) -g -c -o $@ $<

%.o: %.cpp
	$(E) "[TCXX]   Compiling $<"
	$(Q)$(TARGET_CXX) -ffunction-sections -Wall -Werror $(addprefix -I, $(TARGET_INCLUDES)) $(TARGET_CFLAGS) $(TARGET_CPPFLAGS) -g -c -o $@ $<

%.o: %.s
	$(E) "[TS]     Compiling $<"
	$(Q)$(TARGET_AS) $(addprefix -I, $(TARGET_INCLUDES)) $(TARGET_ASFLAGS) $(TARGET_CPPFLAGS) -g -c -o $@ $<

%.dep: %.c
	$(Q)$(TARGET_CC) -ffunction-sections -Wall -Werror $(addprefix -I, $(TARGET_INCLUDES)) $(TARGET_CFLAGS) $(TARGET_CPPFLAGS) -g -M -MT $(addsuffix .o, $(basename $@)) -MF $@ $<

%.dep: %.cc
	$(Q)$(TARGET_CXX) -ffunction-sections -Wall -Werror $(addprefix -I, $(TARGET_INCLUDES)) $(TARGET_CFLAGS) $(TARGET_CPPFLAGS) -g -M -MT $(addsuffix .o, $(basename $@)) -MF $@ $<

%.dep: %.cpp
	$(Q)$(TARGET_CXX) -ffunction-sections -Wall -Werror $(addprefix -I, $(TARGET_INCLUDES)) $(TARGET_CFLAGS) $(TARGET_CPPFLAGS) -g -M -MT $(addsuffix .o, $(basename $@)) -MF $@ $<

%.dep: %.s
	$(Q)touch $@

%.dep: %.o
	$(Q)touch $@

TARGET_OBJS = $(addsuffix .o, $(basename $(TARGET_SRCS)))
TARGET_DEPS = $(addsuffix .dep, $(basename $(TARGET_SRCS)))

ifneq ($(TARGET),)
TARGET_ELF = $(addsuffix .elf, $(basename $(TARGET)))
TARGET_BIN = $(addsuffix .bin, $(basename $(TARGET)))
TARGET_MAP = $(addsuffix .map, $(basename $(TARGET)))
TARGET_OBJS += $(addsuffix .o, $(basename $(TARGET)))
TARGET_DEPS += $(addsuffix .dep, $(basename $(TARGET)))
endif

$(TARGET_ELF): $(TARGET_OBJS) $(LIBDEPS) $(LDSCRIPT) $(SPECS)
	$(E) "[TL]     Linking $@"
	$(Q)$(TARGET_LD) -Wl,--gc-sections -Wl,-Map=$(TARGET_MAP) -o $@ $(TARGET_OBJS) $(TARGET_LDFLAGS) -g -T$(LDSCRIPT) -specs=$(SPECS) $(LIBS)

$(TARGET_MAP): $(TARGET_ELF)

$(TARGET_BIN): $(TARGET_ELF)
	$(E) "[TB]     Creating $@"
	$(Q)$(TARGET_OBJCOPY) $< -O binary $@

$(TARGET_LIB): $(TARGET_OBJS)
	$(E) "[TLIB]   Creating $@"
	$(Q)$(TARGET_AR) rcs $@ $^

.PHONY: clean-generic ldeps

clean-generic:
	$(E) "[CLEAN]  $(CURDIR)"
	$(Q)rm -f $(TARGET_LIB) $(TARGET_OBJS) $(TARGET) $(TARGET_ELF) $(TARGET_BIN) $(TARGET_MAP) $(TARGET_DEPS)

ldeps: $(TARGET_DEPS)

-include $(TARGET_DEPS)