Makefile 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340
  1. # The contents of this file are subject to the Mozilla Public
  2. # License Version 1.1 (the "License"); you may not use this file
  3. # except in compliance with the License. You may obtain a copy of
  4. # the License at http://www.mozilla.org/MPL/
  5. #
  6. # Software distributed under the License is distributed on an "AS
  7. # IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
  8. # implied. See the License for the specific language governing
  9. # rights and limitations under the License.
  10. #
  11. # The Original Code is the Netscape Portable Runtime library.
  12. #
  13. # The Initial Developer of the Original Code is Netscape
  14. # Communications Corporation. Portions created by Netscape are
  15. # Copyright (C) 1994-2000 Netscape Communications Corporation. All
  16. # Rights Reserved.
  17. #
  18. # Contributor(s): Silicon Graphics, Inc.
  19. #
  20. # Portions created by SGI are Copyright (C) 2000-2001 Silicon
  21. # Graphics, Inc. All Rights Reserved.
  22. #
  23. # Alternatively, the contents of this file may be used under the
  24. # terms of the GNU General Public License Version 2 or later (the
  25. # "GPL"), in which case the provisions of the GPL are applicable
  26. # instead of those above. If you wish to allow use of your
  27. # version of this file only under the terms of the GPL and not to
  28. # allow others to use your version of this file under the MPL,
  29. # indicate your decision by deleting the provisions above and
  30. # replace them with the notice and other provisions required by
  31. # the GPL. If you do not delete the provisions above, a recipient
  32. # may use your version of this file under either the MPL or the
  33. # GPL.
  34. # This is the full version of the libst library - modify carefully
  35. VERSION = 1.9
  36. ##########################
  37. # Supported OSes:
  38. #
  39. #OS = DARWIN
  40. #OS = LINUX
  41. # Please see the "Other possible defines" section below for
  42. # possible compilation options.
  43. ##########################
  44. CC = cc
  45. AR = ar
  46. LD = ld
  47. RANLIB = ranlib
  48. LN = ln
  49. STATIC_ONLY = yes
  50. SHELL = /bin/sh
  51. ECHO = /bin/echo
  52. BUILD = DBG
  53. TARGETDIR = $(OS)_$(shell uname -r)_$(BUILD)
  54. # For Cygwin, it pass a default OS env, we ignore it.
  55. ifeq ($(OS), Windows_NT)
  56. OS =
  57. endif
  58. # For cygwin/windows, the 'uname -r' generate path with parentheses,
  59. # which cause the make fails, so we use 'uname -s' instead.
  60. ifeq ($(OS), CYGWIN64)
  61. TARGETDIR = $(OS)_$(shell uname -s)_$(BUILD)
  62. endif
  63. DEFINES = -D$(OS)
  64. CFLAGS =
  65. SFLAGS =
  66. ARFLAGS = -r
  67. LNFLAGS = -s
  68. DSO_SUFFIX = so
  69. MAJOR = $(shell echo $(VERSION) | sed 's/^\([^\.]*\).*/\1/')
  70. DESC = st.pc
  71. ##########################
  72. # Platform section.
  73. # Possible targets:
  74. TARGETS = darwin-debug darwin-optimized \
  75. linux-debug linux-optimized \
  76. cygwin64-debug
  77. UTEST_TARGETS = darwin-debug-utest linux-debug-utest \
  78. darwin-debug-gcov linux-debug-gcov \
  79. cygwin64-debug-utest
  80. #
  81. # Platform specifics
  82. #
  83. ifeq ($(OS), DARWIN)
  84. EXTRA_OBJS = $(TARGETDIR)/md_darwin.o
  85. LD = cc
  86. SFLAGS = -fPIC -fno-common
  87. DSO_SUFFIX = dylib
  88. CPU_ARCHS = $(shell g++ -dM -E - </dev/null |grep -q '__x86_64' && echo x86_64)
  89. CPU_ARCHS += $(shell g++ -dM -E - </dev/null |grep -q '__aarch64' && echo arm64)
  90. CFLAGS += -arch $(CPU_ARCHS)
  91. LDFLAGS += -arch $(CPU_ARCHS)
  92. LDFLAGS += -dynamiclib -install_name /sw/lib/libst.$(MAJOR).$(DSO_SUFFIX) -compatibility_version $(MAJOR) -current_version $(VERSION)
  93. OTHER_FLAGS = -Wall
  94. DEFINES += -DMD_HAVE_KQUEUE -DMD_HAVE_SELECT
  95. endif
  96. ifeq ($(OS), LINUX)
  97. EXTRA_OBJS = $(TARGETDIR)/md_linux.o $(TARGETDIR)/md_linux2.o
  98. SFLAGS = -fPIC
  99. LDFLAGS = -shared -soname=$(SONAME) -lc
  100. OTHER_FLAGS = -Wall
  101. DEFINES += -DMD_HAVE_EPOLL -DMD_HAVE_SELECT
  102. endif
  103. ifeq ($(OS), CYGWIN64)
  104. EXTRA_OBJS = $(TARGETDIR)/md_cygwin64.o
  105. SFLAGS = -fPIC
  106. DSO_SUFFIX = dll
  107. LDFLAGS = -shared -soname=$(SONAME) -lc
  108. OTHER_FLAGS = -Wall
  109. DEFINES += -DMD_HAVE_SELECT
  110. endif
  111. #
  112. # End of platform section.
  113. ##########################
  114. ifeq ($(BUILD), OPT)
  115. OTHER_FLAGS += -O2
  116. else
  117. OTHER_FLAGS += -g -O0
  118. DEFINES += -DDEBUG
  119. endif
  120. ##########################
  121. # Other possible defines:
  122. # To use poll(2) instead of select(2) for events checking:
  123. # DEFINES += -DUSE_POLL
  124. # You may prefer to use select for applications that have many threads
  125. # using one file descriptor, and poll for applications that have many
  126. # different file descriptors. With USE_POLL poll() is called with at
  127. # least one pollfd per I/O-blocked thread, so 1000 threads sharing one
  128. # descriptor will poll 1000 identical pollfds and select would be more
  129. # efficient. But if the threads all use different descriptors poll()
  130. # may be better depending on your operating system's implementation of
  131. # poll and select. Really, it's up to you. Oh, and on some platforms
  132. # poll() fails with more than a few dozen descriptors.
  133. #
  134. # Some platforms allow to define FD_SETSIZE (if select() is used), e.g.:
  135. # DEFINES += -DFD_SETSIZE=4096
  136. #
  137. # To use malloc(3) instead of mmap(2) for stack allocation:
  138. # DEFINES += -DMALLOC_STACK
  139. #
  140. # To provision more than the default 16 thread-specific-data keys
  141. # (but not too many!):
  142. # DEFINES += -DST_KEYS_MAX=<n>
  143. #
  144. # To start with more than the default 64 initial pollfd slots
  145. # (but the table grows dynamically anyway):
  146. # DEFINES += -DST_MIN_POLLFDS_SIZE=<n>
  147. #
  148. # Note that you can also add these defines by specifying them as
  149. # make/gmake arguments (without editing this Makefile). For example:
  150. #
  151. # make EXTRA_CFLAGS=-DUSE_POLL <target>
  152. #
  153. # (replace make with gmake if needed).
  154. #
  155. # You can also modify the default selection of an alternative event
  156. # notification mechanism. E.g., to enable kqueue(2) support (if it's not
  157. # enabled by default):
  158. #
  159. # gmake EXTRA_CFLAGS=-DMD_HAVE_KQUEUE <target>
  160. #
  161. # or to disable default epoll(4) support:
  162. #
  163. # make EXTRA_CFLAGS=-UMD_HAVE_EPOLL <target>
  164. #
  165. # or to enable sendmmsg(2) support:
  166. #
  167. # make EXTRA_CFLAGS="-DMD_HAVE_SENDMMSG -D_GNU_SOURCE"
  168. #
  169. # or to enable stats for ST:
  170. #
  171. # make EXTRA_CFLAGS=-DDEBUG_STATS
  172. #
  173. # or enable the coverage for utest:
  174. # make UTEST_FLAGS="-fprofile-arcs -ftest-coverage"
  175. #
  176. ##########################
  177. CFLAGS += $(DEFINES) $(OTHER_FLAGS) $(EXTRA_CFLAGS)
  178. CFLAGS += $(UTEST_FLAGS)
  179. OBJS = $(TARGETDIR)/sched.o \
  180. $(TARGETDIR)/stk.o \
  181. $(TARGETDIR)/sync.o \
  182. $(TARGETDIR)/key.o \
  183. $(TARGETDIR)/io.o \
  184. $(TARGETDIR)/event.o
  185. OBJS += $(EXTRA_OBJS)
  186. HEADER = $(TARGETDIR)/st.h
  187. SLIBRARY = $(TARGETDIR)/libst.a
  188. DLIBRARY = $(TARGETDIR)/libst.$(DSO_SUFFIX).$(VERSION)
  189. LINKNAME = libst.$(DSO_SUFFIX)
  190. SONAME = libst.$(DSO_SUFFIX).$(MAJOR)
  191. FULLNAME = libst.$(DSO_SUFFIX).$(VERSION)
  192. ifeq ($(OS), DARWIN)
  193. LINKNAME = libst.$(DSO_SUFFIX)
  194. SONAME = libst.$(MAJOR).$(DSO_SUFFIX)
  195. FULLNAME = libst.$(VERSION).$(DSO_SUFFIX)
  196. endif
  197. ifeq ($(STATIC_ONLY), yes)
  198. LIBRARIES = $(SLIBRARY)
  199. else
  200. LIBRARIES = $(SLIBRARY) $(DLIBRARY)
  201. endif
  202. ifeq ($(OS),)
  203. ST_ALL = unknown
  204. else
  205. ST_ALL = $(TARGETDIR) $(LIBRARIES) $(HEADER) $(DESC)
  206. endif
  207. all: $(ST_ALL)
  208. unknown:
  209. @echo
  210. @echo "Please specify one of the following targets:"
  211. @echo
  212. @for target in $(TARGETS); do echo $$target; done
  213. @echo
  214. @for target in $(UTEST_TARGETS); do echo $$target; done
  215. @echo
  216. st.pc: st.pc.in
  217. sed "s/@VERSION@/${VERSION}/g" < $< > $@
  218. $(TARGETDIR):
  219. if [ ! -d $(TARGETDIR) ]; then mkdir $(TARGETDIR); fi
  220. $(SLIBRARY): $(OBJS)
  221. $(AR) $(ARFLAGS) $@ $(OBJS)
  222. $(RANLIB) $@
  223. rm -f obj; $(LN) $(LNFLAGS) $(TARGETDIR) obj
  224. $(DLIBRARY): $(OBJS:%.o=%-pic.o)
  225. $(LD) $(LDFLAGS) $^ -o $@
  226. if test "$(LINKNAME)"; then \
  227. cd $(TARGETDIR); \
  228. rm -f $(SONAME) $(LINKNAME); \
  229. $(LN) $(LNFLAGS) $(FULLNAME) $(SONAME); \
  230. $(LN) $(LNFLAGS) $(FULLNAME) $(LINKNAME); \
  231. fi
  232. $(HEADER): public.h
  233. rm -f $@
  234. cp public.h $@
  235. $(TARGETDIR)/md_linux.o: md_linux.S
  236. $(CC) $(CFLAGS) -c $< -o $@
  237. $(TARGETDIR)/md_linux2.o: md_linux2.S
  238. $(CC) $(CFLAGS) -c $< -o $@
  239. $(TARGETDIR)/md_darwin.o: md_darwin.S
  240. $(CC) $(CFLAGS) -c $< -o $@
  241. $(TARGETDIR)/md_cygwin64.o: md_cygwin64.S
  242. $(CC) $(CFLAGS) -c $< -o $@
  243. $(TARGETDIR)/%.o: %.c common.h md.h
  244. $(CC) $(CFLAGS) -c $< -o $@
  245. clean:
  246. rm -rf *_OPT *_DBG obj st.pc
  247. ##########################
  248. # Pattern rules:
  249. ifneq ($(SFLAGS),)
  250. # Compile with shared library options if it's a C file
  251. $(TARGETDIR)/%-pic.o: %.c common.h md.h
  252. $(CC) $(CFLAGS) $(SFLAGS) -c $< -o $@
  253. endif
  254. # Compile assembly as normal or C as normal if no SFLAGS
  255. %-pic.o: %.o
  256. rm -f $@; $(LN) $(LNFLAGS) $(<F) $@
  257. ##########################
  258. # Target rules:
  259. darwin-debug:
  260. $(MAKE) OS="DARWIN" BUILD="DBG"
  261. darwin-optimized:
  262. $(MAKE) OS="DARWIN" BUILD="OPT"
  263. linux-debug:
  264. $(MAKE) OS="LINUX" BUILD="DBG"
  265. linux-optimized:
  266. $(MAKE) OS="LINUX" BUILD="OPT"
  267. cygwin64-debug:
  268. $(MAKE) OS="CYGWIN64" BUILD="DBG"
  269. darwin-debug-utest:
  270. @echo "Build utest for state-threads"
  271. $(MAKE) OS="DARWIN" BUILD="DBG"
  272. cd utest && $(MAKE)
  273. linux-debug-utest:
  274. @echo "Build utest for state-threads"
  275. $(MAKE) OS="LINUX" BUILD="DBG"
  276. cd utest && $(MAKE)
  277. cygwin64-debug-utest:
  278. @echo "Build utest for state-threads"
  279. $(MAKE) OS="CYGWIN64" BUILD="DBG"
  280. cd utest && $(MAKE) UTEST_FLAGS="-std=gnu++0x" # @see https://www.codenong.com/18784112/
  281. darwin-debug-gcov:
  282. @echo "Build utest with gcov for state-threads"
  283. $(MAKE) OS="DARWIN" BUILD="DBG" UTEST_FLAGS="-fprofile-arcs -ftest-coverage" STATIC_ONLY=yes
  284. cd utest && $(MAKE) UTEST_FLAGS="-fprofile-arcs -ftest-coverage"
  285. linux-debug-gcov:
  286. @echo "Build utest with gcov for state-threads"
  287. $(MAKE) OS="LINUX" BUILD="DBG" UTEST_FLAGS="-fprofile-arcs -ftest-coverage" STATIC_ONLY=yes
  288. cd utest && $(MAKE) UTEST_FLAGS="-fprofile-arcs -ftest-coverage"
  289. ##########################