# DO NOT CHANGE STUFF BEYOND THIS LINE
# ====================================
-all: $(BINARY_NAME) $(BINARY_NAME).dynamic $(BINARY_NAME).static
-
CC=gcc
LD=gcc
AR=ar
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)
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 $@
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