summaryrefslogtreecommitdiff
path: root/lib/Module.mk
blob: 432a0518fc544cd737b3be3dd2e7cba85e6ec960 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# I2C library for Linux
#
# Copyright (C) 2012  Jean Delvare <jdelvare@suse.de>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published
# by the Free Software Foundation; either version 2.1 of the License, or
# (at your option) any later version.

LIB_DIR		:= lib

LIB_CFLAGS	:= -Wstrict-prototypes -Wshadow -Wpointer-arith -Wcast-qual \
		   -Wcast-align -Wwrite-strings -Wnested-externs -Winline \
		   -W -Wundef -Wmissing-prototypes -Iinclude

# The main and minor version of the library
# The library soname (major number) must be changed if and only if the
# interface is changed in a backward incompatible way.  The interface is
# defined by the public header files - in this case they are only smbus.h.
LIB_MAINVER	:= 0
LIB_MINORVER	:= 1.0
LIB_VER		:= $(LIB_MAINVER).$(LIB_MINORVER)

# The shared and static library names
LIB_SHBASENAME	:= libi2c.so
LIB_SHSONAME	:= $(LIB_SHBASENAME).$(LIB_MAINVER)
LIB_SHLIBNAME	:= $(LIB_SHBASENAME).$(LIB_VER)
LIB_STLIBNAME	:= libi2c.a

LIB_TARGETS	:= $(LIB_SHLIBNAME)
LIB_LINKS	:= $(LIB_SHSONAME) $(LIB_SHBASENAME)
LIB_OBJECTS	:= smbus.o
ifeq ($(BUILD_STATIC_LIB),1)
LIB_TARGETS	+= $(LIB_STLIBNAME)
LIB_OBJECTS	+= smbus.ao
endif

#
# Libraries
#

$(LIB_DIR)/$(LIB_SHLIBNAME): $(LIB_DIR)/smbus.o
	$(CC) -shared $(LDFLAGS) -Wl,--version-script=$(LIB_DIR)/libi2c.map -Wl,-soname,$(LIB_SHSONAME) -o $@ $^ -lc

$(LIB_DIR)/$(LIB_SHSONAME):
	$(RM) $@
	$(LN) $(LIB_SHLIBNAME) $@

$(LIB_DIR)/$(LIB_SHBASENAME):
	$(RM) $@
	$(LN) $(LIB_SHLIBNAME) $@

$(LIB_DIR)/$(LIB_STLIBNAME): $(LIB_DIR)/smbus.ao
	$(RM) $@
	$(AR) rcvs $@ $^

#
# Objects
# Each object must be built twice, once for the shared library and
# once again for the static library.
#

$(LIB_DIR)/smbus.o: $(LIB_DIR)/smbus.c $(INCLUDE_DIR)/i2c/smbus.h
	$(CC) $(SOCFLAGS) $(LIB_CFLAGS) -c $< -o $@

$(LIB_DIR)/smbus.ao: $(LIB_DIR)/smbus.c $(INCLUDE_DIR)/i2c/smbus.h
	$(CC) $(CFLAGS) $(LIB_CFLAGS) -c $< -o $@

#
# Commands
#

all-lib: $(addprefix $(LIB_DIR)/,$(LIB_TARGETS) $(LIB_LINKS))

strip-lib: $(addprefix $(LIB_DIR)/,$(LIB_TARGETS))
	strip $(addprefix $(LIB_DIR)/,$(LIB_TARGETS))

clean-lib:
	$(RM) $(addprefix $(LIB_DIR)/,*.o *.ao $(LIB_TARGETS) $(LIB_LINKS))

install-lib: $(addprefix $(LIB_DIR)/,$(LIB_TARGETS))
	$(INSTALL_DIR) $(DESTDIR)$(libdir)
	$(INSTALL_PROGRAM) $(LIB_DIR)/$(LIB_SHLIBNAME) $(DESTDIR)$(libdir)
	$(LN) $(LIB_SHLIBNAME) $(DESTDIR)$(libdir)/$(LIB_SHSONAME)
	$(LN) $(LIB_SHSONAME) $(DESTDIR)$(libdir)/$(LIB_SHBASENAME)
ifeq ($(BUILD_STATIC_LIB),1)
	$(INSTALL_DATA) $(LIB_DIR)/$(LIB_STLIBNAME) $(DESTDIR)$(libdir)
endif

uninstall-lib:
	for library in $(LIB_TARGETS) $(LIB_LINKS) ; do \
	$(RM) $(DESTDIR)$(libdir)/$$library ; done

all: all-lib

strip: strip-lib

clean: clean-lib

install: install-lib

uninstall: uninstall-lib