Makefile 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  1. ##
  2. ## Please check the configurion parameters below
  3. ##
  4. ## Installation directory. By default, go in /usr/local.
  5. ## Distributions should probably use /, but they probably know better...
  6. ifndef PREFIX
  7. PREFIX = /usr/local
  8. endif
  9. ## Compiler to use (modify this for cross compile).
  10. CC = gcc
  11. ## Other tools you need to modify for cross compile (static lib only).
  12. AR = ar
  13. RANLIB = ranlib
  14. ## Uncomment this to build tools using static version of the library.
  15. ## Mostly useful for embedded platforms without ldd, or to create
  16. ## a local version (non-root).
  17. # BUILD_STATIC = y
  18. ## Uncomment this to build without using libm (less efficient).
  19. ## This is mostly useful for embedded platforms without maths.
  20. # BUILD_NOLIBM = y
  21. ## Uncomment this to strip binary from symbols. This reduce binary size.
  22. ## by a few percent but make debug worse...
  23. # BUILD_STRIPPING = y
  24. ## Uncomment this to build with only essential functionality.
  25. ## This leaves out the less used features and cut in half the tools.
  26. ## This is mostly useful for embedded platforms without limited feature needs.
  27. # BUILD_WE_ESSENTIAL = y
  28. # ***************************************************************************
  29. # ***** Most users should not need to change anything beyond this point *****
  30. # ***************************************************************************
  31. # Version of the Wireless Tools
  32. WT_VERSION := $(shell sed -ne "/WT_VERSION/{s:\([^0-9]*\)::;p;q;}" < iwlib.h )
  33. # Version of Wireless Extensions.
  34. WE_VERSION := $(shell sed -ne "/WE_VERSION/{s:\([^0-9]*\)::;p;q;}" < iwlib.h )
  35. # Always use local header for wireless extensions
  36. WEXT_HEADER = wireless.$(WE_VERSION).h
  37. # Targets to build
  38. STATIC=libiw.a
  39. DYNAMIC=libiw.so.$(WT_VERSION)
  40. PROGS= iwconfig iwlist iwpriv iwspy iwgetid iwevent ifrename
  41. MANPAGES8=iwconfig.8 iwlist.8 iwpriv.8 iwspy.8 iwgetid.8 iwevent.8 ifrename.8
  42. MANPAGES7=wireless.7
  43. MANPAGES5=iftab.5
  44. EXTRAPROGS= macaddr iwmulticall
  45. # Composition of the library :
  46. OBJS = iwlib.o
  47. # Select which library to build and to link tool with
  48. ifdef BUILD_STATIC
  49. IWLIB=$(STATIC)
  50. IWLIB_INSTALL=install-static
  51. else
  52. IWLIB=$(DYNAMIC)
  53. IWLIB_INSTALL=install-dynamic
  54. endif
  55. # Standard name for dynamic library so that the dynamic linker can pick it.
  56. # We will just create a symbolic link to the real thing.
  57. DYNAMIC_LINK= libiw.so
  58. # Install directories
  59. INSTALL_DIR= $(PREFIX)/sbin/
  60. INSTALL_LIB= $(PREFIX)/lib/
  61. INSTALL_INC= $(PREFIX)/include/
  62. INSTALL_MAN= $(PREFIX)/man/
  63. # Various commands
  64. RM = rm -f
  65. RM_CMD = $(RM) *.BAK *.bak *.d *.o *.so ,* *~ *.a *.orig *.rej *.out
  66. LDCONFIG = ldconfig
  67. # Do we want to build with or without libm ?
  68. ifdef BUILD_NOLIBM
  69. LIBS=
  70. WELIB_FLAG= -DWE_NOLIBM=y
  71. else
  72. LIBS= -lm
  73. endif
  74. # Stripping or not ?
  75. ifdef BUILD_STRIPPING
  76. STRIPFLAGS= -Wl,-s
  77. else
  78. STRIPFLAGS=
  79. endif
  80. # Do we want to build with only essential functionality ?
  81. ifdef BUILD_WE_ESSENTIAL
  82. WEDEF_FLAG= -DWE_ESSENTIAL=y
  83. endif
  84. # Other flags
  85. CFLAGS=-Os -W -Wall -Wstrict-prototypes -Wmissing-prototypes -Wshadow \
  86. -Wpointer-arith -Wcast-qual -Winline -I.
  87. #CFLAGS=-O2 -W -Wall -Wstrict-prototypes -I.
  88. DEPFLAGS=-MMD
  89. XCFLAGS=$(CFLAGS) $(DEPFLAGS) $(WARN) $(HEADERS) $(WELIB_FLAG) $(WEDEF_FLAG)
  90. PICFLAG=-fPIC
  91. # Standard compilation targets
  92. all:: $(IWLIB) $(PROGS)
  93. %: %.o
  94. $(CC) $(LDFLAGS) $(STRIPFLAGS) $(XCFLAGS) -o $@ $^ $(LIBS)
  95. %.o: %.c wireless.h
  96. $(CC) $(XCFLAGS) -c $<
  97. %.so: %.c wireless.h
  98. $(CC) $(XCFLAGS) $(PICFLAG) -c -o $@ $<
  99. iwconfig: iwconfig.o $(IWLIB)
  100. iwlist: iwlist.o $(IWLIB)
  101. iwpriv: iwpriv.o $(IWLIB)
  102. iwspy: iwspy.o $(IWLIB)
  103. iwgetid: iwgetid.o $(IWLIB)
  104. iwevent: iwevent.o $(IWLIB)
  105. ifrename: ifrename.o $(IWLIB)
  106. macaddr: macaddr.o $(IWLIB)
  107. # Always do symbol stripping here
  108. iwmulticall: iwmulticall.o
  109. $(CC) $(LDFLAGS) -Wl,-s $(XCFLAGS) -o $@ $^ $(LIBS)
  110. # It's a kind of magic...
  111. wireless.h:
  112. cp $(WEXT_HEADER) wireless.h
  113. # Compilation of the dynamic library
  114. $(DYNAMIC): $(OBJS:.o=.so)
  115. $(CC) -shared -o $@ -Wl,-soname,$@ $(STRIPFLAGS) $(LIBS) -lc $^
  116. # Compilation of the static library
  117. $(STATIC): $(OBJS:.o=.so)
  118. $(RM) $@
  119. $(AR) cru $@ $^
  120. $(RANLIB) $@
  121. # Installation : So crude but so effective ;-)
  122. # Less crude thanks to many contributions ;-)
  123. install:: $(IWLIB_INSTALL) install-bin install-hdr install-man
  124. # Install the dynamic library
  125. install-dynamic:: $(DYNAMIC)
  126. install -m 755 -d $(INSTALL_LIB)
  127. install -m 755 $(DYNAMIC) $(INSTALL_LIB)
  128. ln -sfn $(DYNAMIC) $(INSTALL_LIB)/$(DYNAMIC_LINK)
  129. @echo "*** Don't forget to add $(INSTALL_LIB) to /etc/ld.so.conf, and run ldconfig as root. ***"
  130. @$(LDCONFIG) || echo "*** Could not run ldconfig ! ***"
  131. # Install the static library
  132. install-static:: $(STATIC)
  133. install -m 755 -d $(INSTALL_LIB)
  134. install -m 644 $(STATIC) $(INSTALL_LIB)
  135. # All the binaries. Careful, no dependancy on install-dynamic
  136. install-bin:: all
  137. install -m 755 -d $(INSTALL_DIR)
  138. install -m 755 $(PROGS) $(INSTALL_DIR)
  139. # Headers to go with the wireless lib (dev)
  140. install-hdr:: wireless.h
  141. install -m 755 -d $(INSTALL_INC)
  142. install -m 644 iwlib.h $(INSTALL_INC)
  143. install -m 644 wireless.h $(INSTALL_INC)
  144. # How could you live without those manapages ?
  145. install-man::
  146. install -m 755 -d $(INSTALL_MAN)/man8/
  147. install -m 644 $(MANPAGES8) $(INSTALL_MAN)/man8/
  148. install -m 755 -d $(INSTALL_MAN)/man7/
  149. install -m 644 $(MANPAGES7) $(INSTALL_MAN)/man7/
  150. install -m 755 -d $(INSTALL_MAN)/man5/
  151. install -m 644 $(MANPAGES5) $(INSTALL_MAN)/man5/
  152. install-iwmulticall:: iwmulticall
  153. install -m 755 -d $(INSTALL_DIR)
  154. install -m 755 $< $(INSTALL_DIR)/iwconfig
  155. ( cd $(INSTALL_DIR) ; \
  156. ln -f -s iwconfig iwlist ; \
  157. ln -f -s iwconfig iwspy ; \
  158. ln -f -s iwconfig iwpriv ; \
  159. ln -f -s iwconfig iwgetid )
  160. clean::
  161. $(RM_CMD)
  162. realclean::
  163. $(RM_CMD)
  164. $(RM) $(STATIC) $(DYNAMIC) $(PROGS) $(EXTRAPROGS) libiw* wireless.h
  165. uninstall::
  166. for f in $(PROGS); do \
  167. $(RM) $(INSTALL_DIR)/$$f; \
  168. done
  169. $(RM) $(INSTALL_LIB)/$(STATIC)
  170. $(RM) $(INSTALL_LIB)/$(DYNAMIC)
  171. $(RM) $(INSTALL_LIB)/$(DYNAMIC_LINK)
  172. $(RM) $(INSTALL_INC)/iwlib.h
  173. $(RM) $(INSTALL_INC)/wireless.h
  174. for f in $(MANPAGES8); do \
  175. $(RM) $(INSTALL_MAN)/man8/$$f; \
  176. done
  177. for f in $(MANPAGES7); do \
  178. $(RM) $(INSTALL_MAN)/man7/$$f; \
  179. done
  180. for f in $(MANPAGES5); do \
  181. $(RM) $(INSTALL_MAN)/man5/$$f; \
  182. done
  183. # Include dependancies
  184. -include *.d