Makefile 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483
  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 = AIX
  40. #OS = CYGWIN
  41. #OS = DARWIN
  42. #OS = FREEBSD
  43. #OS = HPUX
  44. #OS = HPUX_64
  45. #OS = IRIX
  46. #OS = IRIX_64
  47. #OS = LINUX
  48. #OS = NETBSD
  49. #OS = OPENBSD
  50. #OS = OSF1
  51. #OS = SOLARIS
  52. #OS = SOLARIS_64
  53. # Please see the "Other possible defines" section below for
  54. # possible compilation options.
  55. ##########################
  56. CC = cc
  57. AR = ar
  58. LD = ld
  59. RANLIB = ranlib
  60. LN = ln
  61. SHELL = /bin/sh
  62. ECHO = /bin/echo
  63. BUILD = DBG
  64. TARGETDIR = $(OS)_$(shell uname -r)_$(BUILD)
  65. DEFINES = -D$(OS)
  66. CFLAGS =
  67. SFLAGS =
  68. ARFLAGS = -rv
  69. LNFLAGS = -s
  70. DSO_SUFFIX = so
  71. MAJOR = $(shell echo $(VERSION) | sed 's/^\([^\.]*\).*/\1/')
  72. DESC = st.pc
  73. ##########################
  74. # Platform section.
  75. # Possible targets:
  76. TARGETS = aix-debug aix-optimized \
  77. cygwin-debug cygwin-optimized \
  78. darwin-debug darwin-optimized \
  79. freebsd-debug freebsd-optimized \
  80. hpux-debug hpux-optimized \
  81. hpux-64-debug hpux-64-optimized \
  82. irix-n32-debug irix-n32-optimized \
  83. irix-64-debug irix-64-optimized \
  84. linux-debug linux-optimized \
  85. netbsd-debug netbsd-optimized \
  86. openbsd-debug openbsd-optimized \
  87. osf1-debug osf1-optimized \
  88. solaris-debug solaris-optimized \
  89. solaris-64-debug solaris-64-optimized
  90. #
  91. # Platform specifics
  92. #
  93. ifeq ($(OS), AIX)
  94. AIX_VERSION = $(shell uname -v).$(shell uname -r)
  95. TARGETDIR = $(OS)_$(AIX_VERSION)_$(BUILD)
  96. CC = xlC
  97. STATIC_ONLY = yes
  98. ifeq ($(BUILD), OPT)
  99. OTHER_FLAGS = -w
  100. endif
  101. ifneq ($(filter-out 4.1 4.2, $(AIX_VERSION)),)
  102. DEFINES += -DMD_HAVE_SOCKLEN_T
  103. endif
  104. endif
  105. ifeq ($(OS), CYGWIN)
  106. TARGETDIR = $(OS)_$(BUILD)
  107. CC = gcc
  108. LD = gcc
  109. DSO_SUFFIX = dll
  110. SLIBRARY = $(TARGETDIR)/libst.dll.a
  111. DLIBRARY = $(TARGETDIR)/libst.dll
  112. DEF_FILE = $(TARGETDIR)/libst.def
  113. LDFLAGS = libst.def -shared --enable-auto-image-base -Wl,--output-def,$(DEF_FILE),--out-implib,$(SLIBRARY)
  114. OTHER_FLAGS = -Wall
  115. endif
  116. ifeq ($(OS), DARWIN)
  117. EXTRA_OBJS = $(TARGETDIR)/md_darwin.o
  118. LD = cc
  119. SFLAGS = -fPIC -fno-common
  120. DSO_SUFFIX = dylib
  121. RELEASE = $(shell uname -r | cut -d. -f1)
  122. PPC = $(shell test $(RELEASE) -le 9 && echo yes)
  123. INTEL = $(shell test $(RELEASE) -ge 9 && echo yes)
  124. ifeq ($(PPC), yes)
  125. CFLAGS += -arch ppc
  126. LDFLAGS += -arch ppc
  127. endif
  128. ifeq ($(INTEL), yes)
  129. CFLAGS += -arch x86_64
  130. LDFLAGS += -arch x86_64
  131. endif
  132. LDFLAGS += -dynamiclib -install_name /sw/lib/libst.$(MAJOR).$(DSO_SUFFIX) -compatibility_version $(MAJOR) -current_version $(VERSION)
  133. OTHER_FLAGS = -Wall
  134. endif
  135. ifeq ($(OS), FREEBSD)
  136. SFLAGS = -fPIC
  137. LDFLAGS = -shared -soname=$(SONAME) -lc
  138. OTHER_FLAGS = -Wall
  139. ifeq ($(shell test -f /usr/include/sys/event.h && echo yes), yes)
  140. DEFINES += -DMD_HAVE_KQUEUE
  141. endif
  142. endif
  143. ifeq (HPUX, $(findstring HPUX, $(OS)))
  144. ifeq ($(OS), HPUX_64)
  145. DEFINES = -DHPUX
  146. CFLAGS = -Ae +DD64 +Z
  147. else
  148. CFLAGS = -Ae +DAportable +Z
  149. endif
  150. RANLIB = true
  151. LDFLAGS = -b
  152. DSO_SUFFIX = sl
  153. endif
  154. ifeq (IRIX, $(findstring IRIX, $(OS)))
  155. ifeq ($(OS), IRIX_64)
  156. DEFINES = -DIRIX
  157. ABIFLAG = -64
  158. else
  159. ABIFLAG = -n32
  160. endif
  161. RANLIB = true
  162. CFLAGS = $(ABIFLAG) -mips3
  163. LDFLAGS = $(ABIFLAG) -shared
  164. OTHER_FLAGS = -fullwarn
  165. endif
  166. ifeq ($(OS), LINUX)
  167. EXTRA_OBJS = $(TARGETDIR)/md.o
  168. SFLAGS = -fPIC
  169. LDFLAGS = -shared -soname=$(SONAME) -lc
  170. OTHER_FLAGS = -Wall
  171. ifeq ($(shell test -f /usr/include/sys/epoll.h && echo yes), yes)
  172. DEFINES += -DMD_HAVE_EPOLL
  173. endif
  174. endif
  175. ifeq ($(OS), NETBSD)
  176. SFLAGS = -fPIC
  177. LDFLAGS = -shared -soname=$(SONAME) -lc
  178. OTHER_FLAGS = -Wall
  179. endif
  180. ifeq ($(OS), OPENBSD)
  181. SFLAGS = -fPIC
  182. LDFLAGS = -shared -soname=$(SONAME) -lc
  183. OTHER_FLAGS = -Wall
  184. ifeq ($(shell test -f /usr/include/sys/event.h && echo yes), yes)
  185. DEFINES += -DMD_HAVE_KQUEUE
  186. endif
  187. endif
  188. ifeq ($(OS), OSF1)
  189. RANLIB = true
  190. LDFLAGS = -shared -all -expect_unresolved "*"
  191. endif
  192. ifeq (SOLARIS, $(findstring SOLARIS, $(OS)))
  193. TARGETDIR = $(OS)_$(shell uname -r | sed 's/^5/2/')_$(BUILD)
  194. CC = gcc
  195. LD = gcc
  196. RANLIB = true
  197. LDFLAGS = -G
  198. OTHER_FLAGS = -Wall
  199. ifeq ($(OS), SOLARIS_64)
  200. DEFINES = -DSOLARIS
  201. CFLAGS += -m64
  202. LDFLAGS += -m64
  203. endif
  204. endif
  205. #
  206. # End of platform section.
  207. ##########################
  208. ifeq ($(BUILD), OPT)
  209. OTHER_FLAGS += -O
  210. else
  211. OTHER_FLAGS += -g
  212. DEFINES += -DDEBUG
  213. endif
  214. ##########################
  215. # Other possible defines:
  216. # To use poll(2) instead of select(2) for events checking:
  217. # DEFINES += -DUSE_POLL
  218. # You may prefer to use select for applications that have many threads
  219. # using one file descriptor, and poll for applications that have many
  220. # different file descriptors. With USE_POLL poll() is called with at
  221. # least one pollfd per I/O-blocked thread, so 1000 threads sharing one
  222. # descriptor will poll 1000 identical pollfds and select would be more
  223. # efficient. But if the threads all use different descriptors poll()
  224. # may be better depending on your operating system's implementation of
  225. # poll and select. Really, it's up to you. Oh, and on some platforms
  226. # poll() fails with more than a few dozen descriptors.
  227. #
  228. # Some platforms allow to define FD_SETSIZE (if select() is used), e.g.:
  229. # DEFINES += -DFD_SETSIZE=4096
  230. #
  231. # To use malloc(3) instead of mmap(2) for stack allocation:
  232. # DEFINES += -DMALLOC_STACK
  233. #
  234. # To provision more than the default 16 thread-specific-data keys
  235. # (but not too many!):
  236. # DEFINES += -DST_KEYS_MAX=<n>
  237. #
  238. # To start with more than the default 64 initial pollfd slots
  239. # (but the table grows dynamically anyway):
  240. # DEFINES += -DST_MIN_POLLFDS_SIZE=<n>
  241. #
  242. # Note that you can also add these defines by specifying them as
  243. # make/gmake arguments (without editing this Makefile). For example:
  244. #
  245. # make EXTRA_CFLAGS=-DUSE_POLL <target>
  246. #
  247. # (replace make with gmake if needed).
  248. #
  249. # You can also modify the default selection of an alternative event
  250. # notification mechanism. E.g., to enable kqueue(2) support (if it's not
  251. # enabled by default):
  252. #
  253. # gmake EXTRA_CFLAGS=-DMD_HAVE_KQUEUE <target>
  254. #
  255. # or to disable default epoll(4) support:
  256. #
  257. # make EXTRA_CFLAGS=-UMD_HAVE_EPOLL <target>
  258. #
  259. # or to enable stats for ST:
  260. #
  261. # make EXTRA_CFLAGS=-DDEBUG_STATS
  262. ##########################
  263. CFLAGS += $(DEFINES) $(OTHER_FLAGS) $(EXTRA_CFLAGS)
  264. OBJS = $(TARGETDIR)/sched.o \
  265. $(TARGETDIR)/stk.o \
  266. $(TARGETDIR)/sync.o \
  267. $(TARGETDIR)/key.o \
  268. $(TARGETDIR)/io.o \
  269. $(TARGETDIR)/event.o
  270. OBJS += $(EXTRA_OBJS)
  271. HEADER = $(TARGETDIR)/st.h
  272. SLIBRARY = $(TARGETDIR)/libst.a
  273. DLIBRARY = $(TARGETDIR)/libst.$(DSO_SUFFIX).$(VERSION)
  274. EXAMPLES = examples
  275. LINKNAME = libst.$(DSO_SUFFIX)
  276. SONAME = libst.$(DSO_SUFFIX).$(MAJOR)
  277. FULLNAME = libst.$(DSO_SUFFIX).$(VERSION)
  278. ifeq ($(OS), CYGWIN)
  279. SONAME = cygst.$(DSO_SUFFIX)
  280. SLIBRARY = $(TARGETDIR)/libst.dll.a
  281. DLIBRARY = $(TARGETDIR)/$(SONAME)
  282. LINKNAME =
  283. # examples directory does not compile under cygwin
  284. EXAMPLES =
  285. endif
  286. # for SRS
  287. # disable examples for ubuntu crossbuild failed.
  288. # @see https://github.com/winlinvip/simple-rtmp-server/issues/308
  289. ifeq ($(OS), LINUX)
  290. EXAMPLES =
  291. endif
  292. ifeq ($(OS), DARWIN)
  293. LINKNAME = libst.$(DSO_SUFFIX)
  294. SONAME = libst.$(MAJOR).$(DSO_SUFFIX)
  295. FULLNAME = libst.$(VERSION).$(DSO_SUFFIX)
  296. endif
  297. ifeq ($(STATIC_ONLY), yes)
  298. LIBRARIES = $(SLIBRARY)
  299. else
  300. LIBRARIES = $(SLIBRARY) $(DLIBRARY)
  301. endif
  302. ifeq ($(OS),)
  303. ST_ALL = unknown
  304. else
  305. ST_ALL = $(TARGETDIR) $(LIBRARIES) $(HEADER) $(EXAMPLES) $(DESC)
  306. endif
  307. all: $(ST_ALL)
  308. unknown:
  309. @echo
  310. @echo "Please specify one of the following targets:"
  311. @echo
  312. @for target in $(TARGETS); do echo $$target; done
  313. @echo
  314. st.pc: st.pc.in
  315. sed "s/@VERSION@/${VERSION}/g" < $< > $@
  316. $(TARGETDIR):
  317. if [ ! -d $(TARGETDIR) ]; then mkdir $(TARGETDIR); fi
  318. $(SLIBRARY): $(OBJS)
  319. $(AR) $(ARFLAGS) $@ $(OBJS)
  320. $(RANLIB) $@
  321. rm -f obj; $(LN) $(LNFLAGS) $(TARGETDIR) obj
  322. $(DLIBRARY): $(OBJS:%.o=%-pic.o)
  323. $(LD) $(LDFLAGS) $^ -o $@
  324. if test "$(LINKNAME)"; then \
  325. cd $(TARGETDIR); \
  326. rm -f $(SONAME) $(LINKNAME); \
  327. $(LN) $(LNFLAGS) $(FULLNAME) $(SONAME); \
  328. $(LN) $(LNFLAGS) $(FULLNAME) $(LINKNAME); \
  329. fi
  330. $(HEADER): public.h
  331. rm -f $@
  332. cp public.h $@
  333. $(TARGETDIR)/md.o: md.S
  334. $(CC) $(CFLAGS) -c $< -o $@
  335. $(TARGETDIR)/md_darwin.o: md_darwin.S
  336. $(CC) $(CFLAGS) -c $< -o $@
  337. $(TARGETDIR)/%.o: %.c common.h md.h
  338. $(CC) $(CFLAGS) -c $< -o $@
  339. examples: $(SLIBRARY)
  340. @echo Making $@
  341. @cd $@; $(MAKE) CC="$(CC)" CFLAGS="$(CFLAGS)" OS="$(OS)" TARGETDIR="$(TARGETDIR)"
  342. clean:
  343. rm -rf *_OPT *_DBG obj st.pc
  344. ##########################
  345. # Pattern rules:
  346. ifneq ($(SFLAGS),)
  347. # Compile with shared library options if it's a C file
  348. $(TARGETDIR)/%-pic.o: %.c common.h md.h
  349. $(CC) $(CFLAGS) $(SFLAGS) -c $< -o $@
  350. endif
  351. # Compile assembly as normal or C as normal if no SFLAGS
  352. %-pic.o: %.o
  353. rm -f $@; $(LN) $(LNFLAGS) $(<F) $@
  354. ##########################
  355. # Target rules:
  356. default-debug:
  357. . ./osguess.sh; $(MAKE) OS="$$OS" BUILD="DBG"
  358. default default-optimized:
  359. . ./osguess.sh; $(MAKE) OS="$$OS" BUILD="OPT"
  360. aix-debug:
  361. $(MAKE) OS="AIX" BUILD="DBG"
  362. aix-optimized:
  363. $(MAKE) OS="AIX" BUILD="OPT"
  364. cygwin-debug:
  365. $(MAKE) OS="CYGWIN" BUILD="DBG"
  366. cygwin-optimized:
  367. $(MAKE) OS="CYGWIN" BUILD="OPT"
  368. darwin-debug:
  369. $(MAKE) OS="DARWIN" BUILD="DBG"
  370. darwin-optimized:
  371. $(MAKE) OS="DARWIN" BUILD="OPT"
  372. freebsd-debug:
  373. $(MAKE) OS="FREEBSD" BUILD="DBG"
  374. freebsd-optimized:
  375. $(MAKE) OS="FREEBSD" BUILD="OPT"
  376. hpux-debug:
  377. $(MAKE) OS="HPUX" BUILD="DBG"
  378. hpux-optimized:
  379. $(MAKE) OS="HPUX" BUILD="OPT"
  380. hpux-64-debug:
  381. $(MAKE) OS="HPUX_64" BUILD="DBG"
  382. hpux-64-optimized:
  383. $(MAKE) OS="HPUX_64" BUILD="OPT"
  384. irix-n32-debug:
  385. $(MAKE) OS="IRIX" BUILD="DBG"
  386. irix-n32-optimized:
  387. $(MAKE) OS="IRIX" BUILD="OPT"
  388. irix-64-debug:
  389. $(MAKE) OS="IRIX_64" BUILD="DBG"
  390. irix-64-optimized:
  391. $(MAKE) OS="IRIX_64" BUILD="OPT"
  392. linux-debug:
  393. $(MAKE) OS="LINUX" BUILD="DBG"
  394. linux-optimized:
  395. $(MAKE) OS="LINUX" BUILD="OPT"
  396. # compatibility
  397. linux-ia64-debug: linux-debug
  398. linux-ia64-optimized: linux-optimized
  399. netbsd-debug:
  400. $(MAKE) OS="NETBSD" BUILD="DBG"
  401. netbsd-optimized:
  402. $(MAKE) OS="NETBSD" BUILD="OPT"
  403. openbsd-debug:
  404. $(MAKE) OS="OPENBSD" BUILD="DBG"
  405. openbsd-optimized:
  406. $(MAKE) OS="OPENBSD" BUILD="OPT"
  407. osf1-debug:
  408. $(MAKE) OS="OSF1" BUILD="DBG"
  409. osf1-optimized:
  410. $(MAKE) OS="OSF1" BUILD="OPT"
  411. solaris-debug:
  412. $(MAKE) OS="SOLARIS" BUILD="DBG"
  413. solaris-optimized:
  414. $(MAKE) OS="SOLARIS" BUILD="OPT"
  415. solaris-64-debug:
  416. $(MAKE) OS="SOLARIS_64" BUILD="DBG"
  417. solaris-64-optimized:
  418. $(MAKE) OS="SOLARIS_64" BUILD="OPT"
  419. ##########################