Makefile 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343
  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 cache the stack and reuse it:
  174. # make EXTRA_CFLAGS=-DMD_CACHE_STACK
  175. #
  176. # or enable the coverage for utest:
  177. # make UTEST_FLAGS="-fprofile-arcs -ftest-coverage"
  178. #
  179. ##########################
  180. CFLAGS += $(DEFINES) $(OTHER_FLAGS) $(EXTRA_CFLAGS)
  181. CFLAGS += $(UTEST_FLAGS)
  182. OBJS = $(TARGETDIR)/sched.o \
  183. $(TARGETDIR)/stk.o \
  184. $(TARGETDIR)/sync.o \
  185. $(TARGETDIR)/key.o \
  186. $(TARGETDIR)/io.o \
  187. $(TARGETDIR)/event.o
  188. OBJS += $(EXTRA_OBJS)
  189. HEADER = $(TARGETDIR)/st.h
  190. SLIBRARY = $(TARGETDIR)/libst.a
  191. DLIBRARY = $(TARGETDIR)/libst.$(DSO_SUFFIX).$(VERSION)
  192. LINKNAME = libst.$(DSO_SUFFIX)
  193. SONAME = libst.$(DSO_SUFFIX).$(MAJOR)
  194. FULLNAME = libst.$(DSO_SUFFIX).$(VERSION)
  195. ifeq ($(OS), DARWIN)
  196. LINKNAME = libst.$(DSO_SUFFIX)
  197. SONAME = libst.$(MAJOR).$(DSO_SUFFIX)
  198. FULLNAME = libst.$(VERSION).$(DSO_SUFFIX)
  199. endif
  200. ifeq ($(STATIC_ONLY), yes)
  201. LIBRARIES = $(SLIBRARY)
  202. else
  203. LIBRARIES = $(SLIBRARY) $(DLIBRARY)
  204. endif
  205. ifeq ($(OS),)
  206. ST_ALL = unknown
  207. else
  208. ST_ALL = $(TARGETDIR) $(LIBRARIES) $(HEADER) $(DESC)
  209. endif
  210. all: $(ST_ALL)
  211. unknown:
  212. @echo
  213. @echo "Please specify one of the following targets:"
  214. @echo
  215. @for target in $(TARGETS); do echo $$target; done
  216. @echo
  217. @for target in $(UTEST_TARGETS); do echo $$target; done
  218. @echo
  219. st.pc: st.pc.in
  220. sed "s/@VERSION@/${VERSION}/g" < $< > $@
  221. $(TARGETDIR):
  222. if [ ! -d $(TARGETDIR) ]; then mkdir $(TARGETDIR); fi
  223. $(SLIBRARY): $(OBJS)
  224. $(AR) $(ARFLAGS) $@ $(OBJS)
  225. $(RANLIB) $@
  226. rm -f obj; $(LN) $(LNFLAGS) $(TARGETDIR) obj
  227. $(DLIBRARY): $(OBJS:%.o=%-pic.o)
  228. $(LD) $(LDFLAGS) $^ -o $@
  229. if test "$(LINKNAME)"; then \
  230. cd $(TARGETDIR); \
  231. rm -f $(SONAME) $(LINKNAME); \
  232. $(LN) $(LNFLAGS) $(FULLNAME) $(SONAME); \
  233. $(LN) $(LNFLAGS) $(FULLNAME) $(LINKNAME); \
  234. fi
  235. $(HEADER): public.h
  236. rm -f $@
  237. cp public.h $@
  238. $(TARGETDIR)/md_linux.o: md_linux.S
  239. $(CC) $(CFLAGS) -c $< -o $@
  240. $(TARGETDIR)/md_linux2.o: md_linux2.S
  241. $(CC) $(CFLAGS) -c $< -o $@
  242. $(TARGETDIR)/md_darwin.o: md_darwin.S
  243. $(CC) $(CFLAGS) -c $< -o $@
  244. $(TARGETDIR)/md_cygwin64.o: md_cygwin64.S
  245. $(CC) $(CFLAGS) -c $< -o $@
  246. $(TARGETDIR)/%.o: %.c common.h md.h
  247. $(CC) $(CFLAGS) -c $< -o $@
  248. clean:
  249. rm -rf *_OPT *_DBG obj st.pc
  250. ##########################
  251. # Pattern rules:
  252. ifneq ($(SFLAGS),)
  253. # Compile with shared library options if it's a C file
  254. $(TARGETDIR)/%-pic.o: %.c common.h md.h
  255. $(CC) $(CFLAGS) $(SFLAGS) -c $< -o $@
  256. endif
  257. # Compile assembly as normal or C as normal if no SFLAGS
  258. %-pic.o: %.o
  259. rm -f $@; $(LN) $(LNFLAGS) $(<F) $@
  260. ##########################
  261. # Target rules:
  262. darwin-debug:
  263. $(MAKE) OS="DARWIN" BUILD="DBG"
  264. darwin-optimized:
  265. $(MAKE) OS="DARWIN" BUILD="OPT"
  266. linux-debug:
  267. $(MAKE) OS="LINUX" BUILD="DBG"
  268. linux-optimized:
  269. $(MAKE) OS="LINUX" BUILD="OPT"
  270. cygwin64-debug:
  271. $(MAKE) OS="CYGWIN64" BUILD="DBG"
  272. darwin-debug-utest:
  273. @echo "Build utest for state-threads"
  274. $(MAKE) OS="DARWIN" BUILD="DBG"
  275. cd utest && $(MAKE)
  276. linux-debug-utest:
  277. @echo "Build utest for state-threads"
  278. $(MAKE) OS="LINUX" BUILD="DBG"
  279. cd utest && $(MAKE)
  280. cygwin64-debug-utest:
  281. @echo "Build utest for state-threads"
  282. $(MAKE) OS="CYGWIN64" BUILD="DBG"
  283. cd utest && $(MAKE) UTEST_FLAGS="-std=gnu++0x" # @see https://www.codenong.com/18784112/
  284. darwin-debug-gcov:
  285. @echo "Build utest with gcov for state-threads"
  286. $(MAKE) OS="DARWIN" BUILD="DBG" UTEST_FLAGS="-fprofile-arcs -ftest-coverage" STATIC_ONLY=yes
  287. cd utest && $(MAKE) UTEST_FLAGS="-fprofile-arcs -ftest-coverage"
  288. linux-debug-gcov:
  289. @echo "Build utest with gcov for state-threads"
  290. $(MAKE) OS="LINUX" BUILD="DBG" UTEST_FLAGS="-fprofile-arcs -ftest-coverage" STATIC_ONLY=yes
  291. cd utest && $(MAKE) UTEST_FLAGS="-fprofile-arcs -ftest-coverage"
  292. ##########################