2
0

Makefile 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480
  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. ##########################
  260. CFLAGS += $(DEFINES) $(OTHER_FLAGS) $(EXTRA_CFLAGS)
  261. OBJS = $(TARGETDIR)/sched.o \
  262. $(TARGETDIR)/stk.o \
  263. $(TARGETDIR)/sync.o \
  264. $(TARGETDIR)/key.o \
  265. $(TARGETDIR)/io.o \
  266. $(TARGETDIR)/event.o
  267. OBJS += $(EXTRA_OBJS)
  268. HEADER = $(TARGETDIR)/st.h
  269. SLIBRARY = $(TARGETDIR)/libst.a
  270. DLIBRARY = $(TARGETDIR)/libst.$(DSO_SUFFIX).$(VERSION)
  271. EXAMPLES = examples
  272. LINKNAME = libst.$(DSO_SUFFIX)
  273. SONAME = libst.$(DSO_SUFFIX).$(MAJOR)
  274. FULLNAME = libst.$(DSO_SUFFIX).$(VERSION)
  275. ifeq ($(OS), CYGWIN)
  276. SONAME = cygst.$(DSO_SUFFIX)
  277. SLIBRARY = $(TARGETDIR)/libst.dll.a
  278. DLIBRARY = $(TARGETDIR)/$(SONAME)
  279. LINKNAME =
  280. # examples directory does not compile under cygwin
  281. EXAMPLES =
  282. endif
  283. # for SRS
  284. # disable examples for ubuntu crossbuild failed.
  285. # @see https://github.com/winlinvip/simple-rtmp-server/issues/308
  286. ifeq ($(OS), LINUX)
  287. EXAMPLES =
  288. endif
  289. ifeq ($(OS), DARWIN)
  290. LINKNAME = libst.$(DSO_SUFFIX)
  291. SONAME = libst.$(MAJOR).$(DSO_SUFFIX)
  292. FULLNAME = libst.$(VERSION).$(DSO_SUFFIX)
  293. endif
  294. ifeq ($(STATIC_ONLY), yes)
  295. LIBRARIES = $(SLIBRARY)
  296. else
  297. LIBRARIES = $(SLIBRARY) $(DLIBRARY)
  298. endif
  299. ifeq ($(OS),)
  300. ST_ALL = unknown
  301. else
  302. ST_ALL = $(TARGETDIR) $(LIBRARIES) $(HEADER) $(EXAMPLES) $(DESC)
  303. endif
  304. all: $(ST_ALL)
  305. unknown:
  306. @echo
  307. @echo "Please specify one of the following targets:"
  308. @echo
  309. @for target in $(TARGETS); do echo $$target; done
  310. @echo
  311. st.pc: st.pc.in
  312. sed "s/@VERSION@/${VERSION}/g" < $< > $@
  313. $(TARGETDIR):
  314. if [ ! -d $(TARGETDIR) ]; then mkdir $(TARGETDIR); fi
  315. $(SLIBRARY): $(OBJS)
  316. $(AR) $(ARFLAGS) $@ $(OBJS)
  317. $(RANLIB) $@
  318. rm -f obj; $(LN) $(LNFLAGS) $(TARGETDIR) obj
  319. $(DLIBRARY): $(OBJS:%.o=%-pic.o)
  320. $(LD) $(LDFLAGS) $^ -o $@
  321. if test "$(LINKNAME)"; then \
  322. cd $(TARGETDIR); \
  323. rm -f $(SONAME) $(LINKNAME); \
  324. $(LN) $(LNFLAGS) $(FULLNAME) $(SONAME); \
  325. $(LN) $(LNFLAGS) $(FULLNAME) $(LINKNAME); \
  326. fi
  327. $(HEADER): public.h
  328. rm -f $@
  329. cp public.h $@
  330. $(TARGETDIR)/md.o: md.S
  331. $(CC) $(CFLAGS) -c $< -o $@
  332. $(TARGETDIR)/md_darwin.o: md_darwin.S
  333. $(CC) $(CFLAGS) -c $< -o $@
  334. $(TARGETDIR)/%.o: %.c common.h md.h
  335. $(CC) $(CFLAGS) -c $< -o $@
  336. examples: $(SLIBRARY)
  337. @echo Making $@
  338. @cd $@; $(MAKE) CC="$(CC)" CFLAGS="$(CFLAGS)" OS="$(OS)" TARGETDIR="$(TARGETDIR)"
  339. clean:
  340. rm -rf *_OPT *_DBG obj st.pc
  341. ##########################
  342. # Pattern rules:
  343. ifneq ($(SFLAGS),)
  344. # Compile with shared library options if it's a C file
  345. $(TARGETDIR)/%-pic.o: %.c common.h md.h
  346. $(CC) $(CFLAGS) $(SFLAGS) -c $< -o $@
  347. endif
  348. # Compile assembly as normal or C as normal if no SFLAGS
  349. %-pic.o: %.o
  350. rm -f $@; $(LN) $(LNFLAGS) $(<F) $@
  351. ##########################
  352. # Target rules:
  353. default-debug:
  354. . ./osguess.sh; $(MAKE) OS="$$OS" BUILD="DBG"
  355. default default-optimized:
  356. . ./osguess.sh; $(MAKE) OS="$$OS" BUILD="OPT"
  357. aix-debug:
  358. $(MAKE) OS="AIX" BUILD="DBG"
  359. aix-optimized:
  360. $(MAKE) OS="AIX" BUILD="OPT"
  361. cygwin-debug:
  362. $(MAKE) OS="CYGWIN" BUILD="DBG"
  363. cygwin-optimized:
  364. $(MAKE) OS="CYGWIN" BUILD="OPT"
  365. darwin-debug:
  366. $(MAKE) OS="DARWIN" BUILD="DBG"
  367. darwin-optimized:
  368. $(MAKE) OS="DARWIN" BUILD="OPT"
  369. freebsd-debug:
  370. $(MAKE) OS="FREEBSD" BUILD="DBG"
  371. freebsd-optimized:
  372. $(MAKE) OS="FREEBSD" BUILD="OPT"
  373. hpux-debug:
  374. $(MAKE) OS="HPUX" BUILD="DBG"
  375. hpux-optimized:
  376. $(MAKE) OS="HPUX" BUILD="OPT"
  377. hpux-64-debug:
  378. $(MAKE) OS="HPUX_64" BUILD="DBG"
  379. hpux-64-optimized:
  380. $(MAKE) OS="HPUX_64" BUILD="OPT"
  381. irix-n32-debug:
  382. $(MAKE) OS="IRIX" BUILD="DBG"
  383. irix-n32-optimized:
  384. $(MAKE) OS="IRIX" BUILD="OPT"
  385. irix-64-debug:
  386. $(MAKE) OS="IRIX_64" BUILD="DBG"
  387. irix-64-optimized:
  388. $(MAKE) OS="IRIX_64" BUILD="OPT"
  389. linux-debug:
  390. $(MAKE) OS="LINUX" BUILD="DBG"
  391. linux-optimized:
  392. $(MAKE) OS="LINUX" BUILD="OPT"
  393. # compatibility
  394. linux-ia64-debug: linux-debug
  395. linux-ia64-optimized: linux-optimized
  396. netbsd-debug:
  397. $(MAKE) OS="NETBSD" BUILD="DBG"
  398. netbsd-optimized:
  399. $(MAKE) OS="NETBSD" BUILD="OPT"
  400. openbsd-debug:
  401. $(MAKE) OS="OPENBSD" BUILD="DBG"
  402. openbsd-optimized:
  403. $(MAKE) OS="OPENBSD" BUILD="OPT"
  404. osf1-debug:
  405. $(MAKE) OS="OSF1" BUILD="DBG"
  406. osf1-optimized:
  407. $(MAKE) OS="OSF1" BUILD="OPT"
  408. solaris-debug:
  409. $(MAKE) OS="SOLARIS" BUILD="DBG"
  410. solaris-optimized:
  411. $(MAKE) OS="SOLARIS" BUILD="OPT"
  412. solaris-64-debug:
  413. $(MAKE) OS="SOLARIS_64" BUILD="DBG"
  414. solaris-64-optimized:
  415. $(MAKE) OS="SOLARIS_64" BUILD="OPT"
  416. ##########################