-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
171 lines (138 loc) · 6.06 KB
/
Makefile
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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
#
# Provides targets to build code with SDCC, generate documentation etc.
#
# | Target | Function |
# |-----------------|---------------------------------------------------|
# | build (default) | Builds a .hex file and dependencies |
# | all | Builds a .hex file and every .c library |
# | dbc | Builds C headers from Vector dbc files |
# | printEnv | Used by scripts to determine project settings |
# | uVision | Run uVisionupdate.sh |
# | html | Build all html documentation under doc/ |
# | pdf | Build all pdf documentation under doc/ |
# | gh-pages | Assemble all docs for GitHub Pages publishing |
# | clean-build | Remove build output |
# | clean-doc | Remove doxygen output |
# | clean | Clean everything |
#
# Override the following settings in Makefile.local if needed.
#
# | Assignment | Function |
# |-----------------|---------------------------------------------------|
# | AWK | The awk interpreter |
# | BUILDDIR | SDCC output directory |
# | CC | Compiler |
# | CFLAGS | Compiler flags |
# | CPP | C preprocesser used by several scripts |
# | CONFDIR | Location for the library configuration files |
# | LIBPROJDIR | Path to the library project |
# | CANPROJDIR | Path to the CAN project |
# | DBCDIR | Location for generated DBC headers |
# | DOC_ALL_TARGETS | All doc/ subtargets (ecu, dbc) |
# | DOC_PUB_TARGETS | All gh-pages/ subtargets (ecu) |
# | GENDIR | Location for generated code |
# | INCDIR | Include directory for contributed headers |
# | LIBDIR | Path to the library sources |
# | OBJSUFX | The file name suffix for object files |
# | HEXSUFX | The file name suffix for intel hex files |
# | DATE | System date, for use when hg is not available |
# | VERSION | Version of the project |
# | SRC | The list of source files from this project |
# | PROJECT | The name of this project |
#
# Locate related projects.
LIBPROJDIR= hsk-libs
# Include shared defaults
include ${LIBPROJDIR}/Makefile.include
# Build with SDCC.
CFLAGS+= -I${LIBDIR}
# Library project configuration files.
CONFDIR:= ${LIBPROJDIR}/${CONFDIR}
# Include directories from the related projects.
INCDIR:= ${LIBPROJDIR}/${INCDIR}
LIBDIR= ${LIBPROJDIR}/src
# Documentation subtargets
DOC_ALL_TARGETS=ecu dbc
# Documenation to publish on GitHub Pages
DOC_PUB_TARGETS=ecu
# List of source files for generating dependencies documentation.
SRC:= $(shell find src/ -name \*.\[hc] -o -name \*.txt)
SRC!= find src/ -name \*.\[hc] -o -name \*.txt
#
# No more overrides.
#
# Local config
_LOCAL_MK:= $(shell test -f Makefile.local || touch Makefile.local)
_LOCAL_MK!= test -f Makefile.local || touch Makefile.local ; echo
# Gmake style, works with FreeBSD make, too
include Makefile.local
build:
.PHONY: ${GENDIR}/sdcc.mk ${GENDIR}/dbc.mk ${GENDIR}/build.mk
# Create the generated content directory
${GENDIR}:
@mkdir -p ${GENDIR}
# Configure SDCC
${GENDIR}/sdcc.mk: ${GENDIR}
@env CC="${CC}" sh ${LIBPROJDIR}/scripts/sdcc.sh ${CONFDIR}/sdcc > $@
# Generate dbc
${GENDIR}/dbc.mk: ${GENDIR}
@sh ${LIBPROJDIR}/scripts/dbc.sh ${CANPROJDIR}/ > $@
# Generate build
${GENDIR}/build.mk: dbc ${GENDIR}
@env CPP="${CPP}" \
${AWK} -f ${LIBPROJDIR}/scripts/build.awk \
-vOBJSUFX="${OBJSUFX}" -vBINSUFX="${HEXSUFX}" \
src/ ${LIBDIR}/ -DSDCC -I${INCDIR}/ -I${LIBDIR}/ \
-I${GENDIR}/ > $@
.PHONY: build all dbc
# Generate headers from CANdbs
dbc: ${GENDIR}/dbc.mk
@${MAKE} DBCDIR=${DBCDIR} -f ${GENDIR}/dbc.mk $@
${DBCDIR}: dbc
# Perform build stage
build all: ${GENDIR}/sdcc.mk ${GENDIR}/build.mk dbc
@env CC="${CC}" CFLAGS="${CFLAGS}" OBJDIR="${BUILDDIR}/" \
${MAKE} -rf ${GENDIR}/sdcc.mk -f ${GENDIR}/build.mk $@
.PHONY: printEnv uVision µVision
printEnv:
@echo export PROJECT=\"${PROJECT}\"
@echo export LIBPROJDIR=\"${LIBPROJDIR}\"
@echo export CANPROJDIR=\"${CANPROJDIR}\"
@echo export GENDIR=\"${GENDIR}\"
@echo export INCDIR=\"${INCDIR}\"
@echo export LIBDIR=\"${LIBDIR}\"
@echo export CPP=\"${CPP}\"
@echo export AWK=\"${AWK}\"
uVision µVision:
@sh uVisionupdate.sh
# Documentation sources
doc/ecu: ${SRC} doxygen.conf
doc/dbc: ${DBCDIR} ${CONFDIR}/doxygen.dbc
# Doxygen targets
${DOC_ALL_TARGETS:C,^,doc/,}: ${CONFDIR}/doxygen.common
@rm -rf "${.TARGET}"
@mkdir -p "${.TARGET}"
@echo 'PROJECT_NAME="${PROJECT}"' >> "${.TARGET}"/.conf
@echo 'PROJECT_NUMBER=${VERSION}' >> "${.TARGET}"/.conf
@echo 'OUTPUT_DIRECTORY="${.TARGET}/"' >> "${.TARGET}"/.conf
@echo 'WARN_LOGFILE="${.TARGET}/warnings.log"' >> "${.TARGET}"/.conf
@cat ${CONFDIR}/doxygen.common ${.ALLSRC:[-2]} ${.TARGET}/.conf | \
doxygen -
# PDF targets
${DOC_ALL_TARGETS:C,^,doc/,:C,$$,/latex/refman.pdf,}: ${.TARGET:H:H}
@cd "${.TARGET:H}" && ${MAKE}
# GitHub Pages targets
${DOC_PUB_TARGETS:C,^,gh-pages/,}: doc/${.TARGET:T} doc/${.TARGET:T}/latex/refman.pdf
@rm -rf "${.TARGET}"
@cp -r "doc/${.TARGET:T}/html" "${.TARGET}"
@cp "${.ALLSRC:[-1]}" "${.TARGET}/${PROJECT}.pdf"
# Documentation meta targets
html: ${DOC_ALL_TARGETS:C,^,doc/,}
pdf: ${DOC_ALL_TARGETS:C,^,doc/,:C,$$,/latex/refman.pdf,}
gh-pages: ${DOC_PUB_TARGETS:C,^,gh-pages/,}
.PHONY: clean clean-doc clean-build
clean: clean-doc clean-build
clean-doc:
@rm -rf doc/*
clean-build:
@rm -rf ${BUILDDIR}/* ${GENDIR}/*