summaryrefslogtreecommitdiffstats
path: root/utils/hwstub/stub/hwstub.make
blob: b46a2736efd35ef85a5e0e9a710b973854e23094 (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
INCLUDES+=-I$(ROOT_DIR)
LINKER_FILE=$(ROOT_DIR)/hwstub.lds
TMP_LDS=$(BUILD_DIR)/link.lds
TMP_MAP=$(BUILD_DIR)/hwstub.map
CFLAGS=$(GCCOPTS) $(DEFINES) -W -Wall -Wundef -O -nostdlib -ffreestanding -Wstrict-prototypes -pipe -std=gnu99 -fomit-frame-pointer -Wno-pointer-sign -Wno-override-init $(INCLUDES)
ASFLAGS=$(CFLAGS) -D__ASSEMBLER__
LDFLAGS=-lgcc -Os -nostdlib -T$(TMP_LDS) -Wl,-Map,$(TMP_MAP) $(INCLUDES) -L$(BUILD_DIR)

SRC:=$(shell cat $(ROOT_DIR)/SOURCES | $(CC) $(INCLUDES) \
    $(DEFINES) -E -P -include "config.h" - 2>/dev/null \
    | grep -v "^\#")
SRC:=$(foreach src,$(SRC),$(BUILD_DIR)/$(src))
OBJ=$(SRC:.c=.o)
OBJ:=$(OBJ:.S=.o)
OBJ_EXCEPT_CRT0=$(filter-out $(BUILD_DIR)/crt0.o,$(OBJ))
EXEC_ELF=$(BUILD_DIR)/hwstub.elf
DEPS=$(foreach obj,$(OBJ),$(obj).d)

EXEC=$(EXEC_ELF)

SILENT?=@
PRINTS=$(SILENT)$(call info,$(1))

all: $(EXEC)

# pull in dependency info for *existing* .o files
-include $(DEPS)

$(BUILD_DIR)/%.o: $(ROOT_DIR)/%.c
	$(SILENT)mkdir -p $(dir $@)
	$(call PRINTS,CC $(<F))
	$(SILENT)$(CC) $(CFLAGS) -c -o $@ $<
	$(SILENT)$(CC) -MM $(CFLAGS) $< -MT $@ > $@.d

$(BUILD_DIR)/%.o: $(ROOT_DIR)/%.S
	$(call PRINTS,AS $(<F))
	$(SILENT)mkdir -p $(dir $@)
	$(SILENT)$(AS) $(ASFLAGS) -c -o $@ $<

$(TMP_LDS): $(LINKER_FILE)
	$(call PRINTS,PP $(<F))
	$(SILENT)$(CC) $(CFLAGS) -E -x c - < $< | sed '/#/d' > $@

$(EXEC_ELF): $(OBJ) $(TMP_LDS)
	$(call PRINTS,LD $(@F))
	$(SILENT)$(LD) $(LDFLAGS) -o $@ $(OBJ_EXCEPT_CRT0)

clean:
	$(SILENT)rm -rf $(OBJ) $(DEPS) $(EXEC) $(TMP_LDS) $(TMP_MAP)