aboutsummaryrefslogtreecommitdiff
path: root/Makefile
blob: 53b42a0aae1729eb6c34d6c8fb8ce84b6442bd8f (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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
# vim:ts=4:sw=4:sts=4:noexpandtab
MAKEFLAGS += --no-builtin-rules

# Default output path. Can be changed by enviroment to compile to different folder
# than default.
O ?= .
# This variable can be overwritten to show executed commands
Q ?= @
# This variable can be used if you want to have configuration file for you project
# in different location than default. You should use absolute path.
CONFIG ?= $(O)/.config

.PHONY: all
# Check if we have configuration"
ifneq ("$(wildcard $(CONFIG))","")
all: libioe.a
else
all: help $(CONFIG)
endif

ifneq ("$(wildcard $(CONFIG))","") # Check if we have configuration
ifeq (,$(filter clean help docs serve-docs clean-docs config oldconfig \
	allyesconfig menuconfig, \
	$(MAKECMDGOALS))) # Ignore build targets if goal is not building

include $(CONFIG) # include configuration
include src/sources.mk

OBJ = $(patsubst %.c,$(O)/build/%.o,$(SRC))
DEP = $(patsubst %.c,$(O)/build/%.d,$(SRC))

-include $(DEP)

CFLAGS = $(shell echo $(CCFLAGS)) $(shell echo -DF_CPU=$(F_CPU)000L) \
		 -mmcu=$(MMCU) -Iinclude -imacros $(O)/build/config.h
CC = $(CHOST)gcc
AR = $(CHOST)ar
CPP = $(CHOST)cpp

$(O)/libioe.a: $(OBJ)
	@echo " AR   $@"
	$(Q)$(AR) -crs $@ $^

$(OBJ): $(O)/build/%.o: src/%.c
	@mkdir -p "$(@D)"
	@echo " CC   $@"
	$(Q)$(CC) $(CFLAGS) -c -o $@ $<

$(DEP): $(O)/build/%.d: src/%.c $(O)/build/config.h
	@mkdir -p "$(@D)"
	@echo " DEP  $@"
	$(Q)$(CPP) -MM -MG -MT '$(O)/build/$*.o $@' $(CFLAGS) -o $@ $<

$(O)/build/config.h: $(CONFIG)
	@mkdir -p "$(@D)"
	@echo " GEN  $@"
	$(Q)grep -v "^#" $(CONFIG) | grep "CONFIG_" | sed -e 's/="\(.*\)"/=\1/;s/=/ /;s/^/#define /' > $@

else
$(O)/libioe.a:
	@echo Please execute non-building target separate from building ones
	@exit 1
endif
else
$(O)/libioe.a: $(CONFIG) # Print error message for missing config file
endif

.PHONY: clean
clean:
	@echo " CLEAN BUILD"
	$(Q)$(RM) -r $(O)/build
	@echo " CLEAN libioe.a"
	$(Q)$(RM) $(O)/libioe.a

.PHONY: docs
docs:
	@echo " DOC $@"
	$(Q)mkdocs build


.PHONY: serve-docs
serve-docs:
	$(Q)mkdocs serve

.PHONY: clean-docs
clean-docs:
	@echo " CLEAN docs"
	$(Q)$(RM) -r html

.PHONY: proper
proper: clean clean-docs
	@echo " CLEAN CONFIG"
	$(Q)$(RM) $(CONFIG) $(CONFIG).orig .config.cmd

.PHONY: help
help:
	@echo  "AVR input/output expansion library"
	@echo  "all/libioe.a - Build library"
	@echo  "config       - Start configuration program"
	@echo  "menuconfig   - NCurses based configuration program (Kconfig)"
	@echo  "docs         - Build documentation"
	@echo  "server-docs  - Start temporally http server with documentation"
	@echo  "help         - Prints this text"
	@echo  "clean        - Removing all object files generated from source files"
	@echo  "clean-docs   - Remove generated documentation"
	@echo  "proper       - Cleans everything including configuration"

TOOL_PATH=tools
IOEROOT=.
include tools/kconfig.mk