summaryrefslogtreecommitdiff
path: root/n/avr/make/Makefile.gen
blob: e4039235a0935990ffa6cdca3e267f84c00e715d (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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# Makefile.gen - General Makefile.

# Flags

INCLUDES = -I$(BASE) -I$(BASE)/common
CFLAGS = -g -Wall -W -Wundef -Wno-unused-parameter $(OPTIMIZE)
ASFLAGS = -Wa,--gstabs
CPPFLAGS = $(DEFS) $(INCLUDES) -MMD \
	   $(if $(CONFIGFILE),$(CONFIGFILE:%=-include %))
LDFLAGS =
LDLIBS = $(LIBS)

# Main rules.

all: avr host

.PHONY: all clean doc

# General rules.

ALL_PROGS = $(PROGS) $(AVR_PROGS) $(HOST_PROGS)
SOURCES = $(foreach prog,$(ALL_PROGS),$($(prog)_SOURCES))

# Modules.

MODULES += host

ifneq (,$(MODULES))
include $(MODULES:%=$(BASE)/modules/%/Makefile.module)
endif

none_SOURCES =

define MODULES_template
$(1)_SOURCES += $(foreach module,\
	$(if $($(1)_MODULES),$($(1)_MODULES),$(MODULES)),\
	$($(subst /,_,$(module))_SOURCES)\
)
endef

$(foreach prog,$(ALL_PROGS),$(eval $(call MODULES_template,$(prog))))

vpath %.c $(MODULES:%=$(BASE)/modules/%)
vpath %.S $(MODULES:%=$(BASE)/modules/%)

# Compilation test rules.

define TEST_MCU_template
test.sub::
	$$(MAKE) CONFIGFILE=$(1) AVR_MCU=$(2) clean elf
endef

define TEST_template
$$(foreach mcu,$$(if $$($(1:%.h=%)_MCU),$$($(1:%.h=%)_MCU),$$(TEST_MCU)),\
	$$(eval $$(call TEST_MCU_template,$(1),$$(mcu))))
test.sub::
	$$(MAKE) CONFIGFILE=$(1) clean host
endef

$(foreach config,$(TEST_CONFIGFILES),$(eval $(call TEST_template,$(config))))

test: test.sub clean

# Include other Makefiles.

ifneq (,$(filter-out %.c %.avr.S,$(SOURCES)))
$(error Sources should be .c or .avr.S files)
endif

ifneq (,$(strip $(ALL_PROGS)))
include $(BASE)/make/Makefile.avr
include $(BASE)/make/Makefile.host
else
avr:
host:
clean.avr:
clean.host:
endif

# Rules for building the doc.

doc: $(DOC)

%.html: %.txt %.exd
	aft $<

%.exd: $(EXTRACTDOC)
	test -n "$^" && extractdoc $^ > $@ || true

# Cleaning.

clean: clean.avr clean.host
	rm -f *.bak *~ $(DOC) *.exd $(EXTRA_CLEAN_FILES)