2828# <info@state-machine.com>
2929##############################################################################
3030#
31- # examples of invoking this Makefile:
32- # building configurations: Debug (default), Release, and Spy
33- # make
34- # make CONF=rel
35- # make CONF=spy
36- # make clean # cleanup the build
37- # make CONF=spy clean # cleanup the build
31+ # this makefile builds the project as follows:
32+ #
33+ # - QP/C source code compiled as C++17
34+ # - All other C source code compiled as C++17
35+ # - All other C++ code compiled as C++17
36+ # - Project linked as C++
3837#
3938# NOTE:
4039# To use this Makefile on Windows, you will need the GNU make utility, which
@@ -56,9 +55,8 @@ C_SRCS := \
5655 philo.c \
5756 table.c
5857
59- DEFINES :=
60-
6158CPP_SRCS :=
59+
6260LIB_DIRS :=
6361LIBS :=
6462OUTPUT := $(PROJECT)
@@ -76,37 +74,36 @@ BIN_DIR := build_$(TARGET)
7674# QP framework
7775#
7876
79- # location of the QP/C framework (if not provided in an env. variable)
80- ifeq ($(QPC ),)
81- QPC := ../../..
77+ # location of the QP framework (if not provided in an env. variable)
78+ ifeq ($(QP ),)
79+ QP := ../../..
8280endif
8381
8482ifeq ($(OS),Windows_NT)
8583
8684ifdef QV
87- QP_PORT_DIR := $(QPC )/ports/win32-qv
85+ QP_PORT_DIR := $(QP )/ports/win32-qv
8886else
89- QP_PORT_DIR := $(QPC )/ports/win32
87+ QP_PORT_DIR := $(QP )/ports/win32
9088endif
9189LIBS += -lws2_32
9290
9391else
9492
9593ifdef QV
96- QP_PORT_DIR := $(QPC )/ports/posix-qv
94+ QP_PORT_DIR := $(QP )/ports/posix-qv
9795else
98- QP_PORT_DIR := $(QPC )/ports/posix
96+ QP_PORT_DIR := $(QP )/ports/posix
9997endif
10098LIBS += -lpthread
10199
102100endif
103101
104102VPATH += \
105- $(QPC)/src/qs \
106103 $(QP_PORT_DIR)
107104
108105INCLUDES += \
109- -I$(QPC )/include \
106+ -I$(QP )/include \
110107 -I$(QP_PORT_DIR)
111108
112109#-----------------------------------------------------------------------------
@@ -135,52 +132,59 @@ QS_SRCS := \
135132 qs_port.c
136133
137134VPATH += \
138- $(QPC )/src/qf \
139- $(QPC)/src/qs $( QP_PORT_DIR)
135+ $(QP )/src/qf \
136+ $(QP_PORT_DIR)
140137
141138INCLUDES += \
142- -I$(QPC )/include \
139+ -I$(QP )/include \
143140 -I$(QP_PORT_DIR)
144141
145142# add the QP sources to the build
146143C_SRCS += $(QP_SRCS)
147144
148145ifeq (spy, $(CONF)) # Spy configuration
149- VPATH += $(QPC )/src/qs
146+ VPATH += $(QP )/src/qs
150147C_SRCS += $(QS_SRCS)
151148endif
152149
153150#-----------------------------------------------------------------------------
154- # GNU toolset:
155- # NOTE: GNU toolset (MinGW) is included in the QTools collection for Windows, see:
156- # https://www.state-machine.com/qtools
151+ # GNU GCC toolset for the host:
152+ # NOTE: GNU toolset for Windows (MinGW) is included in the QTools collection
153+ # for Windows, see: https://www.state-machine.com/qtools
154+ #
157155# It is assumed that %QTOOLS%\bin directory is added to the PATH
158156#
159157CC := gcc
160158CPP := g++
161- #LINK := gcc # for C programs
162159LINK := g++ # for C++ programs
163- COV := gcov -f
164160
165161#-----------------------------------------------------------------------------
166162# basic utilities (included in QTools for Windows), see:
167163# https://www.state-machine.com/qtools
168164#
169165ifeq ($(OS),Windows_NT)
166+ TARGET_EXT := .exe
170167 MKDIR := mkdir
171168 RM := rm
172- TARGET_EXT := .exe
169+ CAT := type
170+ COV := gcov -abcgum
171+ CODE_COV := --coverage -fcondition-coverage # NOTE: required gcc 14 or newer
173172else ifeq ($(OSTYPE),cygwin)
173+ TARGET_EXT := .exe
174174 MKDIR := mkdir -p
175175 RM := rm -f
176- TARGET_EXT := .exe
176+ CAT := cat
177+ COV := gcov -b
178+ CODE_COV := -fprofile-arcs -ftest-coverage # old gcc (version < 14)
177179else
180+ TARGET_EXT :=
178181 MKDIR := mkdir -p
179182 RM := rm -f
180- TARGET_EXT :=
183+ CAT := cat
184+ COV := gcov -b
185+ CODE_COV := -fprofile-arcs -ftest-coverage # old gcc (version < 14)
181186endif
182187
183-
184188##############################################################################
185189# Typically you should not need to change anything below this line
186190
@@ -191,10 +195,12 @@ ifeq (rel, $(CONF)) # Release configuration ..................................
191195
192196BIN_DIR := build_rel
193197# gcc options:
194- CFLAGS := -c -fno-pie -std=c11 -pedantic -Wall -Wextra -W \
198+ CFLAGS := -c -fno-pie -std=c11 -pedantic -Wall \
199+ -Wall -Wextra -Wpedantic -Wsign-conversion \
195200 -O3 $(INCLUDES) $(DEFINES) $(DEF) -DNDEBUG
196201
197- CPPFLAGS := -c -fno-pie -std=c++11 -pedantic -Wall -Wextra \
202+ CPPFLAGS := -c -fno-pie -std=c++17 -pedantic \
203+ -Wall -Wextra -Wpedantic -Wsign-conversion \
198204 -fno-rtti -fno-exceptions \
199205 -O3 $(INCLUDES) $(DEFINES) $(DEF) -DNDEBUG
200206
@@ -203,10 +209,12 @@ else ifeq (spy, $(CONF)) # Spy configuration ................................
203209BIN_DIR := build_spy
204210
205211# gcc options:
206- CFLAGS := -c -g -fno-pie -std=c11 -pedantic -Wall -Wextra -W \
212+ CFLAGS := -c -g -fno-pie -std=c11 -pedantic \
213+ -Wall -Wextra -Wpedantic -Wsign-conversion \
207214 -O $(INCLUDES) $(DEFINES) $(DEF) -DQ_SPY
208215
209- CPPFLAGS := -c -g -fno-pie -std=c++11 -pedantic -Wall -Wextra \
216+ CPPFLAGS := -c -g -fno-pie -std=c++17 -pedantic \
217+ -Wall -Wextra -Wpedantic -Wsign-conversion \
210218 -fno-rtti -fno-exceptions \
211219 -O $(INCLUDES) $(DEFINES) -DQ_SPY
212220
@@ -215,23 +223,25 @@ else # default Debug configuration .........................................
215223BIN_DIR := build
216224
217225# gcc options:
218- CFLAGS := -c -g -fno-pie -std=c11 -pedantic -Wall -Wextra -W \
226+ CFLAGS := -c -g -fno-pie -std=c11 -pedantic \
227+ -Wall -Wextra -Wpedantic -Wsign-conversion \
219228 -O $(INCLUDES) $(DEFINES) $(DEF)
220229
221- CPPFLAGS := -c -g -fno-pie -std=c++11 -pedantic -Wall -Wextra \
230+ CPPFLAGS := -c -g -fno-pie -std=c++17 -pedantic \
231+ -Wall -Wextra -Wpedantic -Wsign-conversion \
222232 -fno-rtti -fno-exceptions \
223233 -O $(INCLUDES) $(DEFINES) $(DEF)
224234
225235endif # .....................................................................
226236
227- ifndef GCC_OLD
228- LINKFLAGS := -no-pie
237+ ifdef GCOV
238+ CFLAGS += $(CODE_COV)
239+ CPPFLAGS += $(CODE_COV)
240+ LINKFLAGS := $(CODE_COV)
229241endif
230242
231- ifdef GCOV
232- CFLAGS += -fprofile-arcs -ftest-coverage
233- CPPFLAGS += -fprofile-arcs -ftest-coverage
234- LINKFLAGS += -lgcov --coverage
243+ ifndef GCC_OLD
244+ LINKFLAGS += -no-pie
235245endif
236246
237247#-----------------------------------------------------------------------------
@@ -251,7 +261,6 @@ endif
251261
252262#-----------------------------------------------------------------------------
253263# rules
254- #
255264
256265.PHONY: clean show
257266
@@ -260,7 +269,7 @@ all: $(TARGET_EXE)
260269ifeq (spy, $(CONF))
261270
262271$(TARGET_EXE) : $(C_OBJS_EXT) $(CPP_OBJS_EXT)
263- $(CPP) $(CPPFLAGS) $(QPC )/src/qs/qstamp.c -o $(BIN_DIR)/qstamp.o
272+ $(CPP) $(CPPFLAGS) $(QP )/src/qs/qstamp.c -o $(BIN_DIR)/qstamp.o
264273 $(LINK) $(LINKFLAGS) $(LIB_DIRS) -o $@ $^ $(BIN_DIR)/qstamp.o $(LIBS)
265274
266275else
0 commit comments