From: Jerome Benoit Date: Mon, 20 Mar 2017 15:28:29 +0000 (+0100) Subject: BuildSystem: Cygwin support for building proper DLL. X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=adb9472d6a59375211612e886174365d8d01468c;p=TD_C.git BuildSystem: Cygwin support for building proper DLL. Signed-off-by: Jerome Benoit --- diff --git a/TP_13/exo2/Makefile b/TP_13/exo2/Makefile index 2fa2084..1a75ccf 100644 --- a/TP_13/exo2/Makefile +++ b/TP_13/exo2/Makefile @@ -29,8 +29,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 @@ -55,8 +53,35 @@ 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 +# Cygwin ncurses do not contain tinfo +LDLIBS := $(filter-out -ltinfo,$(LDLIBS)) +BINARY_SUFFIX := .exe +DLIB_SUFFIX := .dll +CYGWIN_LDLIBS_NOARCHIVE = -lncurses +CYGWIN_LIBLDFLAGS := -Wl,--out-implib=$(LIBRARY_PATH)/$(LIBRARY_NAME)$(DLIB_SUFFIX).a \ + -Wl,--export-all-symbols \ + -Wl,--enable-auto-import endif ifeq ($(LTO_SUPPORT),yes) @@ -77,40 +102,40 @@ 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 $@ @@ -137,14 +162,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