Be more explicit in Makefiles about external libraries linking
authorJérôme Benoit <jerome.benoit@piment-noir.org>
Fri, 5 May 2017 18:06:07 +0000 (20:06 +0200)
committerJérôme Benoit <jerome.benoit@piment-noir.org>
Fri, 5 May 2017 18:06:07 +0000 (20:06 +0200)
Beautify a bit the tic-tac-toe displaying

Signed-off-by: Jérôme Benoit <jerome.benoit@piment-noir.org>
TP_13/exo1/Makefile
TP_13/exo2/Makefile
TP_13/exo2/lib/display.c
TP_13/exo2/src/main.c

index 56d4989a6989a76679149132492cd0ae8e7814a7..55808324352487727f845abb810d906d6d84f483 100644 (file)
@@ -19,8 +19,9 @@
 # http://make.mad-scientist.net/papers/advanced-auto-dependency-generation/#tldr
 BINARY_NAME:=exo1
 SRC_PATH:=src
-LIBRARY_NAME:=libexo1
+LIBRARY_NAME:=lib$(BINARY_NAME)
 LIBRARY_PATH:=lib
+LDLIBS:=-l$(BINARY_NAME)
 BUILD_TYPE:=debug
 #BUILD_TYPE=release
 
@@ -98,7 +99,7 @@ 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)
+LDLIBS := $(LDLIBS) -L$(LIBRARY_PATH)
 
 all: $(BINARY_NAME)$(BINARY_SUFFIX) $(BINARY_NAME).dynamic$(BINARY_SUFFIX) $(BINARY_NAME).static$(BINARY_SUFFIX)
 
index 5f595793b94649418d958eaacaedf04d3b0d81d7..8dab395969d92bf4cbae75d57106edbeeed5f7b5 100644 (file)
@@ -19,9 +19,9 @@
 # http://make.mad-scientist.net/papers/advanced-auto-dependency-generation/#tldr
 BINARY_NAME:=exo2
 SRC_PATH:=src
-LIBRARY_NAME:=libexo2
+LIBRARY_NAME:=lib$(BINARY_NAME)
 LIBRARY_PATH:=lib
-LDLIBS:=-lncurses -ltinfo
+LDLIBS:=-l$(BINARY_NAME) -lncurses -ltinfo
 BUILD_TYPE:=debug
 #BUILD_TYPE:=release
 
@@ -102,7 +102,7 @@ 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)
+LDLIBS := $(LDLIBS) -L$(LIBRARY_PATH)
 
 all: $(BINARY_NAME)$(BINARY_SUFFIX) $(BINARY_NAME).dynamic$(BINARY_SUFFIX) $(BINARY_NAME).static$(BINARY_SUFFIX)
 
index c04b51b1feb5e4ae0dfebbd2d258503e362d3891..72bd0f5f37e071b639d7da69ac025f0d21956eb4 100644 (file)
@@ -68,9 +68,11 @@ static int remap_y(int y) {
 
     if (y == 1) {
         return 0;
-    } else if (y == 2) {
-        return 3;
-    } else {
+    } else if (y > 1 && y <= 3) {
+        return (remap_y(y - 1) + 3);
+    }  else {
+        /* FIXME: return an error value like -1
+         * but for now there a bug somewhere */
         return 6;
     }
 }
@@ -79,9 +81,11 @@ static int remap_x(int x) {
 
     if (x == 1) {
         return 1;
-    } else if (x == 2) {
-        return 6;
+    } else if (x > 1 && x <= 3) {
+        return (remap_x(x - 1) + 5);
     } else {
+        /* FIXME: return an error value like -1
+         * but for now there a bug somewhere */
         return 11;
     }
 }
index 854ddb9c1e52d9dd6a90622eda0b11120080e55b..bdc1ccd881172d9e3c206cd493e9001a6054e05d 100644 (file)
@@ -17,6 +17,12 @@ int main() {
     char* exit_msg = malloc(str_max_length * sizeof(char));
 
     initscr();
+    if (has_colors() == false) {
+        endwin();
+        printf("Votre terminal ne supporte pas les couleurs.\n");
+        exit(EXIT_FAILURE);
+    }
+    start_color();
     getmaxyx(stdscr, row, col);
     noecho();
     curs_set(0);