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.
 
 
 
 

291 lines
9.7 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 textcode.a
  12. all: t $(LIBS) libowfat.a libsocket
  13. CC=gcc
  14. CFLAGS=-pipe -W -Wall -O2 -fomit-frame-pointer
  15. #CFLAGS=-pipe -Os -march=pentiumpro -mcpu=pentiumpro -fomit-frame-pointer -fschedule-insns2 -Wall
  16. CFLAGS += -fstrict-aliasing -Wstrict-aliasing=2
  17. # startrip
  18. ifneq ($(DEBUG),)
  19. CFLAGS=-pipe -Wall -g
  20. endif
  21. path = $(subst :, ,$(PATH))
  22. diet_path = $(foreach dir,$(path),$(wildcard $(dir)/diet))
  23. ifeq ($(strip $(diet_path)),)
  24. ifneq ($(wildcard /opt/diet/bin/diet),)
  25. DIET=/opt/diet/bin/diet
  26. else
  27. DIET=
  28. endif
  29. else
  30. DIET:=$(strip $(diet_path))
  31. endif
  32. ifneq ($(DIET),)
  33. DIETLIBPATH=$(shell $(DIET) -L $(CC))
  34. ifneq ($(wildcard $(DIETLIBPATH)/*ibc.a),)
  35. LIBDIR=$(DIETLIBPATH)
  36. endif
  37. ifneq ($(DEBUG),1)
  38. DIET+=-Os
  39. endif
  40. endif
  41. # to build without diet libc support, use $ make DIET=
  42. # see http://www.fefe.de/dietlibc/ for details about the diet libc
  43. VPATH=str:byte:fmt:scan:uint:open:stralloc:unix:socket:buffer:mmap:textcode:taia:tai:dns:case:array:mult:io
  44. BYTE_OBJS=$(patsubst byte/%.c,%.o,$(wildcard byte/*.c))
  45. FMT_OBJS=$(patsubst fmt/%.c,%.o,$(wildcard fmt/*.c))
  46. SCAN_OBJS=$(patsubst scan/%.c,%.o,$(wildcard scan/*.c))
  47. STR_OBJS=$(patsubst str/%.c,%.o,$(wildcard str/*.c))
  48. UINT_OBJS=$(patsubst uint/%.c,%.o,$(wildcard uint/*.c))
  49. OPEN_OBJS=$(patsubst open/%.c,%.o,$(wildcard open/*.c))
  50. STRALLOC_OBJS=$(patsubst stralloc/%.c,%.o,$(wildcard stralloc/*.c))
  51. UNIX_OBJS=$(patsubst unix/%.c,%.o,$(wildcard unix/*.c))
  52. SOCKET_OBJS=$(patsubst socket/%.c,%.o,$(wildcard socket/*.c))
  53. BUFFER_OBJS=$(patsubst buffer/%.c,%.o,$(wildcard buffer/*.c))
  54. MMAP_OBJS=$(patsubst mmap/%.c,%.o,$(wildcard mmap/*.c))
  55. TEXTCODE_OBJS=$(patsubst textcode/%.c,%.o,$(wildcard textcode/*.c))
  56. TAI_OBJS=$(patsubst tai/%.c,%.o,$(wildcard tai/*.c))
  57. TAIA_OBJS=$(patsubst taia/%.c,%.o,$(wildcard taia/*.c))
  58. DNS_OBJS=$(patsubst dns/%.c,%.o,$(wildcard dns/*.c))
  59. CASE_OBJS=$(patsubst case/%.c,%.o,$(wildcard case/*.c))
  60. ARRAY_OBJS=$(patsubst array/%.c,%.o,$(wildcard array/*.c))
  61. MULT_OBJS=$(patsubst mult/%.c,%.o,$(wildcard mult/*.c))
  62. IO_OBJS=$(patsubst io/%.c,%.o,$(wildcard io/*.c))
  63. $(BYTE_OBJS): byte.h
  64. $(FMT_OBJS): fmt.h
  65. $(SCAN_OBJS): scan.h
  66. $(STR_OBJS): str.h
  67. $(UINT_OBJS): uint16.h uint32.h
  68. $(STRALLOC_OBJS): stralloc.h
  69. $(SOCKET_OBJS): socket.h
  70. $(BUFFER_OBJS): buffer.h
  71. $(MMAP_OBJS): mmap.h open.h
  72. $(TEXTCODE_OBJS): textcode.h
  73. $(TAI_OBJS): tai.h uint64.h
  74. $(TAIA_OBJS): taia.h tai.h uint64.h
  75. $(DNS_OBJS): dns.h stralloc.h taia.h tai.h uint64.h iopause.h
  76. $(CASE_OBJS): case.h
  77. $(ARRAY_OBJS): uint64.h array.h
  78. $(MULT_OBJS): uint64.h uint32.h uint16.h safemult.h
  79. $(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
  80. iob_addbuf.o iob_addfile.o iob_new.o iob_reset.o iob_send.o: iob_internal.h iob.h
  81. iopause.o: select.h
  82. openreadclose.o readclose.o: readclose.h
  83. dns_rcip.o dns_rcrw.o openreadclose.o: openreadclose.h
  84. # stoprip
  85. byte.a: $(BYTE_OBJS)
  86. fmt.a: $(FMT_OBJS)
  87. scan.a: $(SCAN_OBJS)
  88. str.a: $(STR_OBJS)
  89. uint.a: $(UINT_OBJS)
  90. open.a: $(OPEN_OBJS)
  91. stralloc.a: $(STRALLOC_OBJS)
  92. unix.a: $(UNIX_OBJS)
  93. socket.a: $(SOCKET_OBJS)
  94. buffer.a: $(BUFFER_OBJS)
  95. mmap.a: $(MMAP_OBJS)
  96. textcode.a: $(TEXTCODE_OBJS)
  97. taia.a: $(TAIA_OBJS)
  98. tai.a: $(TAI_OBJS)
  99. dns.a: $(DNS_OBJS)
  100. case.a: $(CASE_OBJS)
  101. array.a: $(ARRAY_OBJS)
  102. mult.a: $(MULT_OBJS)
  103. io.a: $(IO_OBJS)
  104. ALL_OBJS=$(DNS_OBJS) $(BYTE_OBJS) $(FMT_OBJS) $(SCAN_OBJS) \
  105. $(STR_OBJS) $(UINT_OBJS) $(OPEN_OBJS) $(STRALLOC_OBJS) $(UNIX_OBJS) \
  106. $(SOCKET_OBJS) $(BUFFER_OBJS) $(MMAP_OBJS) $(TEXTCODE_OBJS) \
  107. $(TAIA_OBJS) $(TAI_OBJS) $(CASE_OBJS) $(ARRAY_OBJS) $(MULT_OBJS) \
  108. $(IO_OBJS)
  109. libowfat.a: $(ALL_OBJS)
  110. ar cr $@ $(ALL_OBJS)
  111. -ranlib $@
  112. CFLAGS+=-I.
  113. %.o: %.c
  114. $(DIET) $(CC) -c $< $(CFLAGS)
  115. %.a:
  116. ar cr $@ $^
  117. -ranlib $@
  118. t.o: iopause.h
  119. t: t.o libowfat.a libsocket
  120. $(DIET) $(CC) -g -o $@ t.o libowfat.a `cat libsocket`
  121. .PHONY: all clean tar install rename
  122. clean:
  123. rm -f *.o *.a *.da *.bbg *.bb core t haveip6.h haven2i.h \
  124. havesl.h haveinline.h iopause.h select.h havekqueue.h haveepoll.h \
  125. libepoll havesigio.h havebsdsf.h havesendfile.h havescope.h havedevpoll.h \
  126. dep libsocket havealloca.h
  127. INCLUDES=buffer.h byte.h fmt.h ip4.h ip6.h mmap.h scan.h socket.h str.h stralloc.h \
  128. uint16.h uint32.h uint64.h open.h textcode.h tai.h taia.h dns.h iopause.h case.h \
  129. openreadclose.h readclose.h ndelay.h array.h io.h safemult.h iob.h havealloca.h \
  130. errmsg.h
  131. install: libowfat.a
  132. install -d $(INCLUDEDIR) $(MAN3DIR) $(LIBDIR)
  133. install -m 644 $(INCLUDES) $(INCLUDEDIR)
  134. install -m 644 $(wildcard */*.3) $(MAN3DIR)
  135. install -m 644 libowfat.a $(LIBDIR)
  136. uninstall:
  137. rm -f $(patsubst %.h,$(INCLUDEDIR)/%.h,$(INCLUDES))
  138. rm -f $(patsubst %.3,$(MAN3DIR)/%.3,$(notdir $(wildcard */*.3)))
  139. rm -f $(LIBDIR)/libowfat.a
  140. VERSION=libowfat-$(shell head -n 1 CHANGES|sed 's/://')
  141. CURNAME=$(notdir $(shell pwd))
  142. tar: Makefile clean rename
  143. rm -f dep libdep
  144. cd ..; tar cvvf $(VERSION).tar.bz2 --use=bzip2 --exclude CVS $(VERSION)
  145. rename:
  146. if test $(CURNAME) != $(VERSION); then cd .. && mv $(CURNAME) $(VERSION); fi
  147. haveip6.h: tryip6.c
  148. -rm -f $@
  149. if $(DIET) $(CC) $(CFLAGS) -c tryip6.c >/dev/null 2>&1; then echo "#define LIBC_HAS_IP6"; fi > $@
  150. -rm -f tryip6.o
  151. havescope.h: tryscope.c
  152. -rm -f $@
  153. if $(DIET) $(CC) $(CFLAGS) -c tryscope.c >/dev/null 2>&1; then echo "#define LIBC_HAS_SCOPE_ID"; fi > $@
  154. -rm -f tryscope.o
  155. haven2i.h: tryn2i.c
  156. -rm -f $@
  157. if $(DIET) $(CC) $(CFLAGS) -o t tryn2i.c >/dev/null 2>&1; then echo "#define HAVE_N2I"; fi > $@
  158. -rm -f t
  159. havesl.h: trysl.c
  160. -rm -f $@
  161. if ! $(DIET) $(CC) $(CFLAGS) -o t trysl.c >/dev/null 2>&1; then echo "typedef int socklen_t;"; fi > $@
  162. -rm -f t
  163. haveinline.h: tryinline.c
  164. -rm -f $@
  165. if ! $(DIET) $(CC) $(CFLAGS) -c tryinline.c >/dev/null 2>&1; then echo "#define inline"; fi > $@
  166. -rm -f tryinline.o
  167. havekqueue.h: trykqueue.c
  168. -rm -f $@
  169. if $(DIET) $(CC) $(CFLAGS) -c trykqueue.c >/dev/null 2>&1; then echo "#define HAVE_KQUEUE"; fi > $@
  170. -rm -f trykqueue.o
  171. havebsdsf.h: trybsdsf.c
  172. -rm -f $@
  173. if $(DIET) $(CC) $(CFLAGS) -o trybsdsf trybsdsf.c >/dev/null 2>&1; then echo "#define HAVE_BSDSENDFILE"; fi > $@
  174. -rm -f trybsdsf.o trybsdsf
  175. havesendfile.h: trysendfile.c
  176. -rm -f $@
  177. if $(DIET) $(CC) $(CFLAGS) -c trysendfile.c >/dev/null 2>&1; then echo "#define HAVE_SENDFILE"; fi > $@
  178. -rm -f trysendfile.o
  179. haveepoll.h: tryepoll.c
  180. -rm -f $@
  181. if $(DIET) $(CC) $(CFLAGS) -o tryepoll tryepoll.c >/dev/null 2>&1; then echo "#define HAVE_EPOLL 1"; else \
  182. if $(DIET) $(CC) $(CFLAGS) -o tryepoll tryepoll.c -lepoll >/dev/null 2>&1; then echo "#define HAVE_EPOLL 2"; fi; fi > $@
  183. -rm -f tryepoll
  184. havedevpoll.h: trydevpoll.c
  185. -rm -f $@
  186. if $(DIET) $(CC) $(CFLAGS) -c trydevpoll.c >/dev/null 2>&1; then echo "#define HAVE_DEVPOLL"; fi > $@
  187. -rm -f trydevpoll.o
  188. libepoll: haveepoll.h
  189. if test "z`cat haveepoll.h`" = "z#define HAVE_EPOLL 2"; then echo -lepoll; fi > $@
  190. havesigio.h: trysigio.c
  191. -rm -f $@
  192. if $(DIET) $(CC) $(CFLAGS) -c trysigio.c >/dev/null 2>&1; then echo "#define HAVE_SIGIO"; fi > $@
  193. -rm -f trysigio.o
  194. havealloca.h: tryalloca.c
  195. -rm -f $@
  196. echo "#include <stdlib.h>" > $@
  197. if $(DIET) $(CC) $(CFLAGS) -c tryalloca.c >/dev/null 2>&1; then echo "#include <alloca.h>"; fi >> $@
  198. -rm -f tryalloca.o
  199. iopause.h: iopause.h1 iopause.h2 trypoll.c
  200. -rm -f $@
  201. if $(DIET) $(CC) $(CFLAGS) -o t trypoll.c >/dev/null 2>&1; then cp iopause.h2 iopause.h; else cp iopause.h1 iopause.h; fi
  202. -rm -f t
  203. select.h: select.h1 select.h2 trysysel.c
  204. -rm -f $@
  205. if $(DIET) $(CC) $(CFLAGS) -c trysysel.c >/dev/null 2>&1; then cp select.h2 select.h; else cp select.h1 select.h; fi
  206. -rm -f trysysel.o
  207. libsocket: trysocket.c
  208. if $(DIET) $(CC) $(CFLAGS) -o trysocket trysocket.c >/dev/null 2>&1; then echo ""; else \
  209. if $(DIET) $(CC) $(CFLAGS) -o trysocket trysocket.c -lsocket >/dev/null 2>&1; then echo "-lsocket"; else \
  210. if $(DIET) $(CC) $(CFLAGS) -o trysocket trysocket.c -lsocket -lnsl >/dev/null 2>&1; then echo "-lsocket -lnsl"; \
  211. fi; fi; fi > blah
  212. if $(DIET) $(CC) $(CFLAGS) -o trysocket trysendfile.c `cat blah`>/dev/null 2>&1; then cat blah; else \
  213. if $(DIET) $(CC) $(CFLAGS) -o trysocket trysendfile.c -lsendfile `cat blah` >/dev/null 2>&1; then echo "-lsendfile"; cat blah; \
  214. fi; fi > libsocket
  215. rm -f blah trysocket
  216. socket_accept6.o socket_connect6.o socket_local6.o socket_mchopcount6.o \
  217. socket_mcjoin6.o socket_mcleave6.o socket_mcloop6.o socket_recv6.o \
  218. socket_remote6.o socket_send6.o socket_tcp6.o socket_udp6.o: haveip6.h havescope.h
  219. socket_getifidx.o socket_getifname.o: haven2i.h
  220. socket_accept4.o socket_accept6.o socket_connected.o socket_local4.o \
  221. socket_local6.o socket_recv4.o socket_recv6.o socket_remote4.o \
  222. socket_remote6.o: havesl.h
  223. dns_nd6.o fmt_xlong.o scan_xlong.o fmt_ip6_flat.o $(TEXTCODE_OBJS): haveinline.h
  224. iob_send.o scan_ip6if.o: havealloca.h
  225. 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
  226. gcc -I. -MM `ls */*.c | grep -v test` t.c | sed -e 's@ \./@ @g' > dep
  227. libdep:
  228. 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
  229. Makefile: GNUmakefile dep libdep
  230. echo "# do not edit! edit GNUmakefile instead" > $@
  231. sed '/startrip/,$$d' < GNUmakefile >> $@
  232. cat dep libdep >> $@
  233. sed -e '1,/stoprip/d' -e 's/ %.c$$//' \
  234. -e 's/^VERSION=.*/'VERSION=$(VERSION)/ \
  235. -e 's/^CURNAME=.*/'CURNAME=$(CURNAME)/ \
  236. -e 's/ Makefile//' < GNUmakefile >> $@