TP_13: Port the buildsystem to Mac OS X
authorJérôme Benoit <jerome.benoit@piment-noir.org>
Sat, 3 Jun 2017 14:41:50 +0000 (16:41 +0200)
committerJérôme Benoit <jerome.benoit@piment-noir.org>
Sat, 3 Jun 2017 14:41:50 +0000 (16:41 +0200)
Signed-off-by: Jérôme Benoit <jerome.benoit@piment-noir.org>
.gitignore
TP_13/exo2/Makefile
TP_13/exo2/lib/display.c

index 2882444788bbaa4f0d1fbba82882534d9c5bb954..c8399954c3a6fc086e9138b042e4cf3ef08010e1 100644 (file)
@@ -7,6 +7,7 @@ exo?
 *.o
 
 *.so
+*.dylib
 *.a
 # for cygwin  
 *.dll
index a2a7103286760cd6abfffb90b2459ea4660bc671..c4660a58ded2e21a20b3f01cc98e4db139de73e3 100644 (file)
@@ -35,7 +35,7 @@ AR=ar
 
 WARN_FLAGS = -Wall -Wextra
 STD_FLAG = -std=c11
-UNAME := $(shell uname -o)
+UNAME := $(shell uname -s)
 
 ifeq ($(BUILD_TYPE),debug)
 BUILDDIR := .build/debug
@@ -56,6 +56,7 @@ endif
 BINARY_SUFFIX :=
 DLIB_PREFIX :=
 SDLIB_PREFIX :=
+SHLIBLDFLAG := -shared
 DLIB_SUFFIX := .so
 SLIB_SUFFIX := .a
 
@@ -72,7 +73,7 @@ $(shell mkdir -p $(DEPDIR))
 DEPFLAGS = -MT $@ -MMD -MP -MF $(DEPDIR)/$(notdir $*).Td
 POSTCOMPILE = mv -f $(DEPDIR)/$(notdir $*).Td $(DEPDIR)/$(notdir $*).d
 
-ifeq ($(UNAME),Cygwin)
+ifeq ($(filter-out CYGWIN_NT,$(UNAME)),CYGWIN_NT)
 CYGWIN_DLIBRARY_NAME := $(subst lib,cyg,$(LIBRARY_NAME))
 GOLD_SUPPORT = no
 # Cygwin ncurses do not contain tinfo
@@ -86,6 +87,14 @@ CYGWIN_LIBLDFLAGS := -Wl,--out-implib=$(LIBRARY_PATH)/$(DLIB_PREFIX)$(LIBRARY_NA
     -Wl,--enable-auto-import
 endif
 
+ifeq ($(UNAME),Darwin)
+SHLIBLDFLAG=-dynamiclib
+LDLIBS := $(filter-out -ltinfo,$(LDLIBS))
+DLIB_SUFFIX=.dylib
+LTO_SUPPORT=no
+GOLD_SUPPORT=no
+endif
+
 ifeq ($(LTO_SUPPORT),yes)
 CFLAGS_LTO = -flto -ffat-lto-objects
 LDFLAGS_LTO = -fuse-linker-plugin -flto
@@ -100,17 +109,22 @@ 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)
+LIBLDFLAGS := $(SHLIBLDFLAG) $(LDFLAGS)
 STATICLIBLDFLAGS := -static $(LDFLAGS)
 LDLIBS := $(LDLIBS) -L$(LIBRARY_PATH)
 
+# Mac OS X do not support static linking
+ifeq ($(UNAME),Darwin)
+all: $(BINARY_NAME)$(BINARY_SUFFIX) $(BINARY_NAME).dynamic$(BINARY_SUFFIX)
+else
 all: $(BINARY_NAME)$(BINARY_SUFFIX) $(BINARY_NAME).dynamic$(BINARY_SUFFIX) $(BINARY_NAME).static$(BINARY_SUFFIX)
+endif
 
 $(LIBRARY_PATH)/$(SLIB_PREFIX)$(LIBRARY_NAME)$(SLIB_SUFFIX): $(LIBOBJS)
        @echo "[AR StO] $@"
        @$(AR) rcs $@ $^
 
