root/lm-sensors/trunk/lib/Module.mk @ 6045

Revision 6045, 8.2 KB (checked in by khali, 2 years ago)

libsensors: Fix warning about library path not in /etc/ld.so.conf

On recent systems, extra configuration files can live in
/etc/ld.so.conf.d, so check this directory too, before warning.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
1#  Module.mk - Makefile for a Linux module for reading sensor data.
2#  Copyright (c) 1998, 1999  Frodo Looijaard <frodol@dds.nl>
3#
4#  This library is free software; you can redistribute it and/or
5#  modify it under the terms of the GNU Lesser General Public
6#  License as published by the Free Software Foundation; either
7#  version 2.1 of the License, or (at your option) any later version.
8#
9#  This library is distributed in the hope that it will be useful,
10#  but WITHOUT ANY WARRANTY; without even the implied warranty of
11#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12#  GNU Lesser General Public License for more details.
13#
14#  You should have received a copy of the GNU General Public License
15#  along with this program; if not, write to the Free Software
16#  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
17#  MA 02110-1301 USA.
18
19# Note that MODULE_DIR (the directory in which this file resides) is a
20# 'simply expanded variable'. That means that its value is substituted
21# verbatim in the rules, until it is redefined.
22MODULE_DIR := lib
23LIB_DIR := $(MODULE_DIR)
24
25# The manual dirs and files
26LIBMAN3DIR := $(MANDIR)/man3
27LIBMAN3FILES := $(MODULE_DIR)/libsensors.3
28LIBMAN5DIR := $(MANDIR)/man5
29LIBMAN5FILES := $(MODULE_DIR)/sensors.conf.5
30
31# The main and minor version of the library
32# The library soname (major number) must be changed if and only if the interface is
33# changed in a backward incompatible way.  The interface is defined by
34# the public header files - in this case they are error.h and sensors.h.
35LIBMAINVER := 4
36LIBMINORVER := 3.2
37LIBVER := $(LIBMAINVER).$(LIBMINORVER)
38
39# The static lib name, the shared lib name, and the internal ('so') name of
40# the shared lib.
41LIBSHBASENAME := libsensors.so
42LIBSHLIBNAME := libsensors.so.$(LIBVER)
43LIBSTLIBNAME := libsensors.a
44LIBSHSONAME := libsensors.so.$(LIBMAINVER)
45
46LIBTARGETS := $(MODULE_DIR)/$(LIBSHLIBNAME) \
47              $(MODULE_DIR)/$(LIBSHSONAME) $(MODULE_DIR)/$(LIBSHBASENAME)
48ifeq ($(BUILD_STATIC_LIB),1)
49LIBTARGETS += $(MODULE_DIR)/$(LIBSTLIBNAME)
50endif
51
52LIBCSOURCES := $(MODULE_DIR)/data.c $(MODULE_DIR)/general.c \
53               $(MODULE_DIR)/error.c $(MODULE_DIR)/access.c \
54               $(MODULE_DIR)/init.c $(MODULE_DIR)/sysfs.c
55
56LIBOTHEROBJECTS := $(MODULE_DIR)/conf-parse.o $(MODULE_DIR)/conf-lex.o
57LIBSHOBJECTS := $(LIBCSOURCES:.c=.lo) $(LIBOTHEROBJECTS:.o=.lo)
58LIBSTOBJECTS := $(LIBCSOURCES:.c=.ao) $(LIBOTHEROBJECTS:.o=.ao)
59LIBEXTRACLEAN := $(MODULE_DIR)/conf-parse.h $(MODULE_DIR)/conf-parse.c \
60                 $(MODULE_DIR)/conf-lex.c
61
62LIBHEADERFILES := $(MODULE_DIR)/error.h $(MODULE_DIR)/sensors.h
63
64# How to create the shared library
65$(MODULE_DIR)/$(LIBSHLIBNAME): $(LIBSHOBJECTS)
66        $(CC) -shared $(LDFLAGS) -Wl,--version-script=$(LIB_DIR)/libsensors.map -Wl,-soname,$(LIBSHSONAME) -o $@ $^ -lc -lm
67
68$(MODULE_DIR)/$(LIBSHSONAME): $(MODULE_DIR)/$(LIBSHLIBNAME)
69        $(RM) $@
70        $(LN) $(LIBSHLIBNAME) $@
71
72$(MODULE_DIR)/$(LIBSHBASENAME): $(MODULE_DIR)/$(LIBSHLIBNAME)
73        $(RM) $@ 
74        $(LN) $(LIBSHLIBNAME) $@
75
76# And the static library
77$(MODULE_DIR)/$(LIBSTLIBNAME): $(LIBSTOBJECTS)
78        $(RM) $@
79        $(AR) rcvs $@ $^
80
81# Depencies for non-C sources
82$(MODULE_DIR)/conf-lex.c: $(MODULE_DIR)/conf-lex.l $(MODULE_DIR)/general.h \
83                          $(MODULE_DIR)/data.h $(MODULE_DIR)/conf-parse.h
84$(MODULE_DIR)/conf-parse.c: $(MODULE_DIR)/conf-parse.y $(MODULE_DIR)/general.h \
85                            $(MODULE_DIR)/data.h
86$(MODULE_DIR)/conf-parse.h: $(MODULE_DIR)/conf-parse.c
87
88# Include all dependency files
89INCLUDEFILES += $(LIBSHOBJECTS:.lo=.ld) $(LIBSTOBJECTS:.ao=.ad)
90
91# Special warning prevention for flex-generated files
92FLEXNOWARN:=-Wno-shadow -Wno-undef -Wno-unused -Wno-missing-prototypes -Wno-sign-compare
93$(MODULE_DIR)/conf-lex.ao: $(MODULE_DIR)/conf-lex.c
94        $(CC) $(ARCPPFLAGS) $(ARCFLAGS) $(FLEXNOWARN) -c $< -o $@
95$(MODULE_DIR)/conf-lex.lo: $(MODULE_DIR)/conf-lex.c
96        $(CC) $(LIBCPPFLAGS) $(LIBCFLAGS) $(FLEXNOWARN) -c $< -o $@
97
98# Special warning prevention for bison-generated files
99YACCNOWARN:=-Wno-undef
100$(MODULE_DIR)/conf-parse.ao: $(MODULE_DIR)/conf-parse.c
101        $(CC) $(ARCPPFLAGS) $(ARCFLAGS) $(YACCNOWARN) -c $< -o $@
102$(MODULE_DIR)/conf-parse.lo: $(MODULE_DIR)/conf-parse.c
103        $(CC) $(LIBCPPFLAGS) $(LIBCFLAGS) $(YACCNOWARN) -c $< -o $@
104
105REMOVELIBST := $(patsubst $(MODULE_DIR)/%,$(DESTDIR)$(LIBDIR)/%,$(LIB_DIR)/$(LIBSTLIBNAME))
106REMOVELIBSH := $(patsubst $(MODULE_DIR)/%,$(DESTDIR)$(LIBDIR)/%,$(LIB_DIR)/$(LIBSHLIBNAME))
107REMOVELNSO  := $(DESTDIR)$(LIBDIR)/$(LIBSHSONAME)
108REMOVELNBS  := $(DESTDIR)$(LIBDIR)/$(LIBSHBASENAME)
109REMOVELIBHF := $(patsubst $(MODULE_DIR)/%,$(DESTDIR)$(LIBINCLUDEDIR)/%,$(LIBHEADERFILES))
110REMOVEMAN3  := $(patsubst $(MODULE_DIR)/%,$(DESTDIR)$(LIBMAN3DIR)/%,$(LIBMAN3FILES))
111REMOVEMAN5  := $(patsubst $(MODULE_DIR)/%,$(DESTDIR)$(LIBMAN5DIR)/%,$(LIBMAN5FILES))
112
113all-lib: $(LIBTARGETS)
114user :: all-lib
115
116# Generate warnings if the install directory isn't in /etc/ld.so.conf
117# or if the library wasn't there before (which means ldconfig must be run).
118# Note that some ld.so's put /usr/lib and /lib first, others put them last,
119# so we can't make any assumptions.
120install-lib: all-lib
121        $(MKDIR) $(DESTDIR)$(LIBDIR) $(DESTDIR)$(LIBINCLUDEDIR) $(DESTDIR)$(LIBMAN3DIR) $(DESTDIR)$(LIBMAN5DIR)
122        @if [ -z "$(DESTDIR)" -a ! -e "$(LIBDIR)/$(LIBSHSONAME)" ] ; then \
123             echo '******************************************************************************' ; \
124             echo 'Warning: This is the first installation of the $(LIBSHSONAME)*' ; \
125             echo '         library files in $(LIBDIR)!' ; \
126             echo '         You must update the library cache or the userspace tools may fail' ; \
127             echo '         or have unpredictable results!' ; \
128             echo '         Run the following command: /sbin/ldconfig' ; \
129             echo '******************************************************************************' ; \
130        fi
131ifeq ($(BUILD_STATIC_LIB),1)
132        $(INSTALL) -m 644 $(LIB_DIR)/$(LIBSTLIBNAME) $(DESTDIR)$(LIBDIR)
133endif
134        $(INSTALL) -m 755 $(LIB_DIR)/$(LIBSHLIBNAME) $(DESTDIR)$(LIBDIR)
135        $(LN) $(LIBSHLIBNAME) $(DESTDIR)$(LIBDIR)/$(LIBSHSONAME)
136        $(LN) $(LIBSHSONAME) $(DESTDIR)$(LIBDIR)/$(LIBSHBASENAME)
137        @if [ -z "$(DESTDIR)" -a "$(LIBDIR)" != "/usr/lib" -a "$(LIBDIR)" != "/lib" ] ; then \
138           if [ -e "/usr/lib/$(LIBSHSONAME)" -o -e "/usr/lib/$(LIBSHBASENAME)" ] ; then \
139             echo '******************************************************************************' ; \
140             echo 'Warning: You have at least one $(LIBSHBASENAME) library file in /usr/lib' ; \
141             echo '         and the new library files are in $(LIBDIR)!' ; \
142             echo '         These old files must be removed or the userspace tools may fail' ; \
143             echo '         or have unpredictable results!' ; \
144             echo '         Run the following command: rm /usr/lib/$(LIBSHBASENAME)*' ; \
145             echo '******************************************************************************' ; \
146           fi ; \
147           cat /etc/ld.so.conf /etc/ld.so.conf.d/*.conf 2>/dev/null | grep -q '^$(LIBDIR)$$' || \
148           cat /etc/ld.so.conf /etc/ld.so.conf.d/*.conf 2>/dev/null | grep -q '^$(LIBDIR)[[:space:]:,=]' || \
149           cat /etc/ld.so.conf /etc/ld.so.conf.d/*.conf 2>/dev/null | grep -q '[[:space:]:,]$(LIBDIR)$$' || \
150           cat /etc/ld.so.conf /etc/ld.so.conf.d/*.conf 2>/dev/null | grep -q '[[:space:]:,]$(LIBDIR)[[:space:]:,=]' || \
151                ( echo '******************************************************************************' ; \
152                  echo 'Warning: Library directory $(LIBDIR) is not in /etc/ld.so.conf!' ; \
153                  echo '         Add it and run /sbin/ldconfig for the userspace tools to work.' ; \
154                  echo '******************************************************************************' ) ; \
155        fi
156        $(INSTALL) -m 644 $(LIBHEADERFILES) $(DESTDIR)$(LIBINCLUDEDIR)
157        $(INSTALL) -m 644 $(LIBMAN3FILES) $(DESTDIR)$(LIBMAN3DIR)
158        $(INSTALL) -m 644 $(LIBMAN5FILES) $(DESTDIR)$(LIBMAN5DIR)
159        $(LN) sensors.conf.5 $(DESTDIR)$(LIBMAN5DIR)/sensors3.conf.5
160
161
162user_install :: install-lib
163
164user_uninstall::
165        $(RM) $(REMOVELIBSH) $(REMOVELNSO) $(REMOVELNBS)
166ifeq ($(BUILD_STATIC_LIB),1)
167        $(RM) $(REMOVELIBST)
168endif
169        $(RM) $(REMOVELIBHF) $(REMOVEMAN3) $(REMOVEMAN5)
170# Remove directory if empty, ignore failure
171        $(RMDIR) $(DESTDIR)$(LIBINCLUDEDIR) 2> /dev/null || true
172
173clean-lib:
174        $(RM) $(LIB_DIR)/*.ld $(LIB_DIR)/*.ad
175        $(RM) $(LIB_DIR)/*.lo $(LIB_DIR)/*.ao
176        $(RM) $(LIBTARGETS) $(LIBEXTRACLEAN)
177# old versions
178        $(RM) $(LIB_DIR)/$(LIBSHBASENAME).*
179clean :: clean-lib
Note: See TracBrowser for help on using the browser.