Makefile 7.5 KB

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