Quantum Leaps eed870ce9d 5.2.0
2013-12-30 17:37:40 -05:00

247 lines
6.5 KiB
Makefile

##############################################################################
# Product: Makefile for LPCXpresso-1343, QK kernel, GNU/CodeRed
# Last Updated for Version: 5.0.0
# Date of the Last Update: Sep 08, 2013
#
# Q u a n t u m L e a P s
# ---------------------------
# innovating embedded systems
#
# Copyright (C) 2002-2013 Quantum Leaps, LLC. All rights reserved.
#
# This program is open source software: you can redistribute it and/or
# modify it under the terms of the GNU General Public License as published
# by the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Alternatively, this program may be distributed and modified under the
# terms of Quantum Leaps commercial licenses, which expressly supersede
# the GNU General Public License and are specifically designed for
# licensees interested in retaining the proprietary status of their code.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
# Contact information:
# Quantum Leaps Web sites: http://www.quantum-leaps.com
# http://www.state-machine.com
# e-mail: info@quantum-leaps.com
##############################################################################
# examples of invoking this Makefile:
# building configurations: Debug (default), Release, and Spy
# make
# make CONF=rel
# make CONF=spy
#
# cleaning configurations: Debug (default), Release, and Spy
# make clean
# make CONF=rel clean
# make CONF=spy clean
PROJECT := dpp-qk
#-----------------------------------------------------------------------------
# GNU ARM compiler
#
ifeq ($(GNU_ARM),)
GNU_ARM = C:/tools/CodeRed/lpcxpresso/Tools
endif
CC := $(GNU_ARM)/bin/arm-none-eabi-gcc
CPP := $(GNU_ARM)/bin/arm-none-eabi-g++
AS := $(GNU_ARM)/bin/arm-none-eabi-as
LINK := $(GNU_ARM)/bin/arm-none-eabi-gcc
BIN := $(GNU_ARM)/bin/arm-none-eabi-objcopy
RM := rm -rf
MKDIR := mkdir
RM := rm
#-----------------------------------------------------------------------------
# NOTE: the Makefile expects that the QPC environment variable is defined
# and points to the QP/C installation directory
#
ifndef QPC
$(error The QPC environment variable must be defined)
endif
#-----------------------------------------------------------------------------
# directories
#
QP_PORT_DIR := $(QPC)/ports/arm-cm/qk/gnu
CMSIS_DIR := $(QPC)/ports/arm-cm/cmsis
APP_DIR := .
# source directories
VPATH = $(APP_DIR) \
$(CMSIS_DIR) \
lpc13xx_lib/src
# Output file basename
OUTPUT := $(PROJECT)
# include directories
INCLUDES = -I"$(QPC)"/include \
-I$(QP_PORT_DIR) \
-I. \
-I$(CMSIS_DIR) \
-Ilpc13xx_lib/inc
# defines
DEFINES = -D__REDLIB__
ARM_CORE = cortex-m3
#-----------------------------------------------------------------------------
# files
#
# assembler source files
ASM_SRCS :=
# C source files
C_SRCS := $(wildcard *.c) \
clkconfig.c \
gpio.c \
timer16.c \
timer32.c \
uart.c
# C++ source files
CPP_SRCS := $(wildcard *.cpp)
LD_SCRIPT := lpc1343.ld
LIBS := -lqp_$(ARM_CORE)_cr
#-----------------------------------------------------------------------------
# build options for various configurations
#
ifeq (rel, $(CONF)) # Release configuration ............................
BIN_DIR := rel
ASFLAGS = -mcpu=$(ARM_CORE)
CFLAGS = -mcpu=$(ARM_CORE) -mthumb -Wall \
-Os $(INCLUDES) $(DEFINES) -DNDEBUG
CPPFLAGS = -mcpu=$(ARM_CORE) -mthumb \
-Wall -fno-rtti -fno-exceptions \
-Os $(INCLUDES) $(DEFINES) -DNDEBUG
LINKFLAGS = -T$(LD_SCRIPT) -mcpu=$(ARM_CORE) -mthumb -nostdlib -Xlinker \
-Map=$(BIN_DIR)/$(OUTPUT).map \
-L$(QP_PORT_DIR)/$(BIN_DIR)
else ifeq (spy, $(CONF)) # Spy configuration ................................
BIN_DIR := spy
ASFLAGS = -g -mcpu=$(ARM_CORE)
CFLAGS = -mcpu=$(ARM_CORE) -mthumb -Wall \
-g -O $(INCLUDES) $(DEFINES) -DQ_SPY
CPPFLAGS = -mcpu=$(ARM_CORE) -mthumb -Wall \
-fno-rtti -fno-exceptions \
-g -O $(INCLUDES) $(DEFINES) -DQ_SPY
LINKFLAGS = -T$(LD_SCRIPT) -mcpu=$(ARM_CORE) -mthumb -nostdlib -Xlinker \
-Map=$(BIN_DIR)/$(OUTPUT).map \
-L$(QP_PORT_DIR)/$(BIN_DIR)
else # default Debug configuration .......................
BIN_DIR := dbg
ASFLAGS = -g -mcpu=$(ARM_CORE)
CFLAGS = -mcpu=$(ARM_CORE) -mthumb -Wall \
-g -O $(INCLUDES) $(DEFINES)
CPPFLAGS = -mcpu=$(ARM_CORE) -mthumb \
-Wall -fno-rtti -fno-exceptions \
-g -O $(INCLUDES) $(DEFINES)
LINKFLAGS = -T$(LD_SCRIPT) -mcpu=$(ARM_CORE) -mthumb -nostdlib -Xlinker \
-Map=$(BIN_DIR)/$(OUTPUT).map \
-L$(QP_PORT_DIR)/$(BIN_DIR)
endif
ASM_OBJS := $(patsubst %.s,%.o,$(ASM_SRCS))
C_OBJS := $(patsubst %.c,%.o,$(C_SRCS))
CPP_OBJS := $(patsubst %.cpp,%.o,$(CPP_SRCS))
TARGET_BIN := $(BIN_DIR)/$(OUTPUT).bin
TARGET_ELF := $(BIN_DIR)/$(OUTPUT).elf
ASM_OBJS_EXT := $(addprefix $(BIN_DIR)/, $(ASM_OBJS))
C_OBJS_EXT := $(addprefix $(BIN_DIR)/, $(C_OBJS))
C_DEPS_EXT := $(patsubst %.o, %.d, $(C_OBJS_EXT))
CPP_OBJS_EXT := $(addprefix $(BIN_DIR)/, $(CPP_OBJS))
CPP_DEPS_EXT := $(patsubst %.o, %.d, $(CPP_OBJS_EXT))
#-----------------------------------------------------------------------------
# rules
#
all: $(BIN_DIR) $(TARGET_BIN)
$(BIN_DIR):
@echo
mkdir -p $@
$(TARGET_BIN): $(TARGET_ELF)
$(BIN) -O binary $< $@
$(TARGET_ELF) : $(ASM_OBJS_EXT) $(C_OBJS_EXT) $(CPP_OBJS_EXT)
$(LINK) $(LINKFLAGS) -o $@ $^ $(LIBS)
$(BIN_DIR)/%.d : %.c
$(CC) -MM -MT $(@:.d=.o) $(CFLAGS) $< > $@
$(BIN_DIR)/%.d : %.cpp
$(CPP) -MM -MT $(@:.d=.o) $(CPPFLAGS) $< > $@
$(BIN_DIR)/%.o : %.s
$(AS) $(ASFLAGS) $< -o $@
$(BIN_DIR)/%.o : %.c
$(CC) $(CFLAGS) -c $< -o $@
$(BIN_DIR)/%.o : %.cpp
$(CPP) $(CPPFLAGS) -c $< -o $@
# include dependency files only if our goal depends on their existence
ifneq ($(MAKECMDGOALS),clean)
ifneq ($(MAKECMDGOALS),show)
-include $(C_DEPS_EXT) $(CPP_DEPS_EXT)
endif
endif
.PHONY : clean
clean:
-$(RM) $(BIN_DIR)/*.o \
$(BIN_DIR)/*.d \
$(BIN_DIR)/*.bin \
$(BIN_DIR)/*.elf \
$(BIN_DIR)/*.map
show:
@echo CONF = $(CONF)
@echo ASM_SRCS = $(ASM_SRCS)
@echo C_SRCS = $(C_SRCS)
@echo CPP_SRCS = $(CPP_SRCS)
@echo ASM_OBJS_EXT = $(ASM_OBJS_EXT)
@echo C_OBJS_EXT = $(C_OBJS_EXT)
@echo C_DEPS_EXT = $(C_DEPS_EXT)
@echo CPP_DEPS_EXT = $(CPP_DEPS_EXT)
@echo TARGET_ELF = $(TARGET_ELF)