Patchwork [1/2] Makefile export shared libraries

login
register
mail settings
Submitter Sidney Amani
Date Dec. 18, 2008, 2:16 p.m.
Message ID <52e42efe0812180616q28c10c72nae087e214c014676@mail.gmail.com>
Download mbox | patch
Permalink /patch/14673/
State New, archived
Headers show

Comments

Sidney Amani - Dec. 18, 2008, 2:16 p.m.
>From b557d3f22d16fc61788a85f5ec6cc02e0195c810 Mon Sep 17 00:00:00 2001
From: Sidney Amani <amani_s@epitech.net>
Date: Wed, 17 Dec 2008 12:46:42 +0100
Subject: [PATCH] Makefile export shared libraries

Export shared libraries. Other userspace tools might
use them.

Signed-off-by: Sidney Amani <amani_s@epitech.net>
Signed-off-by: Corentin Chary <chary_c@epitech.net>
---
 ubi-utils/new-utils/Makefile |   32 +++++++++++++++++++++-----------
 1 files changed, 21 insertions(+), 11 deletions(-)

 # in order to force make using our rule defined below
@@ -32,6 +35,11 @@ all: $(UTILS)
 %.o: %.c
 	$(CC) $(CFLAGS) $(CPPFLAGS) $< -c -o $@

+# The below is for shared libraries
+%.pic.o: %.c
+	$(CC) $(CFLAGS) -fPIC $(CPPFLAGS) $< -c -o $@
+
+
 # And the below is the rule to get final executable from its .o and common.o
 %: libubi.a %.o common.o
 	$(CC) $(CFLAGS) $(LDFLAGS) $(filter %.o, $^) -lubi -o $@
@@ -45,15 +53,7 @@ ubinize: ubinize.o common.o crc32.o libiniparser.a
libubigen.a
 ubiformat: ubiformat.o common.o crc32.o libmtd.a libscan.a libubi.a libubigen.a
 	$(CC) $(CFLAGS) $(LDFLAGS) $(filter %.o, $^) -lmtd -lscan -lubi -lubigen -o $@

-libubi.a: libubi.o
-	$(AR) crv $@ $^
-	$(RANLIB) $@
-
-libmtd.a: libmtd.o
-	$(AR) crv $@ $^
-	$(RANLIB) $@
-
-libubigen.a: libubigen.o
+%.a: %.o
 	$(AR) crv $@ $^
 	$(RANLIB) $@

@@ -65,14 +65,24 @@ libscan.a: libscan.o crc32.o
 	$(AR) crv $@ $^
 	$(RANLIB) $@

+%.so: %.pic.o
+	$(CC) $(LDFLAGS) -shared -o $@ $^
+
 clean:
-	rm -rf *.o $(addsuffix .a, $(LIBS)) $(UTILS) .*.c.dep
+	rm -rf *.o $(addsuffix .a, $(LIBS)) $(addsuffix .so, $(LIBS))
$(UTILS) .*.c.dep

 install: ${UTILS}
 	mkdir -p ${DESTDIR}/${SBINDIR}
 	install -m 0755 ${UTILS} ${DESTDIR}/${SBINDIR}/
+	for i in $(addsuffix .so, $(LIBS)); do \
+		[ -f $$i ] &&  install -m 0755 $$i  ${DESTDIR}/${LIBDIR}/; \
+	done

 uninstall:
 	for file in ${UTILS}; do \
 		$(RM) ${DESTDIR}/${SBINDIR}/$$file; \
 	done
+	for file in $(addsuffix .so, $(LIBS)); do \
+		$(RM) -f  ${DESTDIR}/${LIBDIR}/$$file.so; \
+	done
+
Josh Boyer - Dec. 18, 2008, 7:12 p.m.
On Thu, Dec 18, 2008 at 03:16:12PM +0100, Sidney Amani wrote:
>>From b557d3f22d16fc61788a85f5ec6cc02e0195c810 Mon Sep 17 00:00:00 2001
>From: Sidney Amani <amani_s@epitech.net>
>Date: Wed, 17 Dec 2008 12:46:42 +0100
>Subject: [PATCH] Makefile export shared libraries
>
>Export shared libraries. Other userspace tools might
>use them.
>
>Signed-off-by: Sidney Amani <amani_s@epitech.net>
>Signed-off-by: Corentin Chary <chary_c@epitech.net>

I don't see where you actually create a shared library here.  There
is no soname set, for example.  I'm not opposed to creating shared
libraries, but it should be done properly so that if the API/ABI
changes then we can bump the soname, etc.

josh
Corentin Chary - Dec. 18, 2008, 8 p.m.
On Thu, Dec 18, 2008 at 8:12 PM, Josh Boyer <jwboyer@gmail.com> wrote:
>
> I don't see where you actually create a shared library here.  There
> is no soname set, for example.  I'm not opposed to creating shared
> libraries, but it should be done properly so that if the API/ABI
> changes then we can bump the soname, etc.

The rules  which create the .so are:

shared: $(addsuffix .so, $(LIBS))
%.pic.o: %.c
      $(CC) $(CFLAGS) -fPIC $(CPPFLAGS) $< -c -o $@
%.so: %.pic.o
      $(CC) $(LDFLAGS) -shared -o $@ $^

We forgot to add -Wl,-soname,foo .
Is there anything else ?
If it's ok we will re-send the patch tomorow.

Patch

diff --git a/ubi-utils/new-utils/Makefile b/ubi-utils/new-utils/Makefile
index 9ba0d95..a975a99 100644
--- a/ubi-utils/new-utils/Makefile
+++ b/ubi-utils/new-utils/Makefile
@@ -7,6 +7,7 @@  DESTDIR := /usr/local
 SBINDIR=/usr/sbin
 MANDIR=/usr/man
 INCLUDEDIR=/usr/include
+LIBDIR=/lib

 CC := $(CROSS)gcc
 AR := $(CROSS)ar
@@ -22,7 +23,9 @@  UTILS = ubiupdatevol ubimkvol ubirmvol ubicrc32
ubinfo ubiattach \

 vpath %.c src

-all: $(UTILS)
+all: $(UTILS) shared
+
+shared: $(addsuffix .so, $(LIBS))

 # The below cancels existing implicite rule to make programs from .c files,