OSDN Git Service

v24
[android-x86/external-wireless-tools.git] / wireless_tools / Makefile
index b7f7550..5de0c9a 100644 (file)
@@ -3,28 +3,32 @@
 #
 
 # Targets to build
-PROGS= iwconfig iwlist iwpriv iwspy iwgetid
+STATIC=libiw.a
+DYNAMIC=libiw.so.24
+PROGS= iwconfig iwlist iwpriv iwspy iwgetid iwevent
+MANPAGES=iwconfig.8 iwlist.8 iwpriv.8 iwspy.8 iwgetid.8 iwevent.8
 
-# Installation directory. By default, go in local.
-# Distributions should probably use /usr/sbin, but they probably know better...
-INSTALL_DIR= /usr/local/sbin
+# Composition of the library :
+OBJS = iwlib.o
 
-# This is our header selection. Try to hide the mess and the misery :-(
-# Please choose *only one* of the define...
+# Define if tools should be built using static or dynamic version of the lib
+IWLIB=$(STATIC)
+#IWLIB=$(DYNAMIC)
 
-# Kernel headers 2.4.X + Glibc 2.2 - Mandrake 8.0 */
-#HEADERS= -DGLIBC22_HEADERS
+# Standard name for dynamic library so that the dynamic linker can pick it.
+# We will just create a symbolic link to the real thing.
+DYNAMIC_LINK= libiw.so
 
-# Kernel headers 2.0.X + Glibc 2.0 - Debian 2.0, RH 5
-# Kernel headers 2.2.X + Glibc 2.1 - Debian 2.2, RH 6.1
-# Kernel headers 2.4.X + Glibc 2.1 - Debian 2.2 upgraded, RH 7.0
-HEADERS= -DGLIBC_HEADERS
+# Installation directory. By default, go in local.
+# Distributions should probably use /usr/sbin, but they probably know better...
+# Don't forget trailing slash to avoid issues
 
-# Kernel headers 2.2.X + Glibc 2.0 - Debian 2.1
-#HEADERS= -DKLUDGE_HEADERS
+INSTALL_DIR= /usr/local/sbin/
+INSTALL_LIB= /usr/local/lib/
+INSTALL_INC= /usr/local/include/
+INSTALL_MAN= /usr/local/man
 
-# Kernel headers 2.0.X + libc5 - old systems
-#HEADERS= -DLIBC5_HEADERS
+# Header selection is now supposed to be automatic...
 
 # Use private copy of Wireless Extension definition instead of the
 # system wide one in /usr/include/linux. Use with care.
@@ -38,42 +42,65 @@ WE_HEADER=
 CC = gcc
 RM = rm -f
 
-RM_CMD = $(RM) *.BAK *.bak *.o ,* *~ *.a
+RM_CMD = $(RM) *.BAK *.bak *.o *.so ,* *~ *.a *.orig *.rej
 
-CFLAGS=-O2 -Wall $(HEADERS) $(WE_HEADER)
+#CFLAGS=-O2 -W -Wall -Wstrict-prototypes -Wmissing-prototypes -Werror
+CFLAGS=-O2 -W -Wall -Wstrict-prototypes
+XCFLAGS=$(CFLAGS) $(WARN) $(HEADERS) $(WE_HEADER)
+PICFLAG=-fPIC
 
-LIBS=-lm
+LIBS= -lm
 
-all:: $(PROGS)
+all:: $(STATIC) $(DYNAMIC) $(PROGS)
 
-.c.o:
-       $(CC) $(CFLAGS) -c $<
+%: %.o
+       $(CC) $(XCFLAGS) -o $@ $^ $(LIBS)
+%.o: %.c
+       $(CC) $(XCFLAGS) -c $<
+%.so: %.c
+       $(CC) $(XCFLAGS) $(PICFLAG) -c -o $@ $<
 
-iwconfig: iwconfig.o iwcommon.o
-       $(CC) $(CFLAGS) -o $@ $^ $(LIBS)
+iwconfig: iwconfig.o $(IWLIB)
 
-iwlist: iwlist.o iwcommon.o
-       $(CC) $(CFLAGS) -o $@ $^ $(LIBS)
+iwlist: iwlist.o $(IWLIB)
 
-iwpriv: iwpriv.o iwcommon.o
-       $(CC) $(CFLAGS) -o $@ $^ $(LIBS)
+iwpriv: iwpriv.o $(IWLIB)
 
-iwspy: iwspy.o iwcommon.o
-       $(CC) $(CFLAGS) -o $@ $^ $(LIBS)
+iwspy: iwspy.o $(IWLIB)
 
 iwgetid: iwgetid.o
-       $(CC) $(CFLAGS) -o $@ $^
+
+iwevent: iwevent.o $(IWLIB)
+
+macaddr: macaddr.o $(IWLIB)
+
+# Compilation of the dynamic library
+$(DYNAMIC): $(OBJS:.o=.so)
+       $(CC) -shared -o $@ -Wl,-soname,$@ -lm -lc $^
+
+# Compilation of the static library
+$(STATIC): $(OBJS)
+       $(RM) $@
+       ar cru $@ $^
+       ranlib $@
 
 # So crude but so effective ;-)
+# Less crude thanks to many contributions ;-)
 install::
-       cp $(PROGS) $(INSTALL_DIR)
+       install -m 755 $(PROGS) $(INSTALL_DIR)
+       install -m 644 $(STATIC) $(INSTALL_LIB)
+       install -m 755 $(DYNAMIC) $(INSTALL_LIB)
+       ln -s $(INSTALL_LIB)/$(DYNAMIC) $(INSTALL_LIB)/$(DYNAMIC_LINK)
+       echo "Don't forget to add $(INSTALL_LIB) to /etc/ld.so.conf, and run ldconfig."
+       install -m 644 iwlib.h $(INSTALL_INC)
+       install -m 644 $(MANPAGES) $(INSTALL_MAN)/man8/
 
 clean::
        $(RM_CMD) 
 
 realclean::
        $(RM_CMD) 
-       $(RM) $(PROGS)
+       $(RM) $(STATIC) $(DYNAMIC) $(PROGS) macaddr
 
 depend::
        makedepend -s "# DO NOT DELETE" -- $(INCLUDES) -- $(SRCS)