From: Jérôme Benoit Date: Mon, 6 Mar 2017 20:21:17 +0000 (+0100) Subject: TP 11 exo1: Fix the Makefile to produce the shared and the static X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=bfccd5920e3d878c33165ebac69b9713c2700028;p=TD_C.git TP 11 exo1: Fix the Makefile to produce the shared and the static library for linked list Signed-off-by: Jérôme Benoit --- diff --git a/.gitignore b/.gitignore index 019d038..332de4f 100644 --- a/.gitignore +++ b/.gitignore @@ -2,6 +2,9 @@ # for cygwin *.exe +*.so +*.a + # editor trash *.swp *.~ diff --git a/TP_11/exo1/Makefile b/TP_11/exo1/Makefile index 6f138af..d287ee2 100644 --- a/TP_11/exo1/Makefile +++ b/TP_11/exo1/Makefile @@ -20,7 +20,7 @@ BUILD_TYPE=debug # DO NOT CHANGE STUFF BEYOND THIS LINE # ==================================== -all: $(LIBRARY_NAME).a $(BINARY_NAME) +all: $(LIBRARY_NAME).a $(LIBRARY_NAME).so $(BINARY_NAME) CC=gcc LD=gcc @@ -41,7 +41,8 @@ STRIP_FLAG = -s OPTIFLAG = -O3 endif -CFLAGS := $(CFLAGS) $(WARN_FLAGS) $(STD_FLAG) $(OPTI_FLAG) $(DEBUG_FLAG) +#FIXME: Add a way to better control the library build +CFLAGS := -fPIC $(CFLAGS) $(WARN_FLAGS) $(STD_FLAG) $(OPTI_FLAG) $(DEBUG_FLAG) LDFLAGS := $(LDFLAGS) $(STRIP_FLAG) LIBLDFLAGS := -shared $(LDFLAGS) @@ -57,17 +58,17 @@ $(shell mkdir -p $(DEPDIR)) DEPFLAGS = -MT $@ -MMD -MP -MF $(DEPDIR)/$*.Td POSTCOMPILE = mv -f $(DEPDIR)/$*.Td $(DEPDIR)/$*.d -$(BINARY_NAME): $(OBJS) - @echo "[LD ] $@" - @$(LD) $(CFLAGS) $(LDFLAGS) $^ $(LDLIBS) -o $@ +$(LIBRARY_NAME).a: $(OBJSLIB) + @echo "[AR StO] $@" + @$(AR) rcs $@ $^ -$(LIBRARY_NAME).so: $(OBJSLIB) $(BINARY_NAME) +$(LIBRARY_NAME).so: $(OBJSLIB) @echo "[LD ShO] $@" - @$(LD) $(CFLAGS) $(LDLIBFLAGS) $^ $(LDLIBS) -o $@ + @$(LD) $(CFLAGS) $(LIBLDFLAGS) $^ -o $@ -$(LIBRARY_NAME).a: $(OBJS) - @echo "[AR StO] $@" - @$(AR) rcs $@ $^ +$(BINARY_NAME): $(OBJS) + @echo "[LD ] $@" + @$(LD) $(CFLAGS) $(LDFLAGS) $^ $(LDLIBS) -o $@ $(OBJDIR)/%.o: %.c $(DEPDIR)/%.d @echo "[C ] $*"