207 lines
5.7 KiB
Makefile
Raw Normal View History

2012-08-14 18:07:04 -04:00
##############################################################################
2013-12-30 17:37:40 -05:00
# Product: Generic Makefile for QP/C application, Win32, MinGW compiler
2014-04-06 11:43:13 -04:00
# Last updated for version 5.3.0
# Last updated on 2014-03-25
2012-08-14 18:07:04 -04:00
#
# Q u a n t u m L e a P s
# ---------------------------
# innovating embedded systems
#
2014-04-06 11:43:13 -04:00
# Copyright (C) Quantum Leaps, www.state-machine.com.
2012-08-14 18:07:04 -04:00
#
# 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
2012-08-14 18:07:04 -04:00
# (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:
2014-04-06 11:43:13 -04:00
# Web: www.state-machine.com
# Email: info@state-machine.com
2012-08-14 18:07:04 -04:00
##############################################################################
# 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
2013-12-30 17:37:40 -05:00
##############################################################################
#
# NOTE: Typically, you should have no need to change anything in this Makefile
#
##############################################################################
2012-08-14 18:07:04 -04:00
#-----------------------------------------------------------------------------
# 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
#-----------------------------------------------------------------------------
# NOTE: this Makefile assumes that the MinGW\bin directory is added
# to the PATH variable.
#
CC := gcc
CPP := g++
LINK := gcc # for C programs
#LINK := g++ # for C++ programs
2013-12-30 17:37:40 -05:00
RM := rm
2012-08-14 18:07:04 -04:00
#-----------------------------------------------------------------------------
# directories
#
2013-12-30 17:37:40 -05:00
# Project name is derived from the directory name
PROJECT := $(notdir $(CURDIR))
QP_PORT_DIR := $(QPC)/ports/win32
2012-08-14 18:07:04 -04:00
APP_DIR := .
VPATH = $(APP_DIR)
# include directories
2013-12-30 17:37:40 -05:00
INCLUDES = -I. \
-I$(QPC)/include \
-I$(QP_PORT_DIR)
2012-08-14 18:07:04 -04:00
# defines
DEFINES =
2013-12-30 17:37:40 -05:00
LINKFLAGS = -Wl,-Map,$(BIN_DIR)/$(PROJECT).map
2012-08-14 18:07:04 -04:00
#-----------------------------------------------------------------------------
# files
#
# C source files
C_SRCS := $(wildcard *.c)
# C++ source files
CPP_SRCS := $(wildcard *.cpp)
LD_SCRIPT :=
#-----------------------------------------------------------------------------
# build options for various configurations
#
ifeq (rel, $(CONF)) # Release configuration ............................
BIN_DIR := rel
CFLAGS = -c -Wall -O2 $(INCLUDES) $(DEFINES) -DNDEBUG
CPPFLAGS = -c -Wall -O2 $(INCLUDES) $(DEFINES) -DNDEBUG
2013-12-30 17:37:40 -05:00
LINKFLAGS = -L$(QP_PORT_DIR)/mingw/$(BIN_DIR)
2012-08-14 18:07:04 -04:00
else ifeq (spy, $(CONF)) # Spy configuration ................................
BIN_DIR := spy
2013-12-30 17:37:40 -05:00
INCLUDES += -I$(QTOOLS)/qspy/include
VPATH += $(QTOOLS)/qspy/source
C_SRCS += qspy.c
2012-08-14 18:07:04 -04:00
CFLAGS = -c -Wall -g $(INCLUDES) $(DEFINES) -DQ_SPY
CPPFLAGS = -c -Wall -g $(INCLUDES) $(DEFINES) -DQ_SPY
else # default Debug configuration .......................
BIN_DIR := dbg
CFLAGS = -c -Wall -g $(INCLUDES) $(DEFINES)
CPPFLAGS = -c -Wall -g $(INCLUDES) $(DEFINES)
endif
2013-12-30 17:37:40 -05:00
LINKFLAGS = -L$(QP_PORT_DIR)/mingw/$(BIN_DIR) -Wl,-Map,$(BIN_DIR)/$(PROJECT).map
#-----------------------------------------------------------------------------
2012-08-14 18:07:04 -04:00
C_OBJS := $(patsubst %.c,%.o,$(C_SRCS))
CPP_OBJS := $(patsubst %.cpp,%.o,$(CPP_SRCS))
2013-12-30 17:37:40 -05:00
TARGET_BIN := $(BIN_DIR)/$(PROJECT).bin
TARGET_EXE := $(BIN_DIR)/$(PROJECT).exe
2012-08-14 18:07:04 -04:00
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_EXE)
#all: $(BIN_DIR) $(TARGET_BIN)
$(BIN_DIR):
@echo
2013-12-30 17:37:40 -05:00
mkdir $@
2012-08-14 18:07:04 -04:00
$(TARGET_BIN): $(TARGET_EXE)
$(BIN) -O binary $< $@
2013-12-30 17:37:40 -05:00
$(TARGET_EXE) : $(C_OBJS_EXT) $(CPP_OBJS_EXT)
2012-08-14 18:07:04 -04:00
$(LINK) $(LINKFLAGS) -o $@ $^ -lqp
$(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 $@
2013-12-30 17:37:40 -05:00
# include dependency files only if our goal depends on their existence
ifneq ($(MAKECMDGOALS),clean)
ifneq ($(MAKECMDGOALS),show)
2012-08-14 18:07:04 -04:00
-include $(C_DEPS_EXT) $(CPP_DEPS_EXT)
2013-12-30 17:37:40 -05:00
endif
endif
2012-08-14 18:07:04 -04:00
.PHONY : clean
clean:
2013-12-30 17:37:40 -05:00
-$(RM) $(BIN_DIR)/*.o \
$(BIN_DIR)/*.d \
$(BIN_DIR)/*.exe \
$(BIN_DIR)/*.map
2012-08-14 18:07:04 -04:00
show:
2013-12-30 17:37:40 -05:00
@echo PROJECT = $(PROJECT)
@echo CONF = $(CONF)
@echo VPATH = $(VPATH)
@echo C_SRCS = $(C_SRCS)
2012-08-14 18:07:04 -04:00
@echo CPP_SRCS = $(CPP_SRCS)
@echo ASM_OBJS_EXT = $(ASM_OBJS_EXT)
2013-12-30 17:37:40 -05:00
@echo C_OBJS_EXT = $(C_OBJS_EXT)
@echo C_DEPS_EXT = $(C_DEPS_EXT)
2012-08-14 18:07:04 -04:00
@echo CPP_DEPS_EXT = $(CPP_DEPS_EXT)