-ifeq ($(UNAME),Cygwin)
+ifeq ($(filter-out CYGWIN_NT,$(UNAME)),CYGWIN_NT)
 $(LIBRARY_PATH)/$(DLIB_PREFIX)$(LIBRARY_NAME)$(DLIB_SUFFIX).a: $(LIBRARY_PATH)/$(DLIB_PREFIX)$(CYGWIN_DLIBRARY_NAME)$(DLIB_SUFFIX)
 $(LIBRARY_PATH)/$(DLIB_PREFIX)$(CYGWIN_DLIBRARY_NAME)$(DLIB_SUFFIX): $(LIBOBJS)
        @echo "[LD DLL] $@"
@@ -118,7 +132,7 @@ $(LIBRARY_PATH)/$(DLIB_PREFIX)$(CYGWIN_DLIBRARY_NAME)$(DLIB_SUFFIX): $(LIBOBJS)
 else
 $(LIBRARY_PATH)/$(DLIB_PREFIX)$(LIBRARY_NAME)$(DLIB_SUFFIX): $(LIBOBJS)
        @echo "[LD ShO] $@"
-       @$(LD) $(LIBCFLAGS) $(LIBLDFLAGS) $^ -o $@
+       @$(LD) $(LIBCFLAGS) $(LIBLDFLAGS) $^ $(LDLIBS) -o $@
 endif
 
 #$(BINARY_NAME)$(BINARY_SUFFIX): $(OBJS) $(LIBOBJS)
@@ -133,7 +147,7 @@ $(BINARY_NAME).static$(BINARY_SUFFIX): $(OBJS) $(LIBRARY_PATH)/$(SLIB_PREFIX)$(L
        @echo "[LD ] $@"
        @$(LD) $(CFLAGS) $(STATICLIBLDFLAGS) $^ $(LDLIBS) -o $@
 
-ifeq ($(UNAME),Cygwin)
+ifeq ($(filter-out CYGWIN_NT,$(UNAME)),CYGWIN_NT)
 $(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)
@@ -168,7 +182,7 @@ clean:
        -@rm $(BINARY_NAME).static$(BINARY_SUFFIX)
        -@rm $(BINARY_NAME).dynamic$(BINARY_SUFFIX)
        -@rm $(LIBRARY_PATH)/$(SLIB_PREFIX)$(LIBRARY_NAME)$(SLIB_SUFFIX)
-ifeq ($(UNAME),Cygwin)
+ifeq ($(filter-out CYGWIN_NT,$(UNAME)),CYGWIN_NT)
        -@rm $(LIBRARY_PATH)/$(DLIB_PREFIX)$(CYGWIN_DLIBRARY_NAME)$(DLIB_SUFFIX)
        -@rm $(LIBRARY_PATH)/$(DLIB_PREFIX)$(LIBRARY_NAME)$(DLIB_SUFFIX).a
 else
index f1cd18096d1354de250c2e8145e86061851477e5..34343a05e215d7f91bf72025bd96799cfd7b778f 100644 (file)
@@ -3,7 +3,7 @@
  *
  *       Filename:  display.c
  *
- *    Description:  Routines to handle the display 
+ *    Description:  Routines to handle the display
  *
  *        Version:  1.0
  *        Created:  15/03/2017 20:06:11
@@ -36,16 +36,16 @@ void print_board(int y, int x) {
     mvprintw(y+7, x, "    |    |");
 }
 
-/* there's only nine valid (y, x) 2-uplets for this two shapes 
+/* there's only nine valid (y, x) 2-uplets for this two shapes
  * that are : - base_y, base_x +1
  *            - base_y, base_x + 6
- *            - base_y, base_x + 11 
- *            - base_y + 3, base_x + 1 
- *            - base_y + 6, base_x + 1 
- *            - base_y + 3, base_x + 6 
- *            - base_y + 3, base_x + 11 
- *            - base_y + 6, base_x + 6 
- *            - base_y + 6, base_x + 11 
+ *            - base_y, base_x + 11
+ *            - base_y + 3, base_x + 1
+ *            - base_y + 6, base_x + 1
+ *            - base_y + 3, base_x + 6
+ *            - base_y + 3, base_x + 11
+ *            - base_y + 6, base_x + 6
+ *            - base_y + 6, base_x + 11
  * The added (y, x) couple values can be {0, 3, 6}x{1, 6, 11}
  */