summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPascal Rigaux <pixel@mandriva.com>2005-03-14 17:20:45 +0000
committerPascal Rigaux <pixel@mandriva.com>2005-03-14 17:20:45 +0000
commit7e317d016823fa511dd2cf20827543b3375ac377 (patch)
tree90caf27f3ad9582857132d8db42759c260cfc722
parent6ac7e5b3e35f4a9382e714f8331bc6bfc947f6e9 (diff)
downloadldetect-7e317d016823fa511dd2cf20827543b3375ac377.tar
ldetect-7e317d016823fa511dd2cf20827543b3375ac377.tar.gz
ldetect-7e317d016823fa511dd2cf20827543b3375ac377.tar.bz2
ldetect-7e317d016823fa511dd2cf20827543b3375ac377.tar.xz
ldetect-7e317d016823fa511dd2cf20827543b3375ac377.zip
libify and simplify
-rw-r--r--Makefile26
-rw-r--r--common.c4
-rw-r--r--common.h21
-rw-r--r--dmi.c8
-rw-r--r--ldetect.spec45
-rw-r--r--libldetect-private.h10
-rw-r--r--libldetect.h9
-rw-r--r--lspcidrake.c1
-rw-r--r--pci.c4
-rw-r--r--pciusb.c3
-rw-r--r--usb.c3
11 files changed, 84 insertions, 50 deletions
diff --git a/Makefile b/Makefile
index e5fb808..726c189 100644
--- a/Makefile
+++ b/Makefile
@@ -1,3 +1,6 @@
+LIB_MAJOR = 0.6
+LIB_MINOR = 0
+
project = ldetect
prefix = /usr
bindir = $(prefix)/bin
@@ -5,17 +8,22 @@ libdir = $(prefix)/lib
includedir = $(prefix)/include
binaries = lspcidrake
-libraries = libldetect.a
+lib_major = libldetect.so.$(LIB_MAJOR)
+libraries = libldetect.so $(lib_major) $(lib_major).$(LIB_MINOR)
CFLAGS = -Wall -W -Wstrict-prototypes -Os -fPIC
RPM ?= $(HOME)/rpm
build: $(binaries) $(libraries)
-lspcidrake: lspcidrake.c libldetect.a
+lspcidrake: lspcidrake.c libldetect.so
-libldetect.a: common.o pciusb.o pci.o usb.o pciclass.o usbclass.o dmi.o
- ar rsc $@ $^
+$(lib_major).$(LIB_MINOR): common.o pciusb.o pci.o usb.o pciclass.o usbclass.o dmi.o
+ $(CC) -shared -Wl,-soname,$(lib_major) -o $@ $^
+$(lib_major): $(lib_major).$(LIB_MINOR)
+ ln -sf $< $@
+libldetect.so: $(lib_major)
+ ln -sf $< $@
pciclass.c: /usr/include/linux/pci.h /usr/include/linux/pci_ids.h
rm -f $@
@@ -27,10 +35,10 @@ usbclass.c: /usr/share/usb.ids
perl generate_usbclass.pl $^ > $@
chmod a-w $@
-pciusb.o: pciusb.c libldetect.h libldetect-private.h common.h
-pci.o: pci.c libldetect.h libldetect-private.h common.h
-usb.o: usb.c libldetect.h libldetect-private.h common.h
-dmi.o: dmi.c libldetect.h libldetect-private.h common.h
+pciusb.o: pciusb.c libldetect.h common.h
+pci.o: pci.c libldetect.h common.h
+usb.o: usb.c libldetect.h common.h
+dmi.o: dmi.c libldetect.h common.h
clean:
rm -f *~ *.o pciclass.c usbclass.c $(binaries) $(libraries)
@@ -38,7 +46,7 @@ clean:
install: build
install -d $(bindir) $(libdir) $(includedir)
install $(binaries) $(bindir)
- install $(libraries) $(libdir)
+ cp -a $(libraries) $(libdir)
install libldetect.h $(includedir)
rpm: srpm
diff --git a/common.c b/common.c
index e82c5fb..01ebae9 100644
--- a/common.c
+++ b/common.c
@@ -18,7 +18,7 @@ static char *table_name_to_file(const char *name) {
return fname;
}
-extern fh fh_open(const char *name) {
+fh fh_open(const char *name) {
fh ret;
char *fname = table_name_to_file(name);
int length = strlen(fname);
@@ -67,7 +67,7 @@ extern fh fh_open(const char *name) {
return ret;
}
-extern void fh_close(fh *f) {
+void fh_close(fh *f) {
fclose(f->f);
if (f->pid > 0)
waitpid(f->pid, NULL, 0);
diff --git a/common.h b/common.h
index 0458ba5..4cf5eb6 100644
--- a/common.h
+++ b/common.h
@@ -1,10 +1,25 @@
+#ifndef LIBLDETECT_COMMON
+#define LIBLDETECT_COMMON
+
+#include "libldetect.h"
+
+#define NON_EXPORTED __attribute__((visibility("hidden")))
+
+extern int pciusb_find_modules(struct pciusb_entries *entries, const char *fpciusbtable) NON_EXPORTED;
+extern void pciusb_initialize(struct pciusb_entry *e) NON_EXPORTED;
+
+#define MAX_DEVICES 100
+#define BUF_SIZE 512
+
+
#define psizeof(a) (sizeof(a) / sizeof(*(a)))
#define ifree(p) do { if (p) { free(p); p = NULL; } } while (0)
-
typedef struct {
FILE *f;
pid_t pid;
} fh;
-extern fh fh_open(const char *name);
-extern void fh_close(fh *f);
+extern fh fh_open(const char *name) NON_EXPORTED;
+extern void fh_close(fh *f) NON_EXPORTED;
+
+#endif
diff --git a/dmi.c b/dmi.c
index a09fcd8..58e4184 100644
--- a/dmi.c
+++ b/dmi.c
@@ -7,8 +7,6 @@
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
-#include "libldetect.h"
-#include "libldetect-private.h"
#include "common.h"
char *dmidecode_file = NULL;
@@ -81,7 +79,7 @@ static char *get_after_colon(char *s) {
} else return NULL;
}
-struct category *lookup_category(const char *cat_name) {
+static struct category *lookup_category(const char *cat_name) {
int i;
for (i = 0; i < nb_categories; i++)
if (streq(categories[i].cat_name, cat_name))
@@ -89,7 +87,7 @@ struct category *lookup_category(const char *cat_name) {
return NULL;
}
-int lookup_field(struct category *category, const char *field_name) {
+static int lookup_field(struct category *category, const char *field_name) {
unsigned int i;
for (i = 0; i < category->nb_fields; i++)
if (streq(category->fields[i], field_name))
@@ -97,7 +95,7 @@ int lookup_field(struct category *category, const char *field_name) {
return 0;
}
-char *lookup_criteria(struct criteria criteria, const char *field) {
+static char *lookup_criteria(struct criteria criteria, const char *field) {
unsigned int i;
for (i = 0; i < criteria.nb; i++)
if (streq(criteria.criteria[i].name, field))
diff --git a/ldetect.spec b/ldetect.spec
index 55a0eb3..1260451 100644
--- a/ldetect.spec
+++ b/ldetect.spec
@@ -1,35 +1,46 @@
+%define lib_major 0.6
+%define lib_minor 0
+%define lib_name %mklibname %{name} %{lib_major}
+
Name: ldetect
-Version: 0.5.6
+Version: %{lib_major}.%{lib_minor}
Release: 1mdk
-Summary: Light hardware detection library
+Summary: Light hardware detection tool
Source: %name.tar.bz2
Group: System/Libraries
URL: http://www.mandrakelinux.com
BuildRoot: %_tmppath/%{name}-buildroot
BuildRequires: usbutils => 0.11-2mdk, pciutils-devel
Conflicts: drakxtools < 9.2-0.32mdk
-Requires: ldetect-lst common-licenses
License: GPL
-%package devel
+%package -n %{lib_name}
+Summary: Light hardware detection library
+Requires: ldetect-lst common-licenses
+Group: System/Libraries
+
+%package -n %{lib_name}-devel
Summary: Development package for ldetect
+Requires: %{lib_name} = %{version}
+Provides: ldetect-devel libldetect-devel
+Obsoletes: ldetect-devel
Group: Development/C
%description
The hardware device lists provided by this package are used as lookup
table to get hardware autodetection
-%description devel
+%description -n %{lib_name}-devel
+see %name
+
+%description -n %{lib_name}
see %name
%prep
%setup -q -n %name
%build
-# Add PIC code in static library because it could be linked into a DSO
-PICFLAGS="-DPIC -fPIC"
-
-%make CFLAGS="-Wall -Wstrict-prototypes $PICFLAGS"
+%make
%install
rm -rf $RPM_BUILD_ROOT
@@ -38,20 +49,30 @@ rm -rf $RPM_BUILD_ROOT
%clean
rm -rf $RPM_BUILD_ROOT
+%post -n %{lib_name} -p /sbin/ldconfig
+
+%postun -n %{lib_name} -p /sbin/ldconfig
+
%files
%defattr(-,root,root)
%doc AUTHORS
%_bindir/*
-%files devel
+%files -n %{lib_name}
+%defattr(-,root,root)
+%_libdir/*.so.*
+
+%files -n %{lib_name}-devel
%defattr(-,root,root)
%doc ChangeLog
%_includedir/*
-%_libdir/*
+%_libdir/*.so
%changelog
-* Mon Mar 14 2005 Pixel <pixel@mandrakesoft.com> 0.5.6-1mdk
+* Mon Mar 14 2005 Pixel <pixel@mandrakesoft.com> 0.6.0-1mdk
- add dmitable parsing and use
+- libldetect.so instead of libldetect.a
+- libification
* Thu Feb 17 2005 Thierry Vignaud <tvignaud@mandrakesoft.com> 0.5.5-1mdk
- handle a few more special cases (gdth, snd-vx222, 8139too, and agp bridges)
diff --git a/libldetect-private.h b/libldetect-private.h
deleted file mode 100644
index 341ed55..0000000
--- a/libldetect-private.h
+++ /dev/null
@@ -1,10 +0,0 @@
-extern int pciusb_find_modules(struct pciusb_entries *entries, const char *fpciusbtable);
-extern void pciusb_initialize(struct pciusb_entry *e);
-
-#define MAX_DEVICES 100
-#define BUF_SIZE 512
-
-
-extern char *proc_usb_path;
-extern char *proc_pci_path;
-extern char *dmidecode_file;
diff --git a/libldetect.h b/libldetect.h
index 9146f27..c70bf5a 100644
--- a/libldetect.h
+++ b/libldetect.h
@@ -1,3 +1,6 @@
+#ifndef LIBLDETECT
+#define LIBLDETECT
+
/******************************************************************************/
/* pciusb *********************************************************************/
/******************************************************************************/
@@ -30,6 +33,7 @@ extern void pciusb_free(struct pciusb_entries *entries);
/******************************************************************************/
extern struct pciusb_entries pci_probe(void);
extern const char *pci_class2text(unsigned long class_);
+extern char *proc_pci_path;
/******************************************************************************/
/* usb ************************************************************************/
@@ -44,6 +48,8 @@ struct usb_class_text {
extern struct usb_class_text usb_class2text(unsigned long class_);
+extern char *proc_usb_path;
+
/******************************************************************************/
/* dmi ************************************************************************/
/******************************************************************************/
@@ -58,3 +64,6 @@ struct dmi_entries {
extern struct dmi_entries dmi_probe(void);
extern void dmi_entries_free(struct dmi_entries entries);
+extern char *dmidecode_file;
+
+#endif
diff --git a/lspcidrake.c b/lspcidrake.c
index 11172ff..3c36fea 100644
--- a/lspcidrake.c
+++ b/lspcidrake.c
@@ -1,7 +1,6 @@
#include <stdio.h>
#include <string.h>
#include "libldetect.h"
-#include "libldetect-private.h"
static int verboze = 0;
diff --git a/pci.c b/pci.c
index dba4294..37dc5ca 100644
--- a/pci.c
+++ b/pci.c
@@ -7,11 +7,9 @@
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
-#include "libldetect.h"
-#include "libldetect-private.h"
#include "common.h"
-char *proc_pci_path_default = "/proc/bus/pci/devices";
+static char *proc_pci_path_default = "/proc/bus/pci/devices";
char *proc_pci_path = NULL;
extern struct pciusb_entries pci_probe(void) {
diff --git a/pciusb.c b/pciusb.c
index 9a98dc6..949aeee 100644
--- a/pciusb.c
+++ b/pciusb.c
@@ -7,9 +7,6 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
-
-#include "libldetect.h"
-#include "libldetect-private.h"
#include "common.h"
extern int pciusb_find_modules(struct pciusb_entries *entries, const char *fpciusbtable) {
diff --git a/usb.c b/usb.c
index d71357b..6b83b7a 100644
--- a/usb.c
+++ b/usb.c
@@ -4,10 +4,9 @@
#include <string.h>
#include <unistd.h>
#include "libldetect.h"
-#include "libldetect-private.h"
#include "common.h"
-char *proc_usb_path_default = "/proc/bus/usb/devices";
+static char *proc_usb_path_default = "/proc/bus/usb/devices";
char *proc_usb_path = NULL;