forked from AnthonyWaithaka/twr_k60n512
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile~
115 lines (93 loc) · 3.15 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
#
# File: Makefile
#
# Copyright (c) 2013, 0xc0170
#
# This program is free software. It comes without any warranty, to
# the extent permitted by applicable law. You can redistribute it
# and/or modify it under the terms of the Do What The Fuck You Want
# To Public License, Version 2, as published by Sam Hocevar. See
# http://www.wtfpl.net/ for more details.
# toolchain specific
TOOLCHAIN = /usr/local/gcc-arm-none-eabi-4_8-2014q2/bin/arm-none-eabi-
CC = $(TOOLCHAIN)gcc
CXX = $(TOOLCHAIN)g++
AS = $(TOOLCHAIN)gcc -x assembler-with-cpp
LD = $(TOOLCHAIN)gcc
OBJCP = $(TOOLCHAIN)objcopy
AR = $(TOOLCHAIN)ar
# application specific
CPU := cortex-m4
INSTRUCTION_MODE := thumb
TARGET := k60_gpio_demo
TARGET_EXT := elf
LD_SCRIPT := k60n512_flash.ld
LIBS :=
# directories
INC_DIRS = . common cpu cpu/headers
SRC_DIRS := . cpu
OUT_DIR := out
INC_DIRS_F = -I. $(patsubst %, -I%, $(INC_DIRS))
# add traling / if not empty
ifeq ($(strip $(OUT_DIR)), )
OBJ_FOLDER =
else
OBJ_FOLDER = $(strip $(OUT_DIR))/
endif
COMPILER_OPTIONS = -O0 -g -ggdb -Wall -fno-strict-aliasing \
-fmessage-length=0 -fno-builtin -m$(INSTRUCTION_MODE) \
-mcpu=$(CPU) -MD -MP
DEPEND_OPTS = -MF $(OBJ_FOLDER)$(@F:.o=.d)
# Flags
CFLAGS = $(COMPILER_OPTIONS) $(DEPEND_OPTS) $(INC_DIRS_F) -c
CXXFLAGS = $(COMPILER_OPTIONS) $(INC_DIRS_F) -c
ASFLAGS = $(COMPILER_OPTIONS) $(INC_DIRS_F) -c
OBJCPFLAGS = -O ihex
ARFLAGS = cr
# Linker options
LD_OPTIONS = -Wl,-Map=$(OBJ_FOLDER)$(TARGET).map $(COMPILER_OPTIONS) -L ../ -T $(LD_SCRIPT) $(INC_DIRS_F)
LD_OPTIONS += -nostartfiles
RM := rm -rf
USER_OBJS :=
C_SRCS :=
S_SRCS :=
C_OBJS :=
S_OBJS :=
# All source/object files inside SRC_DIRS
C_SRCS := $(foreach dir,$(SRC_DIRS),$(wildcard $(dir)/*.c))
C_OBJS := $(patsubst %.c,$(OBJ_FOLDER)%.o,$(notdir $(C_SRCS)))
S_SRCS := $(foreach dir,$(SRC_DIRS),$(wildcard $(dir)/*.s))
S_OBJS := $(patsubst %.c,$(OBJ_FOLDER)%.o,$(notdir $(S_SRCS)))
VPATH := $(SRC_DIRS)
$(OBJ_FOLDER)%.o : %.c
@echo ‘Building file: $(@F)’
@echo ‘Invoking: MCU C Compiler’
$(CC) $(CFLAGS) $< -o $@
@echo 'Finished building: $(@F)'
@echo ' '
$(OBJ_FOLDER)%.o : %.s
@echo 'Building file: $(@F)'
@echo 'Invoking: MCU Assembler'
$(AS) $(ASFLAGS) $< -o $@
@echo 'Finished building: $(@F)'
@echo ' '
all: create_outputdir $(OBJ_FOLDER)$(TARGET).$(TARGET_EXT) print_size
create_outputdir:
$(shell mkdir $(OBJ_FOLDER) 2>/dev/null)
# Tool invocations
$(OBJ_FOLDER)$(TARGET).$(TARGET_EXT): $(C_OBJS) $(S_OBJS)
@echo 'Building target: $@'
@echo 'Invoking: MCU Linker'
$(LD) $(LD_OPTIONS) $(C_OBJS) $(S_OBJS) $(USER_OBJS) $(LIBS) -o $(OBJ_FOLDER)$(TARGET).$(TARGET_EXT)
@echo 'Finished building target: $@'
@echo ' '
# Other Targets
clean:
@echo 'Removing entire out directory'
$(RM) $(TARGET).$(TARGET_EXT) $(TARGET).bin $(TARGET).map $(OBJ_FOLDER)*.* $(OBJ_FOLDER)
@echo ' '
print_size:
@echo 'Printing size'
arm-none-eabi-size --totals $(OBJ_FOLDER)$(TARGET).$(TARGET_EXT); arm-none-eabi-objcopy -O binary $(OBJ_FOLDER)$(TARGET).$(TARGET_EXT) $(OBJ_FOLDER)$(TARGET).bin ;
@echo ' '
.PHONY: all clean dependents print_size