From 98edfbe1c6a32654f9985239ae1a5d05c74e6a0f Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Fri, 5 May 2017 20:06:07 +0200 Subject: [PATCH] Be more explicit in Makefiles about external libraries linking MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Beautify a bit the tic-tac-toe displaying Signed-off-by: Jérôme Benoit --- TP_13/exo1/Makefile | 5 +++-- TP_13/exo2/Makefile | 6 +++--- TP_13/exo2/lib/display.c | 14 +++++++++----- TP_13/exo2/src/main.c | 6 ++++++ 4 files changed, 21 insertions(+), 10 deletions(-) diff --git a/TP_13/exo1/Makefile b/TP_13/exo1/Makefile index 56d4989..5580832 100644 --- a/TP_13/exo1/Makefile +++ b/TP_13/exo1/Makefile @@ -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) diff --git a/TP_13/exo2/Makefile b/TP_13/exo2/Makefile index 5f59579..8dab395 100644 --- a/TP_13/exo2/Makefile +++ b/TP_13/exo2/Makefile @@ -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) diff --git a/TP_13/exo2/lib/display.c b/TP_13/exo2/lib/display.c index c04b51b..72bd0f5 100644 --- a/TP_13/exo2/lib/display.c +++ b/TP_13/exo2/lib/display.c @@ -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; } } diff --git a/TP_13/exo2/src/main.c b/TP_13/exo2/src/main.c index 854ddb9..bdc1ccd 100644 --- a/TP_13/exo2/src/main.c +++ b/TP_13/exo2/src/main.c @@ -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); -- 2.34.1