Mirror of :pserver:cvs@cvs.fefe.de:/cvs libowfat https://www.fefe.de/libowfat/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

401 lines
13 KiB

  1. # Warning! There is no real "make install" support.
  2. # The include files are named after the djb, i.e. pretty generic. They
  3. # will probably conflict with other headers. That's why I install them
  4. # in /opt/diet, where they are in the default search path for my diet libc
  5. # work but don't conflict with anything there. YMMV.
  6. prefix=/opt/diet
  7. LIBDIR=${prefix}/lib
  8. INCLUDEDIR=${prefix}/include
  9. MAN3DIR=${prefix}/man/man3
  10. LIBS=byte.a fmt.a scan.a str.a uint.a open.a stralloc.a unix.a socket.a \
  11. buffer.a mmap.a taia.a tai.a dns.a case.a mult.a array.a io.a \
  12. textcode.a cdb.a critbit.a
  13. all: headers ent $(LIBS) libowfat.a libsocket t
  14. pic pie:
  15. $(MAKE) CC="gcc -fPIC" LDFLAGS="-fpie"
  16. picx32 piex32:
  17. $(MAKE) CC="gcc -mx32 -fPIC" LDFLAGS="-fpie"
  18. CROSS=
  19. #CROSS=i686-mingw-
  20. CC?=gcc
  21. CCC=$(CROSS)$(CC)
  22. WERROR=
  23. WARN=-W -Wall -Wextra $(WERROR)
  24. # Use the second version if you are building for a binary that is only
  25. # supposed to run on this machine. It tells gcc to use CPU instructions
  26. # that are specific to the CPU the code is compiled on.
  27. NATIVE=
  28. #NATIVE=-march=native -mtune=native
  29. OPT_REG=-O2
  30. OPT_PLUS=-O3 $(NATIVE)
  31. DEFINE=-D_REENTRANT
  32. CFLAGS=-pipe $(WARN) $(DEFINE) $(OPT_REG)
  33. CFLAGS_OPT=-pipe $(WARN) $(DEFINE) $(OPT_PLUS)
  34. #CFLAGS=-pipe -Os -march=pentiumpro -mcpu=pentiumpro -fomit-frame-pointer -fschedule-insns2 -Wall
  35. ent: ent.c haveuint128.h
  36. $(CC) -g -o ent ent.c -I.
  37. # CFLAGS += -fstrict-aliasing -Wstrict-aliasing=2
  38. # startrip
  39. ifneq ($(DEBUG),)
  40. CFLAGS=-pipe -Wall -g -Og
  41. endif
  42. path = $(subst :, ,$(PATH))
  43. diet_path = $(foreach dir,$(path),$(wildcard $(dir)/diet))
  44. ifeq ($(strip $(diet_path)),)
  45. ifneq ($(wildcard /opt/diet/bin/diet),)
  46. DIET=/opt/diet/bin/diet
  47. else
  48. DIET=
  49. endif
  50. else
  51. DIET:=$(strip $(diet_path))
  52. endif
  53. gcc_path = $(foreach dir,$(path),$(wildcard $(dir)/gcc))
  54. ifeq ($(strip $(gcc_path)),)
  55. CC=clang
  56. else
  57. CC=gcc
  58. endif
  59. ifneq ($(DIET),)
  60. DIETLIBPATH=$(shell $(DIET) -L $(CCC))
  61. ifneq ($(wildcard $(DIETLIBPATH)/*ibc.a),)
  62. LIBDIR=$(DIETLIBPATH)
  63. endif
  64. ifneq ($(DEBUG),1)
  65. DIET+=-Os
  66. endif
  67. endif
  68. # to build without diet libc support, use $ make DIET=
  69. # see http://www.fefe.de/dietlibc/ for details about the diet libc
  70. VPATH=str:byte:fmt:scan:uint:open:stralloc:unix:socket:buffer:mmap:textcode:taia:tai:dns:case:array:mult:io:cdb:critbit
  71. BYTE_OBJS=$(patsubst byte/%.c,%.o,$(wildcard byte/*.c))
  72. FMT_OBJS=$(patsubst fmt/%.c,%.o,$(wildcard fmt/*.c))
  73. SCAN_OBJS=$(patsubst scan/%.c,%.o,$(wildcard scan/*.c))
  74. STR_OBJS=$(patsubst str/%.c,%.o,$(wildcard str/*.c))
  75. UINT_OBJS=$(patsubst uint/%.c,%.o,$(wildcard uint/*.c))
  76. OPEN_OBJS=$(patsubst open/%.c,%.o,$(wildcard open/*.c))
  77. STRALLOC_OBJS=$(patsubst stralloc/%.c,%.o,$(wildcard stralloc/*.c))
  78. UNIX_OBJS=$(patsubst unix/%.c,%.o,$(wildcard unix/*.c))
  79. SOCKET_OBJS=$(patsubst socket/%.c,%.o,$(wildcard socket/*.c))
  80. BUFFER_OBJS=$(patsubst buffer/%.c,%.o,$(wildcard buffer/*.c))
  81. MMAP_OBJS=$(patsubst mmap/%.c,%.o,$(wildcard mmap/*.c))
  82. TEXTCODE_OBJS=$(patsubst textcode/%.c,%.o,$(wildcard textcode/*.c))
  83. TAI_OBJS=$(patsubst tai/%.c,%.o,$(wildcard tai/*.c))
  84. TAIA_OBJS=$(patsubst taia/%.c,%.o,$(wildcard taia/*.c))
  85. DNS_OBJS=$(patsubst dns/%.c,%.o,$(wildcard dns/*.c))
  86. CASE_OBJS=$(patsubst case/%.c,%.o,$(wildcard case/*.c))
  87. ARRAY_OBJS=$(patsubst array/%.c,%.o,$(wildcard array/*.c))
  88. MULT_OBJS=$(patsubst mult/%.c,%.o,$(wildcard mult/*.c))
  89. IO_OBJS=$(patsubst io/%.c,%.o,$(wildcard io/*.c))
  90. CDB_OBJS=$(patsubst cdb/%.c,%.o,$(wildcard cdb/*.c))
  91. CRITBIT_OBJS=$(patsubst critbit/%.c,%.o,$(wildcard critbit/*.c))
  92. $(BYTE_OBJS): byte.h
  93. $(FMT_OBJS): fmt.h
  94. $(SCAN_OBJS): scan.h haveuint128.h
  95. $(STR_OBJS): str.h
  96. $(UINT_OBJS): uint16.h uint32.h
  97. $(STRALLOC_OBJS): stralloc.h
  98. $(SOCKET_OBJS): socket.h
  99. $(BUFFER_OBJS): buffer.h
  100. $(MMAP_OBJS): mmap.h open.h
  101. $(TEXTCODE_OBJS): textcode.h
  102. $(TAI_OBJS): tai.h uint64.h
  103. $(TAIA_OBJS): taia.h tai.h uint64.h
  104. $(DNS_OBJS): dns.h stralloc.h taia.h tai.h uint64.h iopause.h
  105. $(CASE_OBJS): case.h
  106. $(ARRAY_OBJS): uint64.h array.h
  107. $(MULT_OBJS): uint64.h uint32.h uint16.h safemult.h
  108. $(IO_OBJS): uint64.h array.h io.h io_internal.h taia.h tai.h haveepoll.h havekqueue.h havesigio.h havebsdsf.h havedevpoll.h havesendfile.h
  109. $(CDB_OBJS): cdb.h uint32.h
  110. $(CRITBIT_OBJS): critbit.h
  111. mult64.o: haveuint128.h
  112. iob_addbuf.o iob_addfile.o iob_new.o iob_reset.o iob_send.o: iob_internal.h iob.h
  113. iopause.o: iopause.h select.h
  114. openreadclose.o readclose.o: readclose.h
  115. dns_rcip.o dns_rcrw.o openreadclose.o: openreadclose.h
  116. iob_send.o scan_ip6if.o: havealloca.h
  117. cdb.o io_mmapwritefile.o: havepread.h
  118. # stoprip
  119. byte.a: $(BYTE_OBJS)
  120. fmt.a: $(FMT_OBJS)
  121. scan.a: $(SCAN_OBJS)
  122. str.a: $(STR_OBJS)
  123. uint.a: $(UINT_OBJS)
  124. open.a: $(OPEN_OBJS)
  125. stralloc.a: $(STRALLOC_OBJS)
  126. unix.a: $(UNIX_OBJS)
  127. socket.a: $(SOCKET_OBJS)
  128. buffer.a: $(BUFFER_OBJS)
  129. mmap.a: $(MMAP_OBJS)
  130. textcode.a: $(TEXTCODE_OBJS)
  131. taia.a: $(TAIA_OBJS)
  132. tai.a: $(TAI_OBJS)
  133. dns.a: $(DNS_OBJS)
  134. case.a: $(CASE_OBJS)
  135. array.a: $(ARRAY_OBJS)
  136. mult.a: $(MULT_OBJS)
  137. io.a: $(IO_OBJS)
  138. cdb.a: $(CDB_OBJS)
  139. critbit.a: $(CRITBIT_OBJS)
  140. ALL_OBJS=$(DNS_OBJS) $(BYTE_OBJS) $(FMT_OBJS) $(SCAN_OBJS) \
  141. $(STR_OBJS) $(UINT_OBJS) $(OPEN_OBJS) $(STRALLOC_OBJS) $(UNIX_OBJS) \
  142. $(SOCKET_OBJS) $(BUFFER_OBJS) $(MMAP_OBJS) $(TEXTCODE_OBJS) \
  143. $(TAIA_OBJS) $(TAI_OBJS) $(CASE_OBJS) $(ARRAY_OBJS) $(MULT_OBJS) \
  144. $(IO_OBJS) $(CDB_OBJS) $(CRITBIT_OBJS)
  145. libowfat.a: $(ALL_OBJS)
  146. $(CROSS)ar cru $@ $(ALL_OBJS)
  147. -$(CROSS)ranlib $@
  148. CFLAGS+=-I.
  149. CFLAGS_OPT+=-I.
  150. %.o: byte/%.c
  151. $(DIET) $(CCC) -c $< $(CFLAGS_OPT)
  152. %.o: %.c
  153. $(DIET) $(CCC) -c $< $(CFLAGS)
  154. %.a:
  155. $(CROSS)ar cru $@ $^
  156. -$(CROSS)ranlib $@
  157. t.o: t.c fmt.h scan.h str.h uint16.h uint32.h stralloc.h socket.h \
  158. buffer.h ip4.h ip6.h byte.h mmap.h open.h textcode.h dns.h iopause.h \
  159. taia.h tai.h uint64.h case.h errmsg.h iob.h io.h array.h safemult.h \
  160. iarray.h io_internal.h haveepoll.h havekqueue.h havedevpoll.h \
  161. havesigio.h CAS.h
  162. t: t.o libowfat.a libsocket
  163. $(DIET) $(CCC) -g -o $@ t.o libowfat.a `cat libsocket` -lpthread $(LDFLAGS)
  164. .PHONY: all clean tar install rename
  165. clean:
  166. rm -f *.o *.obj *.a *.lib *.da *.bbg *.bb core t haveip6.h haven2i.h \
  167. havesl.h haveinline.h iopause.h select.h havekqueue.h haveepoll.h \
  168. libepoll havesigio.h havebsdsf.h havesendfile.h havescope.h havedevpoll.h \
  169. dep libsocket havealloca.h haveuint128.h entities.h ent havepread.h
  170. INCLUDES=buffer.h byte.h fmt.h ip4.h ip6.h mmap.h scan.h socket.h str.h stralloc.h \
  171. uint16.h uint32.h uint64.h open.h textcode.h tai.h taia.h dns.h iopause.h case.h \
  172. openreadclose.h readclose.h ndelay.h array.h io.h safemult.h iob.h havealloca.h \
  173. errmsg.h cdb.h cdb_make.h rangecheck.h iarray.h va_narg.h isset.h \
  174. compiletimeassert.h critbit.h
  175. libowfat:
  176. -mkdir libowfat
  177. .PHONY: headers
  178. headers: libowfat $(INCLUDES)
  179. ln -f $(INCLUDES) libowfat/
  180. install-inc:
  181. install -d $(DESTDIR)$(INCLUDEDIR)/libowfat
  182. install -m 644 $(INCLUDES) $(DESTDIR)$(INCLUDEDIR)/libowfat
  183. install-lib: libowfat.a
  184. install -d $(DESTDIR)$(LIBDIR)
  185. install -m 644 libowfat.a $(DESTDIR)$(LIBDIR)
  186. install-man:
  187. install -d $(DESTDIR)$(MAN3DIR)
  188. install -m 644 $(wildcard */*.3) $(DESTDIR)$(MAN3DIR)
  189. install: headers install-inc install-man install-lib
  190. uninstall:
  191. rm -f $(patsubst %.h,$(INCLUDEDIR)/%.h,$(INCLUDES))
  192. rm -f $(INCLUDEDIR)/libowfat/*.h
  193. test -d $(INCLUDEDIR)/libowfat && rmdir $(INCLUDEDIR)/libowfat
  194. rm -f $(patsubst %.3,$(MAN3DIR)/%.3,$(notdir $(wildcard */*.3)))
  195. rm -f $(LIBDIR)/libowfat.a
  196. VERSION=libowfat-$(shell head -n 1 CHANGES|sed 's/://')
  197. CURNAME=$(notdir $(shell pwd))
  198. tar: Makefile clean rename
  199. rm -f dep libdep
  200. cd ..; tar cvvf $(VERSION).tar.xz --use=xz --exclude CVS $(VERSION)
  201. rename:
  202. if test $(CURNAME) != $(VERSION); then cd .. && mv $(CURNAME) $(VERSION); fi
  203. haveip6.h: tryip6.c
  204. -rm -f $@
  205. if $(DIET) $(CCC) $(CFLAGS) -c tryip6.c >/dev/null 2>&1; then echo "#define LIBC_HAS_IP6"; fi > $@
  206. -rm -f tryip6.o
  207. havescope.h: tryscope.c
  208. -rm -f $@
  209. if $(DIET) $(CCC) $(CFLAGS) -c tryscope.c >/dev/null 2>&1; then echo "#define LIBC_HAS_SCOPE_ID"; fi > $@
  210. -rm -f tryscope.o
  211. haven2i.h: tryn2i.c
  212. -rm -f $@
  213. if $(DIET) $(CCC) $(CFLAGS) -o t tryn2i.c >/dev/null 2>&1; then echo "#define HAVE_N2I"; fi > $@
  214. -rm -f t
  215. havesl.h: trysl.c
  216. -rm -f $@
  217. if ! $(DIET) $(CCC) $(CFLAGS) -o t trysl.c >/dev/null 2>&1; then echo "typedef int socklen_t;"; fi > $@
  218. -rm -f t
  219. haveinline.h: tryinline.c
  220. -rm -f $@
  221. if ! $(DIET) $(CCC) $(CFLAGS) -c tryinline.c >/dev/null 2>&1; then echo "#define inline"; fi > $@
  222. -rm -f tryinline.o
  223. havekqueue.h: trykqueue.c
  224. -rm -f $@
  225. if $(DIET) $(CCC) $(CFLAGS) -c trykqueue.c >/dev/null 2>&1; then echo "#define HAVE_KQUEUE"; fi > $@
  226. -rm -f trykqueue.o
  227. havebsdsf.h: trybsdsf.c
  228. -rm -f $@
  229. if $(DIET) $(CCC) $(CFLAGS) -o trybsdsf trybsdsf.c >/dev/null 2>&1; then echo "#define HAVE_BSDSENDFILE"; fi > $@
  230. -rm -f trybsdsf.o trybsdsf
  231. havesendfile.h: trysendfile.c
  232. -rm -f $@
  233. if $(DIET) $(CCC) $(CFLAGS) -c trysendfile.c >/dev/null 2>&1; then echo "#define HAVE_SENDFILE"; fi > $@
  234. -rm -f trysendfile.o
  235. haveepoll.h: tryepoll.c
  236. -rm -f $@
  237. if $(DIET) $(CCC) $(CFLAGS) -o tryepoll tryepoll.c >/dev/null 2>&1; then echo "#define HAVE_EPOLL 1"; else \
  238. if $(DIET) $(CCC) $(CFLAGS) -o tryepoll tryepoll.c -lepoll >/dev/null 2>&1; then echo "#define HAVE_EPOLL 2"; fi; fi > $@
  239. -rm -f tryepoll
  240. havedevpoll.h: trydevpoll.c
  241. -rm -f $@
  242. if $(DIET) $(CCC) $(CFLAGS) -c trydevpoll.c >/dev/null 2>&1; then echo "#define HAVE_DEVPOLL"; fi > $@
  243. -rm -f trydevpoll.o
  244. libepoll: haveepoll.h
  245. if test "z`cat haveepoll.h`" = "z#define HAVE_EPOLL 2"; then echo -lepoll; fi > $@
  246. havesigio.h: trysigio.c
  247. -rm -f $@
  248. if $(DIET) $(CCC) $(CFLAGS) -c trysigio.c >/dev/null 2>&1; then echo "#define HAVE_SIGIO"; fi > $@
  249. -rm -f trysigio.o
  250. havealloca.h: tryalloca.c
  251. -rm -f $@
  252. echo "#include <stdlib.h>" > $@
  253. if $(DIET) $(CCC) $(CFLAGS) -c tryalloca.c -DA >/dev/null 2>&1; then echo "#include <alloca.h>"; fi >> $@
  254. if $(DIET) $(CCC) $(CFLAGS) -c tryalloca.c -DB >/dev/null 2>&1; then echo "#include <malloc.h>"; fi >> $@
  255. -rm -f tryalloca.o
  256. haveuint128.h: tryuint128.c
  257. -rm -f $@
  258. if $(DIET) $(CCC) $(CFLAGS) -c tryuint128.c >/dev/null 2>&1; then echo "#define HAVE_UINT128"; fi > $@
  259. -rm -f tryuint128.o
  260. havepread.h: trypread.c
  261. -rm -f $@
  262. if $(DIET) $(CCC) $(CFLAGS) -c trypread.c >/dev/null 2>&1; then echo "#define HAVE_PREAD"; fi > $@
  263. -rm -f trypread.o
  264. iopause.h: iopause.h1 iopause.h2 trypoll.c
  265. -rm -f $@
  266. if $(DIET) $(CCC) $(CFLAGS) -o t trypoll.c >/dev/null 2>&1; then cp iopause.h2 iopause.h; else cp iopause.h1 iopause.h; fi
  267. -rm -f t
  268. select.h: select.h1 select.h2 trysysel.c
  269. -rm -f $@
  270. if $(DIET) $(CCC) $(CFLAGS) -c trysysel.c >/dev/null 2>&1; then cp select.h2 select.h; else cp select.h1 select.h; fi
  271. -rm -f trysysel.o
  272. libsocket: trysocket.c
  273. if $(DIET) $(CCC) $(CFLAGS) -o trysocket trysocket.c >/dev/null 2>&1; then echo ""; else \
  274. if $(DIET) $(CCC) $(CFLAGS) -o trysocket trysocket.c -lsocket >/dev/null 2>&1; then echo "-lsocket"; else \
  275. if $(DIET) $(CCC) $(CFLAGS) -o trysocket trysocket.c -lsocket -lnsl >/dev/null 2>&1; then echo "-lsocket -lnsl"; \
  276. fi; fi; fi > blah
  277. if $(DIET) $(CCC) $(CFLAGS) -o trysocket trysendfile.c `cat blah`>/dev/null 2>&1; then cat blah; else \
  278. if $(DIET) $(CCC) $(CFLAGS) -o trysocket trysendfile.c -lsendfile `cat blah` >/dev/null 2>&1; then echo "-lsendfile"; cat blah; \
  279. fi; fi > libsocket
  280. rm -f blah trysocket
  281. socket_accept6.o socket_bind6.o socket_connect6.o socket_local6.o \
  282. socket_mchopcount6.o socket_mcjoin6.o socket_mcleave6.o socket_mcloop6.o \
  283. socket_recv6.o socket_remote6.o socket_sctp6b.o socket_send6.o \
  284. socket_tcp6b.o socket_tcp6.o socket_udp6.o: haveip6.h
  285. socket_accept6.o socket_connect6.o socket_local6.o socket_recv6.o \
  286. socket_remote6.o socket_send6.o: havescope.h
  287. socket_getifidx.o socket_getifname.o: haven2i.h
  288. socket_accept4.o socket_accept6.o socket_connected.o socket_local4.o \
  289. socket_local6.o socket_recv4.o socket_recv6.o socket_remote4.o \
  290. socket_remote6.o: havesl.h
  291. dns_nd6.o fmt_xlong.o scan_xlong.o fmt_ip6_flat.o $(TEXTCODE_OBJS): haveinline.h
  292. iob_send.o scan_ip6if.o: havealloca.h
  293. dep: haveip6.h haven2i.h havesl.h haveinline.h iopause.h select.h haveepoll.h havekqueue.h havedevpoll.h havescope.h havesigio.h havebsdsf.h havesendfile.h havealloca.h haveuint128.h entities.h havepread.h
  294. $(CC) -I. -MM `ls */*.c | grep -v test` t.c | sed -e 's@ \./@ @g' > dep
  295. libdep:
  296. for i in $(LIBS); do (echo -n $$i|tr a-z A-Z|sed 's/.A$$/_OBJS=/'; echo $${i%.a}/*.c|sed -e 's@[^/]*/\([^.]*\)\.c@\1.o @g'); done > libdep
  297. Makefile: GNUmakefile dep libdep
  298. echo "# do not edit! edit GNUmakefile instead" > $@
  299. sed '/startrip/,$$d' < GNUmakefile >> $@
  300. cat dep libdep >> $@
  301. sed -e '1,/stoprip/d' -e 's/ %.c$$//' \
  302. -e 's/^VERSION=.*/'VERSION=$(VERSION)/ \
  303. -e 's/^CURNAME=.*/'CURNAME=$(CURNAME)/ \
  304. -e 's/ Makefile//' < GNUmakefile >> $@
  305. windoze:
  306. $(MAKE) DIET= CROSS=i686-mingw32-
  307. windoze64:
  308. $(MAKE) DIET= CROSS=x86_64-mingw32-
  309. update:
  310. dl -n http://www.w3.org/TR/html5/entities.json
  311. entities.h: entities.json ent
  312. ./ent
  313. scan_html.o: entities.h
  314. sa1:
  315. $(MAKE) clean
  316. scan-build $(MAKE) DIET= -j8
  317. sa2:
  318. $(MAKE) clean
  319. $(MAKE) DIET= CC="gcc -fanalyzer" -j8