1# I2C library for Linux
2#
3# Copyright (C) 2012  Jean Delvare <jdelvare@suse.de>
4#
5# This program is free software; you can redistribute it and/or modify
6# it under the terms of the GNU Lesser General Public License as published
7# by the Free Software Foundation; either version 2.1 of the License, or
8# (at your option) any later version.
9
10LIB_DIR		:= lib
11
12LIB_CFLAGS	:= -Wstrict-prototypes -Wshadow -Wpointer-arith -Wcast-qual \
13		   -Wcast-align -Wwrite-strings -Wnested-externs -Winline \
14		   -W -Wundef -Wmissing-prototypes -Iinclude
15
16# The main and minor version of the library
17# The library soname (major number) must be changed if and only if the
18# interface is changed in a backward incompatible way.  The interface is
19# defined by the public header files - in this case they are only smbus.h.
20LIB_MAINVER	:= 0
21LIB_MINORVER	:= 1.1
22LIB_VER		:= $(LIB_MAINVER).$(LIB_MINORVER)
23
24# The shared and static library names
25LIB_SHBASENAME	:= libi2c.so
26LIB_SHSONAME	:= $(LIB_SHBASENAME).$(LIB_MAINVER)
27LIB_SHLIBNAME	:= $(LIB_SHBASENAME).$(LIB_VER)
28LIB_STLIBNAME	:= libi2c.a
29
30LIB_TARGETS	:=
31ifeq ($(BUILD_DYNAMIC_LIB),1)
32LIB_LINKS	:= $(LIB_SHSONAME) $(LIB_SHBASENAME)
33LIB_TARGETS	+= $(LIB_SHLIBNAME)
34endif
35ifeq ($(BUILD_STATIC_LIB),1)
36LIB_TARGETS	+= $(LIB_STLIBNAME)
37endif
38
39# Library file to link against (static or dynamic)
40ifeq ($(USE_STATIC_LIB),1)
41LIB_DEPS	:= $(LIB_DIR)/$(LIB_STLIBNAME)
42else
43LIB_DEPS	:= $(LIB_DIR)/$(LIB_SHBASENAME)
44endif
45
46#
47# Libraries
48#
49
50$(LIB_DIR)/$(LIB_SHLIBNAME): $(LIB_DIR)/smbus.o
51	$(CC) -shared $(LDFLAGS) -Wl,--version-script=$(LIB_DIR)/libi2c.map -Wl,-soname,$(LIB_SHSONAME) -o $@ $^ -lc
52
53$(LIB_DIR)/$(LIB_SHSONAME): $(LIB_DIR)/$(LIB_SHLIBNAME)
54	$(RM) $@
55	$(LN) $(LIB_SHLIBNAME) $@
56
57$(LIB_DIR)/$(LIB_SHBASENAME): $(LIB_DIR)/$(LIB_SHLIBNAME)
58	$(RM) $@
59	$(LN) $(LIB_SHLIBNAME) $@
60
61$(LIB_DIR)/$(LIB_STLIBNAME): $(LIB_DIR)/smbus.ao
62	$(RM) $@
63	$(AR) rcvs $@ $^
64
65#
66# Objects
67# Each object must be built twice, once for the shared library and
68# once again for the static library.
69#
70
71$(LIB_DIR)/smbus.o: $(LIB_DIR)/smbus.c $(INCLUDE_DIR)/i2c/smbus.h
72	$(CC) $(SOCFLAGS) $(LIB_CFLAGS) -c $< -o $@
73
74$(LIB_DIR)/smbus.ao: $(LIB_DIR)/smbus.c $(INCLUDE_DIR)/i2c/smbus.h
75	$(CC) $(CFLAGS) $(LIB_CFLAGS) -c $< -o $@
76
77#
78# Commands
79#
80
81all-lib: $(addprefix $(LIB_DIR)/,$(LIB_TARGETS) $(LIB_LINKS))
82
83strip-lib: $(addprefix $(LIB_DIR)/,$(LIB_TARGETS))
84	$(STRIP) $(addprefix $(LIB_DIR)/,$(LIB_TARGETS))
85
86clean-lib:
87	$(RM) $(addprefix $(LIB_DIR)/,*.o *.ao $(LIB_TARGETS) $(LIB_LINKS))
88
89install-lib: $(addprefix $(LIB_DIR)/,$(LIB_TARGETS))
90	$(INSTALL_DIR) $(DESTDIR)$(libdir)
91ifeq ($(BUILD_DYNAMIC_LIB),1)
92	$(INSTALL_PROGRAM) $(LIB_DIR)/$(LIB_SHLIBNAME) $(DESTDIR)$(libdir)
93	$(LN) $(LIB_SHLIBNAME) $(DESTDIR)$(libdir)/$(LIB_SHSONAME)
94	$(LN) $(LIB_SHSONAME) $(DESTDIR)$(libdir)/$(LIB_SHBASENAME)
95endif
96ifeq ($(BUILD_STATIC_LIB),1)
97	$(INSTALL_DATA) $(LIB_DIR)/$(LIB_STLIBNAME) $(DESTDIR)$(libdir)
98endif
99
100uninstall-lib:
101	for library in $(LIB_TARGETS) $(LIB_LINKS) ; do \
102	$(RM) $(DESTDIR)$(libdir)/$$library ; done
103
104all: all-lib
105
106strip: strip-lib
107
108clean: clean-lib
109
110install: install-lib
111
112uninstall: uninstall-lib
113