TP11 exo1: Properly make linked list function a library shared and static
authorJérôme Benoit <jerome.benoit@piment-noir.org>
Tue, 7 Mar 2017 15:20:48 +0000 (16:20 +0100)
committerJérôme Benoit <jerome.benoit@piment-noir.org>
Tue, 7 Mar 2017 15:20:48 +0000 (16:20 +0100)
And build two new binaries for static and dynamic linking against the
library.

To launch the dynamic binary: LD_LIBRARY_PATH=. ./exo1.dynamic

Signed-off-by: Jérôme Benoit <jerome.benoit@piment-noir.org>
TP_11/exo1/Makefile

index f8cfee721cf62243e6263cfb66d819389fb05b80..634334e0682cb605ae3af644cb9ee7461d927cdb 100644 (file)
 BINARY_NAME=exo1
 LIBOBJS=clist.o # object to put in the library
 LIBRARY_NAME=libtpC
+#LDLIBS=-L. -ltpC
 BUILD_TYPE=debug
 
 # ====================================
 # DO NOT CHANGE STUFF BEYOND THIS LINE
 # ====================================
 
-all: $(LIBRARY_NAME).a $(LIBRARY_NAME).so $(BINARY_NAME)
+all: $(BINARY_NAME) $(BINARY_NAME).dynamic $(BINARY_NAME).static
 
 CC=gcc
 LD=gcc
@@ -70,6 +71,15 @@ $(BINARY_NAME): $(OBJS)
        @echo "[LD ] $@"
        @$(LD) $(CFLAGS) $(LDFLAGS) $^ $(LDLIBS) -o $@
 
+LOCALLDLIBS=-L. -ltpC
+$(BINARY_NAME).static: $(OBJDIR)/$(BINARY_NAME).o $(LIBRARY_NAME).a
+       @echo "[LD ] $@"
+       @$(LD) $(CFLAGS) $(LDFLAGS) $^ $(LOCALLDLIBS) $(LDLIBS) -o $@
+
+$(BINARY_NAME).dynamic: $(OBJDIR)/$(BINARY_NAME).o $(LIBRARY_NAME).so
+       @echo "[LD ] $@"
+       @$(LD) $(CFLAGS) $(LDFLAGS) $^ $(LOCALLDLIBS) $(LDLIBS) -o $@
+
 $(OBJDIR)/%.o: %.c $(DEPDIR)/%.d
        @echo "[C  ] $*"
        @$(CC) $(DEPFLAGS) $(CFLAGS) -c $< -o $@
@@ -85,6 +95,8 @@ clean:
        @echo "[CLN]"
        -@rm -r $(BUILDDIR)
        -@rm $(BINARY_NAME)
+       -@rm $(BINARY_NAME).static
+       -@rm $(BINARY_NAME).dynamic
        -@rm $(LIBRARY_NAME).so
        -@rm $(LIBRARY_NAME).a