Merge pull request #580 from wigyori/cc-libpcap
[15.05/openwrt.git] / package / libs / libpcap / patches / 100-debian_shared_lib.patch
1 Debian-specific modifications to the upstream Makefile.in to
2 build a shared library.
3
4 --- a/Makefile.in
5 +++ b/Makefile.in
6 @@ -38,6 +38,13 @@ mandir = @mandir@
7  srcdir = @srcdir@
8  VPATH = @srcdir@
9  
10 +# some defines for shared library compilation
11 +LIBVERSION=1
12 +LIBNAME=pcap
13 +LIBRARY=lib$(LIBNAME).a
14 +SOLIBRARY=lib$(LIBNAME).so
15 +SHAREDLIB=$(SOLIBRARY).$(LIBVERSION)
16 +
17  #
18  # You shouldn't need to edit anything below.
19  #
20 @@ -62,7 +69,8 @@ DEPENDENCY_CFLAG = @DEPENDENCY_CFLAG@
21  PROG=libpcap
22  
23  # Standard CFLAGS
24 -FULL_CFLAGS = $(CCOPT) $(INCLS) $(DEFS) $(CFLAGS)
25 +FULL_CFLAGS = $(CCOPT) $(INCLS) $(DEFS) $(CFLAGS) $(CPPFLAGS)
26 +CFLAGS_SHARED = -shared -Wl,-soname,$(SHAREDLIB)
27  
28  INSTALL = @INSTALL@
29  INSTALL_PROGRAM = @INSTALL_PROGRAM@
30 @@ -77,7 +85,11 @@ YACC = @YACC@
31  # problem if you don't own the file but can write to the directory.
32  .c.o:
33         @rm -f $@
34 -       $(CC) $(FULL_CFLAGS) -c $(srcdir)/$*.c
35 +       $(CC) $(FULL_CFLAGS) -c -o $@ $(srcdir)/$*.c
36 +
37 +%_pic.o: %.c %.o
38 +       @rm -f $@
39 +       $(CC) -fPIC $(FULL_CFLAGS) -c -o $@ $(srcdir)/$*.c
40  
41  PSRC = pcap-@V_PCAP@.c @USB_SRC@ @BT_SRC@ @BT_MONITOR_SRC@ @NETFILTER_SRC@ @DBUS_SRC@
42  FSRC =  @V_FINDALLDEVS@
43 @@ -93,6 +105,7 @@ SRC =        $(PSRC) $(FSRC) $(CSRC) $(SSRC) $(
44  # We would like to say "OBJ = $(SRC:.c=.o)" but Ultrix's make cannot
45  # hack the extra indirection
46  OBJ =  $(PSRC:.c=.o) $(FSRC:.c=.o) $(CSRC:.c=.o) $(SSRC:.c=.o) $(GENSRC:.c=.o) $(LIBOBJS)
47 +OBJ_PIC = $(PSRC:.c=_pic.o) $(FSRC:.c=_pic.o) $(CSRC:.c=_pic.o) $(SSRC:.c=_pic.o) $(GENSRC:.c=_pic.o)
48  PUBHDR = \
49         pcap.h \
50         pcap-bpf.h \
51 @@ -157,7 +170,7 @@ TAGFILES = \
52  
53  CLEANFILES = $(OBJ) libpcap.* $(TESTS) \
54         $(PROG)-`cat $(srcdir)/VERSION`.tar.gz $(GENSRC) $(GENHDR) \
55 -       lex.yy.c pcap-config
56 +       lex.yy.c pcap-config $(OBJ_PIC)
57  
58  MAN1 = pcap-config.1
59  
60 @@ -365,7 +378,7 @@ libpcap.a: $(OBJ)
61         $(AR) rc $@ $(OBJ) $(ADDLARCHIVEOBJS)
62         $(RANLIB) $@
63  
64 -shared: libpcap.$(DYEXT)
65 +shared: $(SHAREDLIB)
66  
67  libpcap.so: $(OBJ)
68         @rm -f $@
69 @@ -443,6 +456,12 @@ libpcap.shareda: $(OBJ)
70  #
71  libpcap.none:
72  
73 +$(SHAREDLIB): $(OBJ_PIC)
74 +       -@rm -f $@
75 +       -@rm -f $(SOLIBRARY)
76 +       $(CC) $(CFLAGS_SHARED) $(LDFLAGS) -o $(SHAREDLIB) $(OBJ_PIC) -lc $(LIBS)
77 +       ln -s $(SHAREDLIB) $(SOLIBRARY)
78 +
79  scanner.c: $(srcdir)/scanner.l
80         $(LEX) -P pcap_ --header-file=scanner.h --nounput -o scanner.c $<
81  scanner.h: scanner.c
82 @@ -455,6 +474,9 @@ scanner.h: scanner.c
83  scanner.o: scanner.c grammar.h
84         $(CC) $(FULL_CFLAGS) -c scanner.c
85  
86 +scanner_pic.o: scanner.c grammar.h
87 +       $(CC) -fPIC $(FULL_CFLAGS) -o $@ -c scanner.c
88 +
89  pcap.o: pcap_version.h
90  
91  grammar.c: $(srcdir)/grammar.y
92 @@ -472,9 +494,16 @@ grammar.o: grammar.c
93  gencode.o: $(srcdir)/gencode.c grammar.h scanner.h
94         $(CC) $(FULL_CFLAGS) -c $(srcdir)/gencode.c
95  
96 +grammar_pic.o: grammar.c
97 +       @rm -f $@
98 +       $(CC) -fPIC $(FULL_CFLAGS) -Dyylval=pcap_lval -o $@ -c grammar.c
99 +
100  version.o: version.c
101         $(CC) $(FULL_CFLAGS) -c version.c
102  
103 +version_pic.o: version.c
104 +       $(CC) -fPIC $(FULL_CFLAGS) -c version.c -o $@
105 +
106  snprintf.o: $(srcdir)/missing/snprintf.c
107         $(CC) $(FULL_CFLAGS) -o $@ -c $(srcdir)/missing/snprintf.c
108  
109 @@ -501,6 +530,9 @@ bpf_filter.c: $(srcdir)/bpf/net/bpf_filt
110  bpf_filter.o: bpf_filter.c
111         $(CC) $(FULL_CFLAGS) -c bpf_filter.c
112  
113 +bpf_filter_pic.o: bpf_filter.c
114 +       $(CC) -fPIC $(FULL_CFLAGS) -c bpf_filter.c -o $@
115 +
116  #
117  # Generate the pcap-config script.
118  #
119 @@ -623,14 +655,11 @@ install: install-shared install-archive
120                     $(DESTDIR)$(mandir)/man@MAN_MISC_INFO@/`echo $$i | sed 's/.manmisc.in/.@MAN_MISC_INFO@/'`; done
121  
122  install-shared: install-shared-$(DYEXT)
123 -install-shared-so: libpcap.so
124 +install-shared-so: $(SHAREDLIB)
125         [ -d $(DESTDIR)$(libdir) ] || \
126             (mkdir -p $(DESTDIR)$(libdir); chmod 755 $(DESTDIR)$(libdir))
127 -       VER=`cat $(srcdir)/VERSION`; \
128 -       MAJOR_VER=`sed 's/\([0-9][0-9]*\)\..*/\1/' $(srcdir)/VERSION`; \
129 -       $(INSTALL_PROGRAM) libpcap.so.$$VER $(DESTDIR)$(libdir)/libpcap.so.$$VER; \
130 -       ln -sf libpcap.so.$$VER $(DESTDIR)$(libdir)/libpcap.so.$$MAJOR_VER; \
131 -       ln -sf libpcap.so.$$MAJOR_VER $(DESTDIR)$(libdir)/libpcap.so
132 +       $(INSTALL_DATA) $(SHAREDLIB) $(DESTDIR)$(libdir)/
133 +       ln -sf $(SHAREDLIB) $(DESTDIR)$(libdir)/$(SOLIBRARY)
134  install-shared-dylib: libpcap.dylib
135         [ -d $(DESTDIR)$(libdir) ] || \
136             (mkdir -p $(DESTDIR)$(libdir); chmod 755 $(DESTDIR)$(libdir))
137 --- a/aclocal.m4
138 +++ b/aclocal.m4
139 @@ -470,7 +470,7 @@ AC_DEFUN(AC_LBL_SHLIBS_INIT,
140                         esac
141                         ;;
142                     esac
143 -                   V_CCOPT="$V_CCOPT $PIC_OPT"
144 +                   V_CCOPT="$V_CCOPT"
145                     V_SONAME_OPT="-Wl,-soname,"
146                     V_RPATH_OPT="-Wl,-rpath,"
147                     ;;
148 @@ -533,7 +533,7 @@ AC_DEFUN(AC_LBL_SHLIBS_INIT,
149                     #
150                     # "cc" is GCC.
151                     #
152 -                   V_CCOPT="$V_CCOPT -fpic"
153 +                   V_CCOPT="$V_CCOPT"
154                     V_SHLIB_CMD="\$(CC)"
155                     V_SHLIB_OPT="-shared"
156                     V_SONAME_OPT="-Wl,-soname,"
157 --- a/pcap-config.in
158 +++ b/pcap-config.in
159 @@ -36,16 +36,6 @@ do
160         esac
161         shift
162  done
163 -if [ "$V_RPATH_OPT" != "" ]
164 -then
165 -       #
166 -       # If libdir isn't /usr/lib, add it to the run-time linker path.
167 -       #
168 -       if [ "$libdir" != "/usr/lib" ]
169 -       then
170 -               RPATH=$V_RPATH_OPT$libdir
171 -       fi
172 -fi
173  if [ "$static" = 1 ]
174  then
175         #