TP11 exo2: Makefile: Add a static binary target and some cleanups
authorJérôme Benoit <jerome.benoit@piment-noir.org>
Tue, 7 Mar 2017 19:27:44 +0000 (20:27 +0100)
committerJérôme Benoit <jerome.benoit@piment-noir.org>
Tue, 7 Mar 2017 19:27:44 +0000 (20:27 +0100)
Signed-off-by: Jérôme Benoit <jerome.benoit@piment-noir.org>
TP_11/exo2/Makefile

index 50191de500f748c8923002c3d6175f2f082a35f3..c986981f3b4fa44ec75d3dabd994860be5774a9e 100644 (file)
@@ -21,7 +21,7 @@ BUILD_TYPE=debug
 # DO NOT CHANGE STUFF BEYOND THIS LINE
 # ====================================
 
-all: $(BINARY_NAME) $(BINARY_NAME).dynamic $(BINARY_NAME).staticlocal
+all: $(BINARY_NAME) $(BINARY_NAME).static $(BINARY_NAME).staticlocal $(BINARY_NAME).dynamic
 
 CC=gcc
 LD=gcc
@@ -46,6 +46,7 @@ endif
 CFLAGS := -fPIC $(CFLAGS) $(WARN_FLAGS) $(STD_FLAG) $(OPTI_FLAG) $(DEBUG_FLAG)
 LDFLAGS := $(LDFLAGS) $(STRIP_FLAG)
 LIBLDFLAGS := -shared $(LDFLAGS)
+STATICLDFLAGS := -static $(LDFLAGS)
 
 OBJDIR := $(BUILDDIR)/objs
 $(shell mkdir -p $(OBJDIR))
@@ -72,6 +73,10 @@ $(BINARY_NAME): $(OBJS)
        @$(LD) $(CFLAGS) $(LDFLAGS) $^ $(LDLIBS) -o $@
 
 LOCALLDLIBS=-L. -ltpC
+$(BINARY_NAME).static: $(OBJDIR)/$(BINARY_NAME).o $(LIBRARY_NAME).a
+       @echo "[LD ] $@"
+       @$(LD) $(CFLAGS) $(STATICLDFLAGS) $^ $(LOCALLDLIBS) $(LDLIBS) -o $@
+
 $(BINARY_NAME).staticlocal: $(OBJDIR)/$(BINARY_NAME).o $(LIBRARY_NAME).a
        @echo "[LD ] $@"
        @$(LD) $(CFLAGS) $(LDFLAGS) $^ $(LOCALLDLIBS) $(LDLIBS) -o $@
@@ -95,10 +100,11 @@ clean:
        @echo "[CLN]"
        -@rm -r $(BUILDDIR)
        -@rm $(BINARY_NAME)
+       -@rm $(BINARY_NAME).static
        -@rm $(BINARY_NAME).staticlocal
        -@rm $(BINARY_NAME).dynamic
-       -@rm $(LIBRARY_NAME).so
        -@rm $(LIBRARY_NAME).a
+       -@rm $(LIBRARY_NAME).so
 
 disassemble: $(BINARY_NAME)
        objdump -d $< | less