summaryrefslogtreecommitdiff
path: root/build/top.mk
blob: 34b46c985240bec55505ce7dbf549896d8f3b4d2 (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
# ucoolib - Microcontroller object oriented library.
#
# Build system top file. To be included with $(BASE) pointing to the project
# root.

ifeq ($(BASE),)
$(error BASE is not defined)
endif

UCOO_BASE := $(patsubst %/build/top.mk,%,$(lastword $(MAKEFILE_LIST)))

include $(UCOO_BASE)/build/macros.mk
-include $(BASE)/build/macros.mk

# General parameters.

OBJDIR := obj

INCLUDES := $(INCLUDES) -I$(UCOO_BASE) -I$(BASE) -I$(OBJDIR)
CPPFLAGS = $(DEFS) $(INCLUDES) -MP -MMD
OPTIMIZE ?= -Os
CFLAGS = -g3 -Wall -W -Wundef -Wno-unused-parameter \
	-fno-exceptions $(OPTIMIZE)
CXXFLAGS = $(CFLAGS) -fno-rtti -fno-threadsafe-statics -std=gnu++11 -Wno-deprecated-declarations
LDFLAGS =
LDLIBS = $(LIBS)

# Quiet, unset to see executed lines.
Q = @

# Main rules.

all:
lst:
size:
hex:
srec:
bin:
crc:
test:

clean:
	$(if $(EXTRA_CLEAN),rm -f $(EXTRA_CLEAN))
	$(if $(EXTRA_CLEAN_DIRS),@echo rmdir $(EXTRA_CLEAN_DIRS))
	$(if $(EXTRA_CLEAN_DIRS),$(call rmdir_as_needed,$(EXTRA_CLEAN_DIRS),$(OBJDIR)))
	@echo rmdir '$(OBJDIR)/.../'
	$(call rmdir_as_needed,$(OBJDIRS),$(OBJDIR))

.PHONY: all lst size hex srec bin crc test clean

# Modules and sources setup.

include $(UCOO_BASE)/build/setup.mk

vpath %.cc $(UCOO_BASE) $(BASE)
vpath %.cpp $(UCOO_BASE) $(BASE)
vpath %.c $(UCOO_BASE) $(BASE)
vpath %.S $(UCOO_BASE) $(BASE)

# Configuration.

include $(UCOO_BASE)/build/config.mk

# Objects directory.

$(OBJDIR):
	$Qmkdir -p $@

# Arch specific.

include $(UCOO_BASE)/build/arch.mk
define TARGETS_template
include $$(firstword $$(wildcard $$(BASE)/build/$1.mk) $$(UCOO_BASE)/build/$1.mk)
endef
$(foreach target,$(TARGETS),$(eval $(call TARGETS_template,$(target))))

TARGETS_SUBTARGETS := $(foreach target,$(TARGETS),$(target):$(target) \
	$(foreach subtarget,$($(target)_SUBTARGETS),$(target):$(subtarget)))

.PHONY: program
ifeq ($(words $(filter-out host,$(TARGETS))),1)
program: $(patsubst %,program.%,$(filter-out host,$(TARGETS)))
endif