From: Jerome Benoit Date: Mon, 20 Mar 2017 16:29:05 +0000 (+0100) Subject: BuildSystem: Sync more exercices with the latest one X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=3a3dd236e2f65bc1a8b052f2fc887d8eec9deb65;p=TD_C.git BuildSystem: Sync more exercices with the latest one Signed-off-by: Jerome Benoit --- diff --git a/TP_13/exo1/Makefile b/TP_13/exo1/Makefile index 152498c..c425996 100644 --- a/TP_13/exo1/Makefile +++ b/TP_13/exo1/Makefile @@ -28,8 +28,6 @@ BUILD_TYPE=debug # DO NOT CHANGE STUFF BEYOND THIS LINE # ==================================== -all: $(BINARY_NAME) $(BINARY_NAME).dynamic $(BINARY_NAME).static - CC=gcc LD=gcc AR=ar @@ -54,8 +52,33 @@ LTO_SUPPORT = yes GOLD_SUPPORT = yes endif +BINARY_SUFFIX := +DLIB_PREFIX := +SDLIB_PREFIX := +DLIB_SUFFIX := .so +SLIB_SUFFIX := .a + +OBJDIR := $(BUILDDIR)/objs +$(shell mkdir -p $(OBJDIR)) + +SRCS=$(wildcard $(SRC_PATH)/*.c) +LIBSRCS=$(wildcard $(LIBRARY_PATH)/*.c) +OBJS=$(patsubst %.c,$(OBJDIR)/%.o,$(notdir $(SRCS))) +LIBOBJS=$(patsubst %.c,$(OBJDIR)/%.o,$(notdir $(LIBSRCS))) + +DEPDIR := $(BUILDDIR)/deps +$(shell mkdir -p $(DEPDIR)) +DEPFLAGS = -MT $@ -MMD -MP -MF $(DEPDIR)/$(notdir $*).Td +POSTCOMPILE = mv -f $(DEPDIR)/$(notdir $*).Td $(DEPDIR)/$(notdir $*).d + ifeq ($(UNAME),Cygwin) GOLD_SUPPORT = no +BINARY_SUFFIX := .exe +DLIB_SUFFIX := .dll +CYGWIN_LDLIBS_NOARCHIVE = -lncurses +CYGWIN_LIBLDFLAGS := -Wl,--out-implib=$(LIBRARY_PATH)/$(DLIB_PREFIX)$(LIBRARY_NAME)$(DLIB_SUFFIX).a \ + -Wl,--export-all-symbols \ + -Wl,--enable-auto-import endif ifeq ($(LTO_SUPPORT),yes) @@ -67,49 +90,49 @@ ifeq ($(GOLD_SUPPORT),yes) LDFLAGS_GOLD = -fuse-ld=gold endif -# Putting header files in the source directory is not the purpose of this INCLUDES variable -INCLUDES := $(INCLUDES) -I$(LIBRARY_PATH) -CFLAGS := $(CFLAGS) $(CFLAGS_LTO) $(WARN_FLAGS) $(STD_FLAG) $(OPTI_FLAG) $(DEBUG_FLAG) $(INCLUDES) +# Putting header files in the source directory is not the purpose of this INCLUDES_PATH variable +INCLUDES_PATH := $(INCLUDES_PATH) -I$(LIBRARY_PATH) +CFLAGS := $(CFLAGS) $(CFLAGS_LTO) $(WARN_FLAGS) $(STD_FLAG) $(OPTI_FLAG) $(DEBUG_FLAG) $(INCLUDES_PATH) LIBCFLAGS := -fPIC $(CFLAGS) LDFLAGS := $(LDFLAGS) $(LDFLAGS_LTO) $(LDFLAGS_GOLD) $(STRIP_FLAG) LIBLDFLAGS := -shared $(LDFLAGS) STATICLIBLDFLAGS := -static $(LDFLAGS) LDLIBS := $(LDLIBS) -L$(LIBRARY_PATH) -l$(BINARY_NAME) -OBJDIR := $(BUILDDIR)/objs -$(shell mkdir -p $(OBJDIR)) +all: $(BINARY_NAME)$(BINARY_SUFFIX) $(BINARY_NAME).dynamic$(BINARY_SUFFIX) $(BINARY_NAME).static$(BINARY_SUFFIX) -SRCS=$(wildcard $(SRC_PATH)/*.c) -LIBSRCS=$(wildcard $(LIBRARY_PATH)/*.c) -OBJS=$(patsubst %.c,$(OBJDIR)/%.o,$(notdir $(SRCS))) -LIBOBJS=$(patsubst %.c,$(OBJDIR)/%.o,$(notdir $(LIBSRCS))) - -DEPDIR := $(BUILDDIR)/deps -$(shell mkdir -p $(DEPDIR)) -DEPFLAGS = -MT $@ -MMD -MP -MF $(DEPDIR)/$(notdir $*).Td -POSTCOMPILE = mv -f $(DEPDIR)/$(notdir $*).Td $(DEPDIR)/$(notdir $*).d - -$(LIBRARY_PATH)/$(LIBRARY_NAME).a: $(LIBOBJS) +$(LIBRARY_PATH)/$(SLIB_PREFIX)$(LIBRARY_NAME)$(SLIB_SUFFIX): $(LIBOBJS) @echo "[AR StO] $@" @$(AR) rcs $@ $^ -$(LIBRARY_PATH)/$(LIBRARY_NAME).so: $(LIBOBJS) +ifeq ($(UNAME),Cygwin) +$(LIBRARY_PATH)/$(DLIB_PREFIX)$(LIBRARY_NAME)$(DLIB_SUFFIX).a: $(LIBRARY_PATH)/$(DLIB_PREFIX)$(LIBRARY_NAME)$(DLIB_SUFFIX) +$(LIBRARY_PATH)/$(DLIB_PREFIX)$(LIBRARY_NAME)$(DLIB_SUFFIX): $(LIBOBJS) + @echo "[LD DLL] $@" + @$(LD) $(LIBCFLAGS) $(LIBLDFLAGS) $(CYGWIN_LIBLDFLAGS) -Wl,--whole-archive $^ -Wl,--no-whole-archive $(CYGWIN_LDLIBS_NOARCHIVE) -o $@ +else +$(LIBRARY_PATH)/$(DLIB_PREFIX)$(LIBRARY_NAME)$(DLIB_SUFFIX): $(LIBOBJS) @echo "[LD ShO] $@" @$(LD) $(LIBCFLAGS) $(LIBLDFLAGS) $^ -o $@ +endif -#$(BINARY_NAME): $(OBJS) $(LIBOBJS) +#$(BINARY_NAME)$(BINARY_SUFFIX): $(OBJS) $(LIBOBJS) # @echo "[LD ] $@" # @$(LD) $(CFLAGS) $(LDFLAGS) $^ $(LDLIBS) -o $@ -$(BINARY_NAME): $(OBJS) $(LIBRARY_PATH)/$(LIBRARY_NAME).a +$(BINARY_NAME)$(BINARY_SUFFIX): $(OBJS) $(LIBRARY_PATH)/$(SLIB_PREFIX)$(LIBRARY_NAME)$(SLIB_SUFFIX) @echo "[LD ] $@" @$(LD) $(CFLAGS) $(LDFLAGS) $^ $(LDLIBS) -o $@ -$(BINARY_NAME).static: $(OBJS) $(LIBRARY_PATH)/$(LIBRARY_NAME).a +$(BINARY_NAME).static$(BINARY_SUFFIX): $(OBJS) $(LIBRARY_PATH)/$(SLIB_PREFIX)$(LIBRARY_NAME)$(SLIB_SUFFIX) @echo "[LD ] $@" @$(LD) $(CFLAGS) $(STATICLIBLDFLAGS) $^ $(LDLIBS) -o $@ -$(BINARY_NAME).dynamic: $(OBJS) $(LIBRARY_PATH)/$(LIBRARY_NAME).so +ifeq ($(UNAME),Cygwin) +$(BINARY_NAME).dynamic$(BINARY_SUFFIX): $(OBJS) $(LIBRARY_PATH)/$(DLIB_PREFIX)$(LIBRARY_NAME)$(DLIB_SUFFIX).a +else +$(BINARY_NAME).dynamic$(BINARY_SUFFIX): $(OBJS) $(LIBRARY_PATH)/$(DLIB_PREFIX)$(LIBRARY_NAME)$(DLIB_SUFFIX) +endif @echo "[LD ] $@" @$(LD) $(CFLAGS) $(LDFLAGS) $^ $(LDLIBS) -o $@ @@ -136,14 +159,17 @@ $(DEPDIR)/%.d: ; clean: @echo "[CLN]" -@rm -r $(BUILDDIR) - -@rm $(BINARY_NAME) - -@rm $(BINARY_NAME).static - -@rm $(BINARY_NAME).dynamic - -@rm $(LIBRARY_PATH)/$(LIBRARY_NAME).a - -@rm $(LIBRARY_PATH)/$(LIBRARY_NAME).so + -@rm $(BINARY_NAME)$(BINARY_SUFFIX) + -@rm $(BINARY_NAME).static$(BINARY_SUFFIX) + -@rm $(BINARY_NAME).dynamic$(BINARY_SUFFIX) + -@rm $(LIBRARY_PATH)/$(SLIB_PREFIX)$(LIBRARY_NAME)$(SLIB_SUFFIX) + -@rm $(LIBRARY_PATH)/$(DLIB_PREFIX)$(LIBRARY_NAME)$(DLIB_SUFFIX) +ifeq ($(UNAME),Cygwin) + -@rm $(LIBRARY_PATH)/$(DLIB_PREFIX)$(LIBRARY_NAME)$(DLIB_SUFFIX).a +endif -disassemble: $(BINARY_NAME) +disassemble: $(BINARY_NAME)$(BINARY_SUFFIX) objdump -d $< | less -symbols: $(BINARY_NAME) +symbols: $(BINARY_NAME)$(BINARY_SUFFIX) objdump -t $< | sort | less