On Sat, 19 Feb 2005, Linus Torvalds wrote:
> 
> Somebody who builds shared libraries more, please correct me/us.

Here's what I believe is a better example of building (and using) sparse 
as a dynamic library. Dunno if we want to go this way.

                Linus

----
===== Makefile 1.62 vs edited =====
--- 1.62/Makefile       2004-12-09 09:21:45 -08:00
+++ edited/Makefile     2005-02-19 11:12:44 -08:00
@@ -4,11 +4,12 @@
 OS=linux
 
 CC=gcc
-CFLAGS=-O -g -Wall -Wwrite-strings
-LDFLAGS=-g
+CFLAGS=-O -g -Wall -Wwrite-strings -fpic
+LDFLAGS=-g -Wl,-rpath,$(BINDIR)
 AR=ar
 
 PREFIX=$(HOME)
+BINDIR=$(PREFIX)/bin
 PROGRAMS=test-lexing test-parsing obfuscate check compile test-linearize 
example
 
 LIB_H=    token.h parse.h lib.h symbol.h scope.h expression.h target.h \
@@ -21,17 +22,19 @@
          flow.o cse.o simplify.o memops.o liveness.o storage.o
 
 LIB_FILE= sparse.a
-LIBS=$(LIB_FILE)
+SLIB_FILE= libsparse.so
 
-all: $(PROGRAMS)
+LIBS=$(SLIB_FILE)
+
+all: $(PROGRAMS) $(SLIB_FILE)
 
 #
 # Install the 'check' binary as 'sparse', just to confuse people.
 #
 #              "The better to keep you on your toes, my dear".
 #
-install: check bin-dir
-       if test $< -nt $(PREFIX)/bin/sparse ; then install -v $< 
$(PREFIX)/bin/sparse ; fi
+install: check $(SLIB_FILE) bin-dir
+       if test $< -nt $(PREFIX)/bin/sparse ; then install -v $< 
$(BINDIR)/sparse ; install -v $(SLIB_FILE) $(BINDIR) ; fi
 
 bin-dir:
        @if ! test -d $(PREFIX)/bin; then \
@@ -42,32 +45,35 @@
 
 .PHONY: bin-dir
 
-test-lexing: test-lexing.o $(LIB_FILE)
+test-lexing: test-lexing.o $(LIBS)
        $(CC) $(LDFLAGS) -o $@ $< $(LIBS)
 
-test-parsing: test-parsing.o $(LIB_FILE)
+test-parsing: test-parsing.o $(LIBS)
        $(CC) $(LDFLAGS) -o $@ $< $(LIBS)
 
-test-linearize: test-linearize.o $(LIB_FILE)
+test-linearize: test-linearize.o $(LIBS)
        $(CC) $(LDFLAGS) -o $@ $< $(LIBS)
 
-test-sort: test-sort.o $(LIB_FILE)
+test-sort: test-sort.o $(LIBS)
        gcc $(LDFLAGS) -o $@ $< $(LIBS)
 
-compile: compile.o compile-i386.o $(LIB_FILE)
+compile: compile.o compile-i386.o $(LIBS)
        $(CC) $(LDFLAGS) -o $@ $< compile-i386.o $(LIBS)
 
-obfuscate: obfuscate.o $(LIB_FILE)
+obfuscate: obfuscate.o $(LIBS)
        $(CC) $(LDFLAGS) -o $@ $< $(LIBS)
 
-check: check.o $(LIB_FILE)
+check: check.o $(LIBS)
        $(CC) $(LDFLAGS) -o $@ $< $(LIBS)
 
-example: example.o $(LIB_FILE)
+example: example.o $(LIBS)
        $(CC) $(LDFLAGS) -o $@ $< $(LIBS)
 
 $(LIB_FILE): $(LIB_OBJS)
-       $(AR) rcs $(LIB_FILE) $(LIB_OBJS)
+       $(AR) rcs $@ $(LIB_OBJS)
+
+$(SLIB_FILE): $(LIB_OBJS)
+       $(CC) -shared -o $@ $(LIB_OBJS)
 
 evaluate.o: $(LIB_H)
 expression.o: $(LIB_H)
-
To unsubscribe from this list: send the line "unsubscribe linux-sparse" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Reply via email to