Makefile 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293
  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 := calc2
  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. main.c \
  70. calc2.c
  71. # C++ source files...
  72. CPP_SRCS :=
  73. # C++ source files...
  74. CPP_SRCS :=
  75. LIB_DIRS :=
  76. LIBS :=
  77. # defines...
  78. # QP_API_VERSION controls the QP API compatibility; 9999 means the latest API
  79. DEFINES := -DQP_API_VERSION=9999
  80. ifeq (,$(CONF))
  81. CONF := dbg
  82. endif
  83. #-----------------------------------------------------------------------------
  84. # add QP/C framework:
  85. #
  86. C_SRCS += \
  87. qep_hsm.c \
  88. qep_msm.c \
  89. qf_actq.c \
  90. qf_defer.c \
  91. qf_dyn.c \
  92. qf_mem.c \
  93. qf_ps.c \
  94. qf_qact.c \
  95. qf_qeq.c \
  96. qf_qmact.c \
  97. qf_time.c \
  98. qf_port.c
  99. QS_SRCS := \
  100. qs.c \
  101. qs_64bit.c \
  102. qs_rx.c \
  103. qs_fp.c \
  104. qs_port.c
  105. ifeq ($(OS),Windows_NT)
  106. # NOTE:
  107. # For Windows hosts, you can choose:
  108. # - the single-threaded QP/C port (win32-qv) or
  109. # - the multithreaded QP/C port (win32).
  110. #
  111. QP_PORT_DIR := $(QPC)/ports/win32-qv
  112. #QP_PORT_DIR := $(QPC)/ports/win32
  113. LIBS += -lws2_32
  114. else
  115. # NOTE:
  116. # For POSIX hosts (Linux, MacOS), you can choose:
  117. # - the single-threaded QP/C port (win32-qv) or
  118. # - the multithreaded QP/C port (win32).
  119. #
  120. QP_PORT_DIR := $(QPC)/ports/posix-qv
  121. #QP_PORT_DIR := $(QPC)/ports/posix
  122. LIBS += -lpthread
  123. endif
  124. #============================================================================
  125. # Typically you should not need to change anything below this line
  126. VPATH += $(QPC)/src/qf $(QP_PORT_DIR)
  127. INCLUDES += -I$(QPC)/include -I$(QP_PORT_DIR)
  128. #-----------------------------------------------------------------------------
  129. # GNU toolset:
  130. #
  131. # NOTE:
  132. # GNU toolset (MinGW) is included in the QTools collection for Windows, see:
  133. # https://www.state-machine.com/qtools
  134. # It is assumed that %QTOOLS%\bin directory is added to the PATH
  135. #
  136. CC := gcc
  137. CPP := g++
  138. LINK := gcc # for C programs
  139. #LINK := g++ # for C++ programs
  140. #-----------------------------------------------------------------------------
  141. # basic utilities (depends on the OS this Makefile runs on):
  142. #
  143. ifeq ($(OS),Windows_NT)
  144. MKDIR := mkdir
  145. RM := rm
  146. TARGET_EXT := .exe
  147. else ifeq ($(OSTYPE),cygwin)
  148. MKDIR := mkdir -p
  149. RM := rm -f
  150. TARGET_EXT := .exe
  151. else
  152. MKDIR := mkdir -p
  153. RM := rm -f
  154. TARGET_EXT :=
  155. endif
  156. #-----------------------------------------------------------------------------
  157. # build configurations...
  158. ifeq (rel, $(CONF)) # Release configuration ..................................
  159. BIN_DIR := build_rel
  160. # gcc options:
  161. CFLAGS = -c -O3 -fno-pie -std=c11 -pedantic -Wall -Wextra -W \
  162. $(INCLUDES) $(DEFINES) -DNDEBUG
  163. CPPFLAGS = -c -O3 -fno-pie -std=c++11 -pedantic -Wall -Wextra \
  164. -fno-rtti -fno-exceptions \
  165. $(INCLUDES) $(DEFINES) -DNDEBUG
  166. else ifeq (spy, $(CONF)) # Spy configuration ................................
  167. BIN_DIR := build_spy
  168. C_SRCS += $(QS_SRCS)
  169. VPATH += $(QPC)/src/qs
  170. # gcc options:
  171. CFLAGS = -c -g -O -fno-pie -std=c11 -pedantic -Wall -Wextra -W \
  172. $(INCLUDES) $(DEFINES) -DQ_SPY
  173. CPPFLAGS = -c -g -O -fno-pie -std=c++11 -pedantic -Wall -Wextra \
  174. -fno-rtti -fno-exceptions \
  175. $(INCLUDES) $(DEFINES) -DQ_SPY
  176. else # default Debug configuration .........................................
  177. BIN_DIR := build
  178. # gcc options:
  179. CFLAGS = -c -g -O -fno-pie -std=c11 -pedantic -Wall -Wextra -W \
  180. $(INCLUDES) $(DEFINES)
  181. CPPFLAGS = -c -g -O -fno-pie -std=c++11 -pedantic -Wall -Wextra \
  182. -fno-rtti -fno-exceptions \
  183. $(INCLUDES) $(DEFINES)
  184. endif # .....................................................................
  185. ifndef GCC_OLD
  186. LINKFLAGS := -no-pie
  187. endif
  188. #-----------------------------------------------------------------------------
  189. C_OBJS := $(patsubst %.c,%.o, $(C_SRCS))
  190. CPP_OBJS := $(patsubst %.cpp,%.o, $(CPP_SRCS))
  191. TARGET_EXE := $(BIN_DIR)/$(PROJECT)$(TARGET_EXT)
  192. C_OBJS_EXT := $(addprefix $(BIN_DIR)/, $(C_OBJS))
  193. C_DEPS_EXT := $(patsubst %.o,%.d, $(C_OBJS_EXT))
  194. CPP_OBJS_EXT := $(addprefix $(BIN_DIR)/, $(CPP_OBJS))
  195. CPP_DEPS_EXT := $(patsubst %.o,%.d, $(CPP_OBJS_EXT))
  196. #-----------------------------------------------------------------------------
  197. # rules
  198. #
  199. .PHONY: clean show
  200. all: $(TARGET_EXE)
  201. $(TARGET_EXE) : $(C_OBJS_EXT) $(CPP_OBJS_EXT)
  202. $(CC) $(CFLAGS) $(QPC)/src/qs/qstamp.c -o $(BIN_DIR)/qstamp.o
  203. $(LINK) $(LINKFLAGS) $(LIB_DIRS) -o $@ $^ $(BIN_DIR)/qstamp.o $(LIBS)
  204. $(BIN_DIR)/%.d : %.c
  205. $(CC) -MM -MT $(@:.d=.o) $(CFLAGS) $< > $@
  206. $(BIN_DIR)/%.d : %.cpp
  207. $(CPP) -MM -MT $(@:.d=.o) $(CPPFLAGS) $< > $@
  208. $(BIN_DIR)/%.o : %.c
  209. $(CC) $(CFLAGS) $< -o $@
  210. $(BIN_DIR)/%.o : %.cpp
  211. $(CPP) $(CPPFLAGS) $< -o $@
  212. # create BIN_DIR and include dependencies only if needed
  213. ifneq ($(MAKECMDGOALS),clean)
  214. ifneq ($(MAKECMDGOALS),show)
  215. ifneq ($(MAKECMDGOALS),debug)
  216. ifeq ("$(wildcard $(BIN_DIR))","")
  217. $(shell $(MKDIR) $(BIN_DIR))
  218. endif
  219. -include $(C_DEPS_EXT) $(CPP_DEPS_EXT)
  220. endif
  221. endif
  222. endif
  223. clean :
  224. -$(RM) $(BIN_DIR)/*.o \
  225. $(BIN_DIR)/*.d \
  226. $(TARGET_EXE)
  227. show :
  228. @echo PROJECT = $(PROJECT)
  229. @echo TARGET_EXE = $(TARGET_EXE)
  230. @echo VPATH = $(VPATH)
  231. @echo C_SRCS = $(C_SRCS)
  232. @echo CPP_SRCS = $(CPP_SRCS)
  233. @echo C_DEPS_EXT = $(C_DEPS_EXT)
  234. @echo C_OBJS_EXT = $(C_OBJS_EXT)
  235. @echo C_DEPS_EXT = $(C_DEPS_EXT)
  236. @echo CPP_DEPS_EXT = $(CPP_DEPS_EXT)
  237. @echo CPP_OBJS_EXT = $(CPP_OBJS_EXT)
  238. @echo LIB_DIRS = $(LIB_DIRS)
  239. @echo LIBS = $(LIBS)
  240. @echo DEFINES = $(DEFINES)