-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile.inc.old
609 lines (497 loc) · 16 KB
/
Makefile.inc.old
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
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
#############################################################################
#
# file: bmptk/Makefile.inc
#
# Makefile for bare metal C++ projects
#
# Copyright (c) 2012 ... 2014 Wouter van Ooijen ([email protected])
#
# Distributed under the Boost Software License, Version 1.0.
# (See accompanying file LICENSE_1_0.txt or copy at
# http://www.boost.org/LICENSE_1_0.txt)
#
#############################################################################
# This string must not contain spaces, that does
# (for some unclear reason) not work on Windows8
VERSION := V03.00_work_in_progress_2014_10_28
SHELL=C:/Windows/System32/cmd.exe
#============================================================================
#
# Invoke the Makefile.custom (if it exists) or else the Makefile.local,
# to get the locations of the external toolsets
#
#============================================================================
ifneq ($(wildcard $(BMPTK)/Makefile.custom),)
include $(BMPTK)/Makefile.custom
else
include $(BMPTK)/Makefile.local
endif
# for debugging
# $(error $(WPF) )
#============================================================================
#
# The main project source file is sure part of the project.
# It is specified with extension: here we find the a .asm, .c or .cpp file
#
# the default project name is 'main'
#
#============================================================================
ifeq ($(MAKECMDGOALS),clean)
NOPROJECT = 1
endif
ifeq ($(MAKECMDGOALS),doxygen)
NOPROJECT = 1
endif
ifeq ($(PROJECT),)
PROJECT = main
endif
ifeq ($(wildcard $(PROJECT).cpp),)
ifeq ($(wildcard $(PROJECT).c),)
ifeq ($(wildcard $(PROJECT).asm),)
ifneq ($(NOPROJECT),1)
$(error PROJECT ($(PROJECT)) is not a .cpp, .c or .asm file)
endif
else
SOURCES += $(PROJECT).asm
endif
else
SOURCES += $(PROJECT).c
endif
else
SOURCES += $(PROJECT).cpp
endif
#============================================================================
#
# decide whether we have a C++ project or a C/Assembler project
#
# When a project uses at least one C++ file it is a C++ project, and
# the C++ tools must be used for ALL files.
# If not, the C tools are used.
#
#============================================================================
SOURCES := $(strip $(SOURCES))
ifeq ($(patsubst %.cpp,,$(SOURCES)),$(SOURCES))
LANGUAGE := C
else
LANGUAGE := C++
endif
# $(error $(LANGUAGE) '$(SOURCES)' '$(patsubst %.cpp,,$(SOURCES))' )
#============================================================================
#
# find the files
#
#============================================================================
SEARCH += $(BMPTK)
SEARCH += $(BMPTK)/graphics
SEARCH += $(BMPTK)/targets
# INCLUDES += -I.
INCLUDES += $(foreach x, $(SEARCH), -I$(x))
bmptk.h:
# You specified an absolute path ($(BMPTK)) for the bmptk location.
# The 'make' tool you use has a bug in handling absolute paths that
# prevents the bmptk makefile from finding some source files.
# Two solutions are:
# 1) Use a make that does not have this bug.
# The gnu make available from www.gnu.org/software/make/ does
# not have this bug, nor does the cs-make that is part of the
# CodesSourcery distribution.
# 2) Use a relative path to specify the bmptk location.
# This almost forces you to locate your project inside the bmptk
# tree, (a subdirectory of) the examples directory is a
# reasonable choice.
#============================================================================
#
# default port, baudrate, xtal for download and debug log
#
#============================================================================
SERIAL_PORT := COM4
SERIAL_BAUDRATE := 38400
XTAL := 12000
#============================================================================
#
# tool executables
#
#============================================================================
CC = "$(PREFIX)gcc"
CPP = "$(PREFIX)g++"
AS = "$(PREFIX)gcc"
OBJCOPY = "$(PREFIX)objcopy"
OBJDUMP = "$(PREFIX)objdump"
SIZES = "$(PREFIX)size"
NM = "$(PREFIX)nm"
ifeq ($(LANGUAGE),C)
LINKER = "$(PREFIX)gcc"
else
LINKER = "$(PREFIX)g++"
endif
NDSTOOL := "$(DEVKITPRO)/devkitARM/bin/ndstool"
ifeq ($(OS),Windows_NT)
RM := "$(BMPTK)/tools/cs-rm" -rf
else
RM := /bin/rm -f
endif
#============================================================================
#
# Intermediate and result files
#
#============================================================================
BIN := $(PROJECT).bin
ELF := $(PROJECT).elf
MAP := $(PROJECT).map
HEX := $(PROJECT).hex
DMP := $(PROJECT).dmp
LSS := $(PROJECT).lss
NDS := $(PROJECT).nds
EXE := $(PROJECT).exe
NMDUMP := $(PROJECT).nmdump
OBJ += $(OBJECTS)
SOURCESX := $(patsubst %.asm,%.o,$(patsubst %.S,%.o,$(SOURCES)))
OBJ += $(patsubst %.c,%.o,$(patsubst %.cpp,%.o,$(SOURCESX)))
OBJ += $(patsubst %,%.o,$(LIBRARIES))
LST += $(patsubst %.o,%.lst,$(OBJ))
#============================================================================
#
# boards
#
#============================================================================
# the target can be either a chip, or a board
ifeq ($(TARGET),)
TARGET = $(CHIP)
else
ifeq ($(CHIP),)
CHIP = $(TARGET)
endif
endif
ifeq ($(TARGET),db103)
CHIP := lpc1114fn28
endif
ifeq ($(TARGET),db104)
CHIP := lpc1114fn28
endif
#============================================================================
#
# target-specific parts
#
#============================================================================
# will remain empty when no valid target is found
PREFIX :=
define Hosted
HOSTED = 1
HAS_FILESYSTEM = 1
endef
HAS_FILESYSTEM = 0
ifeq ($(TARGET),nds)
$(eval $(Hosted))
CHIP := ARMv7
PREFIX := $(DEVKITPRO)/devkitARM/bin/arm-none-eabi-
CORE_FLAGS := -march=armv5te -mtune=arm946e-s -fomit-frame-pointer
CORE_FLAGS += -ffast-math -mthumb -mthumb-interwork -DARM9
INCLUDES += -I$(DEVKITPRO)/ -I$(DEVKITPRO)/libnds/include
LIBS += -L$(DEVKITPRO)/libnds/lib -lnds9
LDFLAGS += -g -mthumb -mthumb-interwork -specs=ds_arm9.specs
RESULTS = $(ELF) $(NDS) $(NMDUMP)
RUN = "$(DEVKITPRO)/emulators/desmume/DeSmuME" $(NDS)
LIBS += nds
SEARCH += $(BMPTK)/stdlib $(BMPTK)/targets/nds
INCLUDES += -I$(BMPTK)/stdlib -I$(BMPTK)/targets/nds
TICKS_PER_US = 67
LINKERSCRIPT =
endif
ifeq ($(TARGET),win)
$(eval $(Hosted))
CHIP := Intel
PREFIX := $(MINGW)/bin/
export PATH := $PREFIX:$(PATH)
# CPP = "$(PREFIX)c++"
CORE_FLAGS := -mno-ms-bitfields
# INCLUDES += -I"$(DEVCPPLIB)/lib/gcc/mingw32/3.4.2/include"
# INCLUDES += -I"$(DEVCPP)/include/c++/3.4.2/backward"
# INCLUDES += -I"$(DEVCPP)/lib/gcc/mingw32"
# INCLUDES += -I"$(DEVCPP)/include/c++/3.4.2"
# INCLUDES += -I"$(DEVCPP)/include"
# LIBS += -L"$(DEVCPP)/lib"
# LDFLAGS += -lgdi32 -lcomdlg32 -luuid -loleaut32 -lole32
LDFLAGS += -lgdi32
RESULTS = $(EXE)
RUN = ./$(EXE)
LIBRARIES += win
SEARCH += $(BMPTK)/targets/win
# INCLUDES += -I$(BMPTK)/targets/win
# INCLUDES += -I $(BMPTK)
LINKERSCRIPT =
endif
define Embedded
EMBEDDED = 1
CORE_FLAGS += -nostartfiles
PREFIX := $(GNU-ARM)/bin/arm-none-eabi-
RESULTS += $(NMDUMP) sizes
endef
define Cortex
$(eval $(Embedded))
INCLUDES += -I$(BMPTK)/targets/cortex/cmsis
XTAL := 12000000
SOURCES += cortex_startup.c
RESULTS += $(ELF) $(BIN) $(MAP) $(HEX) $(DMP) $(LSS) $(NMDUMP)
FMCMD = COM($(patsubst COM%,%,$(SERIAL_PORT)),$(SERIAL_BAUDRATE))
FMCMD += DEVICE($(FNAME), 12000000, 0)
FMCMD += HARDWARE(BOOTEXEC, 50, 100)
FMCMD += ERASE(DEVICE, PROTECTISP)
FMCMD += HEXFILE($(HEX), NOCHECKSUMS, NOFILL, PROTECTISP)
RUN = $(LPC21ISP) -control -verify -term $(HEX) $(SERIAL_PORT) $(SERIAL_BAUDRATE) 12000
# TERMINAL = lpc21isp -termonly x $(SERIAL_PORT) 19200 y
# RUN = $(FLASHMAGIC) '$(FMCMD)'
LINKERSCRIPT = linkerscript.ld
LDFLAGS += -T linkerscript.ld -nostartfiles
DEFINES += -DBMPTK_EMBEDDED -DBMPTK_EMBEDDED_HEAP -DBMPTK_EMBEDDED_IOSTREAM
RESULTS += linkerscript.ld
OBJ += cortex_startup.o cortex.o
endef
define Cortex-M0
$(eval $(Cortex))
CORE_FLAGS += -mcpu=cortex-m0 -mthumb -fomit-frame-pointer -march=armv6-m
SEARCH += $(BMPTK)/targets/cortex
INCLUDES += -I$(BMPTK)/targets/cortex
LD_CONFIG = -DROM_START=0 -DRAM_START=0x10000000
endef
define LPC81X
$(eval $(Cortex-M0))
INCLUDES += -I$(BMPTK)/targets/cortex/cmsis/lpc800/inc
endef
ifeq ($(CHIP),lpc810m021fn8)
$(eval $(LPC81X))
FNAME = LPC810M021FN8
STACKSIZE ?= 256
LD_CONFIG += -DROM_SIZE=8k -DRAM_SIZE=1k
endif
ifeq ($(CHIP),lpc812m101)
$(eval $(LPC81X))
FNAME = LPC810M021FN8
STACKSIZE ?= 1k
LD_CONFIG += -DROM_SIZE=16k -DRAM_SIZE=4k
endif
define LPC1114
$(eval $(Cortex-M0))
INCLUDES += -I$(BMPTK)/targets/cortex/cmsis/11xx/inc
endef
ifeq ($(CHIP),lpc1114fn28)
$(eval $(LPC1114))
FNAME = LPC1114/102
STACKSIZE ?= 2k
LD_CONFIG += -DROM_SIZE=32k -DRAM_SIZE=4k
HWCPP += lpc1114.hpp lpc1114fn28.hpp
endif
define LPC1227
$(eval $(Cortex-M0))
INCLUDES += -I$(BMPTK)/targets/cortex/cmsis/12xx/inc
SOURCES += lpc1227.cpp
endef
ifeq ($(CHIP),lpc1227fbd301)
$(eval $(LPC1227))
FNAME = LPC1227/301
STACK_SIZE ?= 2k
LD_CONFIG += -DROM_SIZE=96k -DRAM_SIZE=8k
endif
ifneq ($(NOPROJECT),1)
ifeq ($(PREFIX),)
$(error invalid or no target specified: "$(TARGET)")
endif
endif
LD_CONFIG += -DSTACK_SIZE=$(STACKSIZE)
#============================================================================
#
# hwcpp
#
#============================================================================
HWCPP += hwcpp.hpp
HWCPP += basics.hpp timing.hpp
HWCPP += string.hpp
HWCPP += numeric.hpp
HWCPP += pins.hpp channels.hpp
HWCPP += i2c.hpp spi.hpp one_wire.hpp
HWCPP += hc595.hpp pcf8574.hpp mcp23xxx.hpp pcf8591.hpp
HWCPP += hd44780.hpp
# HWCPP += graphics.hpp
HWCPP += pcd8544.hpp lcd_19.hpp
HWCPP += ds18x20.hpp
HWCPP += ads7843.hpp
ifeq ($(LANGUAGE),C++)
HWCPPDIRS = hwcpp hwcpp/core hwcpp/targets hwcpp/chips
#$INCLUDES += $(foreach x, $(HWCPPDIRS), -I$(BMPTK)/$(x))
SEARCH += $(foreach x, $(HWCPPDIRS), $(BMPTK)/$(x))
HEADERS += $(HWCPP)
endif
#============================================================================
#
# Pass information to the code
#
#============================================================================
DEFINES += -DBMPTK_TARGET=$(TARGET)
DEFINES += -DBMPTK_TARGET_$(TARGET)
DEFINES += -DBMPTK_CHIP=$(CHIP)
DEFINES += -DBMPTK_CHIP_$(CHIP)
DEFINES += -DBMPTK_XTAL=$(XTAL)
DEFINES += -DBMPTK_BAUDRATE=$(SERIAL_BAUDRATE)
DEFINES += -DBMPTK_VERSION=$(VERSION)
ifeq ($(HOSTED),1)
DEFINES += -DBMPTK_HOSTED
endif
ifeq ($(EMBEDDED),1)
DEFINES += -DBMPTK_EMBEDDED
endif
ifeq ($(HAS_FILESYSTEM),1)
DEFINES += -DBMPTK_HAS_FILESYSTEM
endif
#============================================================================
#
# the default font, required by bmptk_graphics
#
# The 04B_03__.ttf file (listed as freeware) was downloaded from
# http://www.eaglefonts.com/04b03-ttf-131597.htm
#
#============================================================================
FONT-DEFAULT := $(BMPTK)/graphics/fonts/04B_03__.TTF
ifeq (bmptk_graphics,$(filter bmptk_graphics,$(LIBS)))
LIBRARIES += font_default
endif
#============================================================================
#
# Dependencies
#
#============================================================================
HEADERS += $(patsubst %,%.h,$(LIBRARIES))
# Assume all sources depend on all headers, the linkerscript, and the Makefile
DEPEND := $(HEADERS) $(LNK) Makefile
$(OBJ): $(DEPEND)
#============================================================================
#
# tool options
#
#============================================================================
# show all warnings, treat most as errors
CORE_FLAGS += -Wall -Werror
CORE_FLAGS += -Wno-unused-local-typedefs
CORE_FLAGS += -Wno-maybe-uninitialized
# use sections to save space
CORE_FLAGS += -fdata-sections -ffunction-sections
# optimize for space
CORE_FLAGS += -Os
# cpp: don't use features that are too expensive
CORE_CPP_FLAGS += -fno-rtti -fno-exceptions
CORE_CPP_FLAGS += -fno-threadsafe-statics -fno-use-cxa-get-exception-ptr
# cpp: use latest language standard
CORE_CPP_FLAGS += -std=c++11
# assembler: enable the preprocessor
CORE_AS_FLAGS += -x assembler-with-cpp
# linker specific
LDFLAGS += -Wl,-Map,$(MAP)
LDFLAGS += -Wl,--gc-sections
COMMON := $(CORE_FLAGS) $(INCLUDES) $(DEFINES)
CPPFLAGS += $(COMMON) $(CORE_CPP_FLAGS)
CFLAGS += $(COMMON) $(CORE_CC_FLAGS)
ASFLAGS += $(COMMON) $(CORE_AS_FLAGS)
LDFLAGS += $(COMMON) $(CORE_LD_FLAGS)
#============================================================================
#
# how to make things
#
#============================================================================
# find non-local source files
# VPATH is not used, beacause it would also 'find' .ld and .o files,
# which should be created locally
vpath %.h $(SEARCH)
vpath %.hpp $(SEARCH)
vpath %.c $(SEARCH)
vpath %.asm $(SEARCH)
vpath %.cpp $(SEARCH)
# use only the explcit rules below
.SUFFIXES:
# How to make object files?
%.o: %.cpp
@echo 'Compiling C++ file: $<'
$(CPP) $(CPPFLAGS) -c -o $@ $<
$(CPP) $(CPPFLAGS) -c -S -o $(patsubst %.o,%.lst,$@) $<
@echo ' '
%.o: %.c
@echo 'Compiling C file: $<'
$(CC) $(CFLAGS) -c -o $@ $<
$(CC) $(CFLAGS) -c -S -o $(patsubst %.o,%.lst,$@) $<
@echo ' '
%.o: %.S
@echo 'Assembling file: $<'
$(AS) $(ASFLAGS) -c -o $@ $<
@echo ' '
%.o: %.asm
@echo 'Assembling file: $<'
$(AS) $(ASFLAGS) -c -o $@ $<
@echo ' '
# How to make a listing from a cpp file
%.list: %.cpp
$(CPP) $(CPPFLAGS) -c -S -o $@ $<
# make the linkerscipt
linkerscript.ld: $(BMPTK)/targets/cortex/linkerscript.c
@echo 'Creating the linkerscript'
$(CC) $(LD_CONFIG) -E -P -C $(BMPTK)/targets/cortex/linkerscript.c -o $@
@echo ' '
# make .elf by linking all objects
# $(error $(addprefix ./,$(OBJ) ) )
$(ELF): $(addprefix ./,$(OBJ)) $(LIBA) $(LNK) ./$(LINKERSCRIPT)
@echo 'Linking target: $(ELF)'
$(LINKER) -Wl,-fatal-warnings -o $@ $(OBJ) $(LIBA) $(LDFLAGS) $(LIBS)
@echo ' '
# make .exe by linking all objects
$(EXE): $(OBJ) $(LNK)
@echo 'Linking target: $(EXE)'
$(LINKER) -o $@ $(OBJ) $(LDFLAGS) $(LIBS)
@echo ' '
# make sizes listing from the elf file
$(NMDUMP): $(ELF)
$(NM) -S --size-sort --radix=d $(ELF) >$(NMDUMP)
# make .bin from .elf
$(BIN): $(ELF)
$(OBJCOPY) -O binary $< $@
# make .hex from .elf
$(HEX): $(ELF)
$(OBJCOPY) --output-target ihex $< $@
# make .dmp from elf
$(DMP): $(ELF)
$(OBJDUMP) -x --syms $< > $@
# make .lss from elf
$(LSS): $(ELF)
$(OBJDUMP) -S $< > $@
# make .nds from .elf
$(NDS): $(ELF)
$(NDSTOOL) -c $@ -9 $< -b $(DEVKITPRO)/libnds/icon.bmp "$(PROJECT)"
# show object sizes
.PHONY: sizes
sizes: $(OBJ)
$(SIZES) -B -t $(OBJ)
"$(BMPTK)/tools/image_sizes/image_sizes.exe" $(MAP)
#============================================================================
#
# targets
#
#============================================================================
.PHONY: $(PROJECT) all build new fresh run clean doxygen
.DEFAULT_GOAL := build
# Build the project
$(PROJECT): $(RESULTS)
# aliases for build the project
all: $(PROJECT)
build: $(PROJECT)
# aliases for clean+build
new: clean build
fresh: clean build
# Run (= download and start) the project
run: $(PROJECT)
$(RUN)
$(TERMINAL)
doxygen: doxyfile
Doxygen
# Cleanup
CLEAN += $(RESULTS)
CLEAN += $(OBJ)
CLEAN += $(MAP)
CLEAN += $(LST)
CLEAN += doxydocs
clean:
$(RM) $(CLEAN)