294 lines
7.8 KiB
Makefile
Raw Normal View History

2018-04-05 17:04:31 -04:00
##############################################################################
2018-10-25 11:13:01 -04:00
# Product: Makefile for QP/C++ for Windows and POSIX *HOSTS*
2020-07-18 17:58:58 -04:00
# Last updated for version 6.8.2
# Last updated on 2020-06-23
2018-04-05 17:04:31 -04:00
#
2018-10-25 11:13:01 -04:00
# Q u a n t u m L e a P s
# ------------------------
# Modern Embedded Software
2018-04-05 17:04:31 -04:00
#
2020-07-18 17:58:58 -04:00
# Copyright (C) 2005-2020 Quantum Leaps, LLC. All rights reserved.
2018-04-05 17:04:31 -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
# (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
2020-07-18 17:58:58 -04:00
# along with this program. If not, see <www.gnu.org/licenses/>.
2018-04-05 17:04:31 -04:00
#
# Contact information:
2020-07-18 17:58:58 -04:00
# <www.state-machine.com/licensing>
# <info@state-machine.com>
2018-04-05 17:04:31 -04:00
##############################################################################
#
# examples of invoking this Makefile:
# building configurations: Debug (default), Release, and Spy
# make
# make CONF=rel
# make CONF=spy
2018-10-25 11:13:01 -04:00
# make clean # cleanup the build
# make CONF=spy clean # cleanup the build
#
# NOTE:
# To use this Makefile on Windows, you will need the GNU make utility, which
# is included in the QTools collection for Windows, see:
# http://sourceforge.net/projects/qpc/files/QTools/
2018-04-05 17:04:31 -04:00
#
#-----------------------------------------------------------------------------
2018-10-25 11:13:01 -04:00
# project name:
2018-04-05 17:04:31 -04:00
#
2018-10-25 11:13:01 -04:00
PROJECT := qhsmtst
2018-04-05 17:04:31 -04:00
#-----------------------------------------------------------------------------
2018-10-25 11:13:01 -04:00
# project directories:
2018-04-05 17:04:31 -04:00
#
# list of all source directories used by this project
2018-10-25 11:13:01 -04:00
VPATH := . \
2018-04-05 17:04:31 -04:00
# list of all include directories needed by this project
2018-10-25 11:13:01 -04:00
INCLUDES := -I. \
# location of the QP/C framework (if not provided in an env. variable)
ifeq ($(QPCPP),)
QPCPP := ../../..
endif
2018-04-05 17:04:31 -04:00
#-----------------------------------------------------------------------------
2018-10-25 11:13:01 -04:00
# project files:
2018-04-05 17:04:31 -04:00
#
# C source files...
2018-10-25 11:13:01 -04:00
C_SRCS :=
2018-04-05 17:04:31 -04:00
# C++ source files...
CPP_SRCS := \
main.cpp \
2018-10-25 11:13:01 -04:00
qhsmtst.cpp
LIB_DIRS :=
LIBS :=
# defines...
# QP_API_VERSION controls the QP API compatibility; 9999 means the latest API
DEFINES := -DQP_API_VERSION=9999
ifeq (,$(CONF))
CONF := dbg
endif
#-----------------------------------------------------------------------------
# add QP/C++ framework (depends on the OS this Makefile runs on):
#
ifeq ($(OS),Windows_NT)
# NOTE:
# For Windows hosts, you can choose:
# - the single-threaded QP/C++ port (win32-qv) or
# - the multithreaded QP/C++ port (win32).
#
QP_PORT_DIR := $(QPCPP)/ports/win32-qv
#QP_PORT_DIR := $(QPCPP)/ports/win32
LIB_DIRS += -L$(QP_PORT_DIR)/$(CONF)
2018-11-22 11:34:13 -05:00
LIBS += -lqp -lws2_32
2018-10-25 11:13:01 -04:00
else
# NOTE:
# For POSIX hosts (Linux, MacOS), you can choose:
# - the single-threaded QP/C++ port (win32-qv) or
# - the multithreaded QP/C++ port (win32).
#
QP_PORT_DIR := $(QPCPP)/ports/posix-qv
#QP_PORT_DIR := $(QPCPP)/ports/posix
2018-04-05 17:04:31 -04:00
2018-10-25 11:13:01 -04:00
CPP_SRCS += \
2018-04-05 17:04:31 -04:00
qep_hsm.cpp \
qep_msm.cpp \
qf_act.cpp \
qf_actq.cpp \
qf_defer.cpp \
qf_dyn.cpp \
qf_mem.cpp \
qf_ps.cpp \
qf_qact.cpp \
qf_qeq.cpp \
qf_qmact.cpp \
qf_time.cpp \
qf_port.cpp
QS_SRCS := \
qs.cpp \
qs_64bit.cpp \
qs_rx.cpp \
2018-10-25 11:13:01 -04:00
qs_fp.cpp \
qs_port.cpp
2018-04-05 17:04:31 -04:00
2018-10-25 11:13:01 -04:00
LIBS += -lpthread
2018-04-05 17:04:31 -04:00
2018-10-25 11:13:01 -04:00
endif
#============================================================================
# Typically you should not need to change anything below this line
VPATH += $(QPCPP)/src/qf $(QP_PORT_DIR)
INCLUDES += -I$(QPCPP)/include -I$(QPCPP)/src -I$(QP_PORT_DIR)
2018-04-05 17:04:31 -04:00
#-----------------------------------------------------------------------------
2018-10-25 11:13:01 -04:00
# GNU toolset:
#
# NOTE:
# GNU toolset (MinGW) is included in the QTools collection for Windows, see:
# http://sourceforge.net/projects/qpc/files/QTools/
# It is assumed that %QTOOLS%\bin directory is added to the PATH
2018-04-05 17:04:31 -04:00
#
CC := gcc
CPP := g++
#LINK := gcc # for C programs
LINK := g++ # for C++ programs
#-----------------------------------------------------------------------------
2018-10-25 11:13:01 -04:00
# basic utilities (depends on the OS this Makefile runs on):
2018-04-05 17:04:31 -04:00
#
2018-10-25 11:13:01 -04:00
ifeq ($(OS),Windows_NT)
MKDIR := mkdir
RM := rm
TARGET_EXT := .exe
else ifeq ($(OSTYPE),cygwin)
MKDIR := mkdir -p
RM := rm -f
TARGET_EXT := .exe
else
MKDIR := mkdir -p
RM := rm -f
TARGET_EXT :=
endif
#-----------------------------------------------------------------------------
# build configurations...
2018-04-05 17:04:31 -04:00
ifeq (rel, $(CONF)) # Release configuration ..................................
2018-10-25 11:13:01 -04:00
BIN_DIR := build_rel
2019-02-10 21:01:38 -05:00
# gcc options:
CFLAGS = -c -O3 -fno-pie -std=c99 -pedantic -Wall -Wextra -W \
$(INCLUDES) $(DEFINES) -DNDEBUG
2018-04-05 17:04:31 -04:00
2019-02-10 21:01:38 -05:00
CPPFLAGS = -c -O3 -fno-pie -std=c++11 -pedantic -Wall -Wextra \
-fno-rtti -fno-exceptions \
$(INCLUDES) $(DEFINES) -DNDEBUG
2018-04-05 17:04:31 -04:00
else ifeq (spy, $(CONF)) # Spy configuration ................................
2018-10-25 11:13:01 -04:00
BIN_DIR := build_spy
2018-04-05 17:04:31 -04:00
CPP_SRCS += $(QS_SRCS)
2018-10-25 11:13:01 -04:00
VPATH += $(QPCPP)/src/qs
2018-04-05 17:04:31 -04:00
2019-02-10 21:01:38 -05:00
# gcc options:
CFLAGS = -c -g -O -fno-pie -std=c99 -pedantic -Wall -Wextra -W \
$(INCLUDES) $(DEFINES) -DQ_SPY
2018-04-05 17:04:31 -04:00
2019-02-10 21:01:38 -05:00
CPPFLAGS = -c -g -O -fno-pie -std=c++11 -pedantic -Wall -Wextra \
-fno-rtti -fno-exceptions \
$(INCLUDES) $(DEFINES) -DQ_SPY
2018-04-05 17:04:31 -04:00
2019-02-10 21:01:38 -05:00
else # default Debug configuration .........................................
2018-04-05 17:04:31 -04:00
2018-10-25 11:13:01 -04:00
BIN_DIR := build
2018-04-05 17:04:31 -04:00
2019-02-10 21:01:38 -05:00
# gcc options:
CFLAGS = -c -g -O -fno-pie -std=c99 -pedantic -Wall -Wextra -W \
$(INCLUDES) $(DEFINES)
2018-04-05 17:04:31 -04:00
2019-02-10 21:01:38 -05:00
CPPFLAGS = -c -g -O -fno-pie -std=c++11 -pedantic -Wall -Wextra \
-fno-rtti -fno-exceptions \
$(INCLUDES) $(DEFINES)
2018-04-05 17:04:31 -04:00
endif # .....................................................................
2020-07-18 17:58:58 -04:00
ifndef GCC_OLD
LINKFLAGS := -no-pie
endif
2018-04-05 17:04:31 -04:00
#-----------------------------------------------------------------------------
C_OBJS := $(patsubst %.c,%.o, $(C_SRCS))
CPP_OBJS := $(patsubst %.cpp,%.o, $(CPP_SRCS))
2018-10-25 11:13:01 -04:00
TARGET_EXE := $(BIN_DIR)/$(PROJECT)$(TARGET_EXT)
2018-04-05 17:04:31 -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))
# create $(BIN_DIR) if it does not exist
ifeq ("$(wildcard $(BIN_DIR))","")
$(shell $(MKDIR) $(BIN_DIR))
endif
#-----------------------------------------------------------------------------
# rules
#
all: $(TARGET_EXE)
$(TARGET_EXE) : $(C_OBJS_EXT) $(CPP_OBJS_EXT)
2019-03-06 20:08:32 -05:00
$(CPP) $(CPPFLAGS) $(QPCPP)/include/qstamp.cpp -o $(BIN_DIR)/qstamp.o
2018-04-05 17:04:31 -04:00
$(LINK) $(LINKFLAGS) $(LIB_DIRS) -o $@ $^ $(BIN_DIR)/qstamp.o $(LIBS)
$(BIN_DIR)/%.d : %.c
$(CC) -MM -MT $(@:.d=.o) $(CFLAGS) $< > $@
2019-02-10 21:01:38 -05:00
$(BIN_DIR)/%.d : %.cpp
$(CPP) -MM -MT $(@:.d=.o) $(CPPFLAGS) $< > $@
2018-04-05 17:04:31 -04:00
$(BIN_DIR)/%.o : %.c
2018-10-25 11:13:01 -04:00
$(CC) $(CFLAGS) $< -o $@
2019-02-10 21:01:38 -05:00
$(BIN_DIR)/%.o : %.cpp
$(CPP) $(CPPFLAGS) $< -o $@
2018-10-25 11:13:01 -04:00
.PHONY : clean show
2018-04-05 17:04:31 -04:00
# 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
2018-10-25 11:13:01 -04:00
.PHONY : clean show
clean :
-$(RM) $(BIN_DIR)/*.o \
$(BIN_DIR)/*.d \
$(TARGET_EXE)
show :
@echo PROJECT = $(PROJECT)
@echo TARGET_EXE = $(TARGET_EXE)
@echo VPATH = $(VPATH)
@echo C_SRCS = $(C_SRCS)
@echo CPP_SRCS = $(CPP_SRCS)
@echo C_DEPS_EXT = $(C_DEPS_EXT)
2018-04-05 17:04:31 -04:00
@echo C_OBJS_EXT = $(C_OBJS_EXT)
@echo C_DEPS_EXT = $(C_DEPS_EXT)
@echo CPP_DEPS_EXT = $(CPP_DEPS_EXT)
@echo CPP_OBJS_EXT = $(CPP_OBJS_EXT)
2018-10-25 11:13:01 -04:00
@echo LIB_DIRS = $(LIB_DIRS)
@echo LIBS = $(LIBS)
@echo DEFINES = $(DEFINES)
2018-04-05 17:04:31 -04:00