Makefile 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  1. ##############################################################################
  2. # Product: Makefile for Embedded Test (ET) for Windows *HOST*
  3. # Last Updated for Version: 7.2.2
  4. # Date of the Last Update: 2023-01-30
  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. # make # make and run the Python tests in the current directory
  37. # make TESTS=test*.py # make and run the selected tests in the curr. dir.
  38. # make HOST=localhost:7705 # connect to host:port
  39. # make norun # only make but not run the tests
  40. # make clean # cleanup the build
  41. # make debug # only run tests in DEBUG mode
  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. # https://github.com/QuantumLeaps/qtools
  47. #
  48. #-----------------------------------------------------------------------------
  49. # project name:
  50. PROJECT := test
  51. #-----------------------------------------------------------------------------
  52. # project directories:
  53. #
  54. QPC := ../../..
  55. ET := ../../et
  56. # list of all source directories used by this project
  57. VPATH := . \
  58. $(QPC)/src/qf \
  59. $(QPC)/src/qs \
  60. $(ET)
  61. # list of all include directories needed by this project
  62. INCLUDES := -I. \
  63. -I$(QPC)/include \
  64. -I$(ET)
  65. #-----------------------------------------------------------------------------
  66. # project files:
  67. #
  68. # C source files...
  69. C_SRCS := \
  70. qf_qeq.c \
  71. qs.c \
  72. qs_rx.c \
  73. test.c \
  74. et.c \
  75. et_host.c
  76. # C++ source files...
  77. CPP_SRCS :=
  78. LIB_DIRS :=
  79. LIBS :=
  80. # defines...
  81. DEFINES := -DQ_SPY
  82. #============================================================================
  83. # Typically you should not need to change anything below this line
  84. #-----------------------------------------------------------------------------
  85. # GNU toolset:
  86. #
  87. # NOTE:
  88. # GNU toolset (MinGW) is included in the QTools collection for Windows, see:
  89. # https://www.state-machine.com/qtools
  90. # It is assumed that %QTOOLS%\bin directory is added to the PATH
  91. #
  92. CC := gcc
  93. CPP := g++
  94. LINK := gcc # for C programs
  95. #LINK := g++ # for C++ programs
  96. #-----------------------------------------------------------------------------
  97. # basic utilities (depends on the OS this Makefile runs on):
  98. #
  99. ifeq ($(OS),Windows_NT)
  100. MKDIR := mkdir
  101. RM := rm
  102. TARGET_EXT := .exe
  103. else ifeq ($(OSTYPE),cygwin)
  104. MKDIR := mkdir -p
  105. RM := rm -f
  106. TARGET_EXT := .exe
  107. else
  108. MKDIR := mkdir -p
  109. RM := rm -f
  110. TARGET_EXT :=
  111. endif
  112. #-----------------------------------------------------------------------------
  113. # build options...
  114. BIN_DIR := build
  115. CFLAGS := -c -g -O -fno-pie -std=c11 -pedantic -Wall -Wextra -W \
  116. $(INCLUDES) $(DEFINES) -DQ_HOST
  117. CPPFLAGS := -c -g -O -fno-pie -std=c++11 -pedantic -Wall -Wextra \
  118. -fno-rtti -fno-exceptions \
  119. $(INCLUDES) $(DEFINES) -DQ_HOST
  120. ifndef GCC_OLD
  121. LINKFLAGS := -no-pie
  122. endif
  123. ifdef GCOV
  124. CFLAGS += -fprofile-arcs -ftest-coverage
  125. CPPFLAGS += -fprofile-arcs -ftest-coverage
  126. LINKFLAGS += -lgcov --coverage
  127. endif
  128. #-----------------------------------------------------------------------------
  129. C_OBJS := $(patsubst %.c,%.o, $(C_SRCS))
  130. CPP_OBJS := $(patsubst %.cpp,%.o, $(CPP_SRCS))
  131. TARGET_EXE := $(BIN_DIR)/$(PROJECT)$(TARGET_EXT)
  132. C_OBJS_EXT := $(addprefix $(BIN_DIR)/, $(C_OBJS))
  133. C_DEPS_EXT := $(patsubst %.o,%.d, $(C_OBJS_EXT))
  134. CPP_OBJS_EXT := $(addprefix $(BIN_DIR)/, $(CPP_OBJS))
  135. CPP_DEPS_EXT := $(patsubst %.o,%.d, $(CPP_OBJS_EXT))
  136. #-----------------------------------------------------------------------------
  137. # rules
  138. #
  139. .PHONY : norun clean show
  140. ifeq ($(MAKECMDGOALS),norun)
  141. all : $(TARGET_EXE)
  142. norun : all
  143. else
  144. all : $(TARGET_EXE) run
  145. endif
  146. $(TARGET_EXE) : $(C_OBJS_EXT) $(CPP_OBJS_EXT)
  147. $(CC) $(CFLAGS) $(QPC)/src/qs/qstamp.c -o $(BIN_DIR)/qstamp.o
  148. $(LINK) $(LINKFLAGS) $(LIB_DIRS) -o $@ $^ $(BIN_DIR)/qstamp.o $(LIBS)
  149. run : $(TARGET_EXE)
  150. $(TARGET_EXE)
  151. $(BIN_DIR)/%.d : %.cpp
  152. $(CPP) -MM -MT $(@:.d=.o) $(CPPFLAGS) $< > $@
  153. $(BIN_DIR)/%.d : %.c
  154. $(CC) -MM -MT $(@:.d=.o) $(CFLAGS) $< > $@
  155. $(BIN_DIR)/%.o : %.c
  156. $(CC) $(CFLAGS) $< -o $@
  157. $(BIN_DIR)/%.o : %.cpp
  158. $(CPP) $(CPPFLAGS) $< -o $@
  159. # create BIN_DIR and include dependencies only if needed
  160. ifneq ($(MAKECMDGOALS),clean)
  161. ifneq ($(MAKECMDGOALS),show)
  162. ifneq ($(MAKECMDGOALS),debug)
  163. ifeq ("$(wildcard $(BIN_DIR))","")
  164. $(shell $(MKDIR) $(BIN_DIR))
  165. endif
  166. -include $(C_DEPS_EXT) $(CPP_DEPS_EXT)
  167. endif
  168. endif
  169. endif
  170. clean :
  171. -$(RM) $(BIN_DIR)/*.*
  172. show :
  173. @echo PROJECT = $(PROJECT)
  174. @echo TARGET_EXE = $(TARGET_EXE)
  175. @echo VPATH = $(VPATH)
  176. @echo C_SRCS = $(C_SRCS)
  177. @echo CPP_SRCS = $(CPP_SRCS)
  178. @echo C_DEPS_EXT = $(C_DEPS_EXT)
  179. @echo C_OBJS_EXT = $(C_OBJS_EXT)
  180. @echo C_DEPS_EXT = $(C_DEPS_EXT)
  181. @echo CPP_DEPS_EXT = $(CPP_DEPS_EXT)
  182. @echo CPP_OBJS_EXT = $(CPP_OBJS_EXT)
  183. @echo LIB_DIRS = $(LIB_DIRS)
  184. @echo LIBS = $(LIBS)
  185. @echo DEFINES = $(DEFINES)