From cd13ef000faed87199286f49809bfe0fa5346c2e Mon Sep 17 00:00:00 2001 From: Tiehuis Date: Tue, 4 Aug 2015 16:42:28 +1200 Subject: [PATCH] Fix makefile targets. Remove unnecessary warnings. --- Makefile | 26 +++++++++++--------------- README.md | 15 ++++++++++++++- src/ai.c | 2 ++ src/gfx_sdl.c | 1 + src/gfx_terminal.c | 13 ++++++++++--- 5 files changed, 38 insertions(+), 19 deletions(-) diff --git a/Makefile b/Makefile index 15e6777..c3724f6 100644 --- a/Makefile +++ b/Makefile @@ -1,30 +1,26 @@ CC ?= clang -CFLAGS += -g -Wall -Wextra +CFLAGS += -Wno-visibility -Wno-incompatible-pointer-types -Wall -Wextra -O2 -DINVERT_COLORS -DVT100 LFLAGS += -DEFINES := -DINVERT_COLORS -DVT100 $(shell pkg-config --cflags sdl2) PROGRAM := 2048 C_FILES := $(wildcard src/*.c) -O_FILES := $(addprefix obj/, $(notdir $(C_FILES:.c=.o))) -FILTERED_O_FILES := $(filter-out obj/gfx%.o obj/merge%.o, $(O_FILES)) +MERGE_FILE := src/merge_std.c +FILTERED_C_FILES := $(filter-out src/gfx%.c src/merge%.c, $(C_FILES)) -all: curses +all: terminal -curses: $(O_FILES) - $(CC) $(FILTERED_O_FILES) obj/merge_std.o obj/gfx_curses.o -o $(PROGRAM) -lcurses +curses: $(FILTERED_C_FILES) src/gfx_curses.c + $(CC) $(CFLAGS) $(FILTERED_C_FILES) $(MERGE_FILE) src/gfx_curses.c -o $(PROGRAM) -lcurses -vt100: $(O_FILES) - $(CC) $(FILTERED_O_FILES) obj/merge_std.o obj/gfx_terminal.o -o $(PROGRAM) +terminal: $(FILTERED_C_FILES) src/gfx_terminal.c + $(CC) $(CFLAGS) $(FILTERED_C_FILES) $(MERGE_FILE) src/gfx_terminal.c -o $(PROGRAM) -sdl: $(O_FILES) - $(CC) $(FILTERED_O_FILES) obj/merge_std.o obj/gfx_sdl.o -o $(PROGRAM) -lSDL2 -lSDL2_ttf - -obj/%.o: src/%.c - $(CC) $(DEFINES) $(CFLAGS) -c -o $@ $< +sdl: $(FILTERED_C_FILES) src/gfx_sdl.c + $(CC) $(CFLAGS) $(FILTERED_C_FILES) $(MERGE_FILE) src/gfx_sdl.c -o $(PROGRAM) $(shell pkg-config --cflags sdl2) -lSDL2 -lSDL2_ttf remake: clean all clean: - rm -f $(O_FILES) $(PROGRAM) + rm -f $(PROGRAM) .PHONY: clean remake diff --git a/README.md b/README.md index 4ce3f1b..489875d 100644 --- a/README.md +++ b/README.md @@ -13,7 +13,20 @@ create a .c file which implements all the functions in gfx.h and add a Makefile git clone https://github.com/Tiehuis/2048-cli.git make -You can also easily install this on el >= 5 (CentOS, RedHat Enterprise Linux, +By default, termios.h is expected to be present for the standard terminal version, and +a VT100 compatible terminal is being used. If a VT100 terminal is not available, simply +alter the makefile and remove the '-DVT100' flag. Compiling with ncurses requires +the development libraries for it, and likewise for using SDL2. + +On an ubuntu/debian machine for example, these can be obtained via + + apt-get install libncurses5-dev + apt-get install libsdl2-dev libsdl2-ttf-dev + +Note: The sdl version is largely to demonstrate plugging in an alternative +graphics frontend, and is likely not wanted. The ncurses version is recommended. + +You can also also easily install this on el >= 5 (CentOS, RedHat Enterprise Linux, Scientific Linux, Oracle) and Fedora >= 19 using the package-manager: sudo yum install 2048-cli[-nocurses] diff --git a/src/ai.c b/src/ai.c index 8c7f9e9..12d5ea8 100644 --- a/src/ai.c +++ b/src/ai.c @@ -1,3 +1,4 @@ +#include #include "ai.h" #include "engine.h" #include "gfx.h" @@ -6,6 +7,7 @@ const char moves[] = {'w', 'a', 's', 'd'}; int ai_move(struct gamestate *g) { + /* Ensure srand is called somewhere prior */ if (g->opts->interactive) gfx_sleep(50); return moves[rand() % 4]; } diff --git a/src/gfx_sdl.c b/src/gfx_sdl.c index ac5bd99..e46f53e 100644 --- a/src/gfx_sdl.c +++ b/src/gfx_sdl.c @@ -1,6 +1,7 @@ #include #include #include +#include "merge.h" #include "gfx.h" /* Side length of a 'pixel' in pixels */ diff --git a/src/gfx_terminal.c b/src/gfx_terminal.c index d9a728c..ec2de50 100644 --- a/src/gfx_terminal.c +++ b/src/gfx_terminal.c @@ -2,6 +2,7 @@ #include #include #include +#include "merge.h" #include "gfx.h" #define iterate(n, expression)\ @@ -16,7 +17,10 @@ struct gfx_state { struct gfx_state* gfx_init(struct gamestate *g) { + (void) g; + struct gfx_state *s = malloc(sizeof(struct gfx_state)); + if (!s) return NULL; tcgetattr(STDIN_FILENO, &s->oldt); s->newt = s->oldt; s->newt.c_lflag &= ~(ICANON | ECHO); @@ -26,6 +30,8 @@ struct gfx_state* gfx_init(struct gamestate *g) void gfx_draw(struct gfx_state *s, struct gamestate *g) { + (void) s; + #ifdef VT100 printf("\033[2J\033[H"); #endif @@ -57,6 +63,7 @@ void gfx_draw(struct gfx_state *s, struct gamestate *g) int gfx_getch(struct gfx_state *s) { + (void) s; return getchar(); } @@ -65,8 +72,8 @@ void gfx_sleep(int ms) usleep(ms * 1000); } -void gfx_destroy(struct gfx_state *t) +void gfx_destroy(struct gfx_state *s) { - tcsetattr(STDIN_FILENO, TCSANOW, &t->oldt); - free(t); + tcsetattr(STDIN_FILENO, TCSANOW, &s->oldt); + free(s); }