294 lines
7.7 KiB
Makefile
Raw Normal View History

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