Makefile 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289
  1. ##############################################################################
  2. # Product: Makefile for QP/C for Windows and POSIX *HOSTS*
  3. # Last updated for version 7.2.0
  4. # Last updated on 2022-11-13
  5. #
  6. # Q u a n t u m L e a P s
  7. # ------------------------
  8. # Modern Embedded Software
  9. #
  10. # Copyright (C) 2005 Quantum Leaps, LLC. All rights reserved.
  11. #
  12. # This program is open source software: you can redistribute it and/or
  13. # modify it under the terms of the GNU General Public License as published
  14. # by the Free Software Foundation, either version 3 of the License, or
  15. # (at your option) any later version.
  16. #
  17. # Alternatively, this program may be distributed and modified under the
  18. # terms of Quantum Leaps commercial licenses, which expressly supersede
  19. # the GNU General Public License and are specifically designed for
  20. # licensees interested in retaining the proprietary status of their code.
  21. #
  22. # This program is distributed in the hope that it will be useful,
  23. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  24. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  25. # GNU General Public License for more details.
  26. #
  27. # You should have received a copy of the GNU General Public License
  28. # along with this program. If not, see <www.gnu.org/licenses/>.
  29. #
  30. # Contact information:
  31. # <www.state-machine.com/licensing>
  32. # <info@state-machine.com>
  33. ##############################################################################
  34. #
  35. # examples of invoking this Makefile:
  36. # building configurations: Debug (default), Release, and Spy
  37. # make
  38. # make CONF=rel
  39. # make CONF=spy
  40. # make clean # cleanup the build
  41. # make CONF=spy clean # cleanup the build
  42. #
  43. # NOTE:
  44. # To use this Makefile on Windows, you will need the GNU make utility, which
  45. # is included in the QTools collection for Windows, see:
  46. # http://sourceforge.net/projects/qpc/files/QTools/
  47. #
  48. #-----------------------------------------------------------------------------
  49. # project name:
  50. #
  51. PROJECT := reminder2
  52. #-----------------------------------------------------------------------------
  53. # project directories:
  54. #
  55. # list of all source directories used by this project
  56. VPATH := . \
  57. # list of all include directories needed by this project
  58. INCLUDES := -I. \
  59. # location of the QP/C framework (if not provided in an env. variable)
  60. ifeq ($(QPC),)
  61. QPC := ../../..
  62. endif
  63. #-----------------------------------------------------------------------------
  64. # project files:
  65. #
  66. # C source files...
  67. C_SRCS := \
  68. bsp.c \
  69. reminder2.c
  70. # C++ source files...
  71. CPP_SRCS :=
  72. LIB_DIRS :=
  73. LIBS :=
  74. # defines...
  75. # QP_API_VERSION controls the QP API compatibility; 9999 means the latest API
  76. DEFINES := -DQP_API_VERSION=9999
  77. ifeq (,$(CONF))
  78. CONF := dbg
  79. endif
  80. #-----------------------------------------------------------------------------
  81. # add QP/C framework:
  82. #
  83. C_SRCS += \
  84. qep_hsm.c \
  85. qep_msm.c \
  86. qf_actq.c \
  87. qf_defer.c \
  88. qf_dyn.c \
  89. qf_mem.c \
  90. qf_ps.c \
  91. qf_qact.c \
  92. qf_qeq.c \
  93. qf_qmact.c \
  94. qf_time.c \
  95. qf_port.c
  96. QS_SRCS := \
  97. qs.c \
  98. qs_64bit.c \
  99. qs_rx.c \
  100. qs_fp.c \
  101. qs_port.c
  102. ifeq ($(OS),Windows_NT)
  103. # NOTE:
  104. # For Windows hosts, you can choose:
  105. # - the single-threaded QP/C port (win32-qv) or
  106. # - the multithreaded QP/C port (win32).
  107. #
  108. QP_PORT_DIR := $(QPC)/ports/win32-qv
  109. #QP_PORT_DIR := $(QPC)/ports/win32
  110. LIBS += -lws2_32
  111. else
  112. # NOTE:
  113. # For POSIX hosts (Linux, MacOS), you can choose:
  114. # - the single-threaded QP/C port (win32-qv) or
  115. # - the multithreaded QP/C port (win32).
  116. #
  117. QP_PORT_DIR := $(QPC)/ports/posix-qv
  118. #QP_PORT_DIR := $(QPC)/ports/posix
  119. LIBS += -lpthread
  120. endif
  121. #============================================================================
  122. # Typically you should not need to change anything below this line
  123. VPATH += $(QPC)/src/qf $(QP_PORT_DIR)
  124. INCLUDES += -I$(QPC)/include -I$(QP_PORT_DIR)
  125. #-----------------------------------------------------------------------------
  126. # GNU toolset:
  127. #
  128. # NOTE:
  129. # GNU toolset (MinGW) is included in the QTools collection for Windows, see:
  130. # https://www.state-machine.com/qtools
  131. # It is assumed that %QTOOLS%\bin directory is added to the PATH
  132. #
  133. CC := gcc
  134. CPP := g++
  135. LINK := gcc # for C programs
  136. #LINK := g++ # for C++ programs
  137. #-----------------------------------------------------------------------------
  138. # basic utilities (depends on the OS this Makefile runs on):
  139. #
  140. ifeq ($(OS),Windows_NT)
  141. MKDIR := mkdir
  142. RM := rm
  143. TARGET_EXT := .exe
  144. else ifeq ($(OSTYPE),cygwin)
  145. MKDIR := mkdir -p
  146. RM := rm -f
  147. TARGET_EXT := .exe
  148. else
  149. MKDIR := mkdir -p
  150. RM := rm -f
  151. TARGET_EXT :=
  152. endif
  153. #-----------------------------------------------------------------------------
  154. # build configurations...
  155. ifeq (rel, $(CONF)) # Release configuration ..................................
  156. BIN_DIR := build_rel
  157. # gcc options:
  158. CFLAGS = -c -O3 -fno-pie -std=c11 -pedantic -Wall -Wextra -W \
  159. $(INCLUDES) $(DEFINES) -DNDEBUG
  160. CPPFLAGS = -c -O3 -fno-pie -std=c++11 -pedantic -Wall -Wextra \
  161. -fno-rtti -fno-exceptions \
  162. $(INCLUDES) $(DEFINES) -DNDEBUG
  163. else ifeq (spy, $(CONF)) # Spy configuration ................................
  164. BIN_DIR := build_spy
  165. C_SRCS += $(QS_SRCS)
  166. VPATH += $(QPC)/src/qs
  167. # gcc options:
  168. CFLAGS = -c -g -O -fno-pie -std=c11 -pedantic -Wall -Wextra -W \
  169. $(INCLUDES) $(DEFINES) -DQ_SPY
  170. CPPFLAGS = -c -g -O -fno-pie -std=c++11 -pedantic -Wall -Wextra \
  171. -fno-rtti -fno-exceptions \
  172. $(INCLUDES) $(DEFINES) -DQ_SPY
  173. else # default Debug configuration .........................................
  174. BIN_DIR := build
  175. # gcc options:
  176. CFLAGS = -c -g -O -fno-pie -std=c11 -pedantic -Wall -Wextra -W \
  177. $(INCLUDES) $(DEFINES)
  178. CPPFLAGS = -c -g -O -fno-pie -std=c++11 -pedantic -Wall -Wextra \
  179. -fno-rtti -fno-exceptions \
  180. $(INCLUDES) $(DEFINES)
  181. endif # .....................................................................
  182. ifndef GCC_OLD
  183. LINKFLAGS := -no-pie
  184. endif
  185. #-----------------------------------------------------------------------------
  186. C_OBJS := $(patsubst %.c,%.o, $(C_SRCS))
  187. CPP_OBJS := $(patsubst %.cpp,%.o, $(CPP_SRCS))
  188. TARGET_EXE := $(BIN_DIR)/$(PROJECT)$(TARGET_EXT)
  189. C_OBJS_EXT := $(addprefix $(BIN_DIR)/, $(C_OBJS))
  190. C_DEPS_EXT := $(patsubst %.o,%.d, $(C_OBJS_EXT))
  191. CPP_OBJS_EXT := $(addprefix $(BIN_DIR)/, $(CPP_OBJS))
  192. CPP_DEPS_EXT := $(patsubst %.o,%.d, $(CPP_OBJS_EXT))
  193. #-----------------------------------------------------------------------------
  194. # rules
  195. #
  196. .PHONY: clean show
  197. all: $(TARGET_EXE)
  198. $(TARGET_EXE) : $(C_OBJS_EXT) $(CPP_OBJS_EXT)
  199. $(CC) $(CFLAGS) $(QPC)/src/qs/qstamp.c -o $(BIN_DIR)/qstamp.o
  200. $(LINK) $(LINKFLAGS) $(LIB_DIRS) -o $@ $^ $(BIN_DIR)/qstamp.o $(LIBS)
  201. $(BIN_DIR)/%.d : %.c
  202. $(CC) -MM -MT $(@:.d=.o) $(CFLAGS) $< > $@
  203. $(BIN_DIR)/%.d : %.cpp
  204. $(CPP) -MM -MT $(@:.d=.o) $(CPPFLAGS) $< > $@
  205. $(BIN_DIR)/%.o : %.c
  206. $(CC) $(CFLAGS) $< -o $@
  207. $(BIN_DIR)/%.o : %.cpp
  208. $(CPP) $(CPPFLAGS) $< -o $@
  209. # create BIN_DIR and include dependencies only if needed
  210. ifneq ($(MAKECMDGOALS),clean)
  211. ifneq ($(MAKECMDGOALS),show)
  212. ifneq ($(MAKECMDGOALS),debug)
  213. ifeq ("$(wildcard $(BIN_DIR))","")
  214. $(shell $(MKDIR) $(BIN_DIR))
  215. endif
  216. -include $(C_DEPS_EXT) $(CPP_DEPS_EXT)
  217. endif
  218. endif
  219. endif
  220. clean :
  221. -$(RM) $(BIN_DIR)/*.o \
  222. $(BIN_DIR)/*.d \
  223. $(TARGET_EXE)
  224. show :
  225. @echo PROJECT = $(PROJECT)
  226. @echo TARGET_EXE = $(TARGET_EXE)
  227. @echo VPATH = $(VPATH)
  228. @echo C_SRCS = $(C_SRCS)
  229. @echo CPP_SRCS = $(CPP_SRCS)
  230. @echo C_DEPS_EXT = $(C_DEPS_EXT)
  231. @echo C_OBJS_EXT = $(C_OBJS_EXT)
  232. @echo C_DEPS_EXT = $(C_DEPS_EXT)
  233. @echo CPP_DEPS_EXT = $(CPP_DEPS_EXT)
  234. @echo CPP_OBJS_EXT = $(CPP_OBJS_EXT)
  235. @echo LIB_DIRS = $(LIB_DIRS)
  236. @echo LIBS = $(LIBS)
  237. @echo DEFINES = $(DEFINES)