Fix makefile targets. Remove unnecessary warnings.
This commit is contained in:
parent
dc9adea7b5
commit
cd13ef000f
26
Makefile
26
Makefile
|
@ -1,30 +1,26 @@
|
||||||
CC ?= clang
|
CC ?= clang
|
||||||
CFLAGS += -g -Wall -Wextra
|
CFLAGS += -Wno-visibility -Wno-incompatible-pointer-types -Wall -Wextra -O2 -DINVERT_COLORS -DVT100
|
||||||
LFLAGS +=
|
LFLAGS +=
|
||||||
DEFINES := -DINVERT_COLORS -DVT100 $(shell pkg-config --cflags sdl2)
|
|
||||||
|
|
||||||
PROGRAM := 2048
|
PROGRAM := 2048
|
||||||
C_FILES := $(wildcard src/*.c)
|
C_FILES := $(wildcard src/*.c)
|
||||||
O_FILES := $(addprefix obj/, $(notdir $(C_FILES:.c=.o)))
|
MERGE_FILE := src/merge_std.c
|
||||||
FILTERED_O_FILES := $(filter-out obj/gfx%.o obj/merge%.o, $(O_FILES))
|
FILTERED_C_FILES := $(filter-out src/gfx%.c src/merge%.c, $(C_FILES))
|
||||||
|
|
||||||
all: curses
|
all: terminal
|
||||||
|
|
||||||
curses: $(O_FILES)
|
curses: $(FILTERED_C_FILES) src/gfx_curses.c
|
||||||
$(CC) $(FILTERED_O_FILES) obj/merge_std.o obj/gfx_curses.o -o $(PROGRAM) -lcurses
|
$(CC) $(CFLAGS) $(FILTERED_C_FILES) $(MERGE_FILE) src/gfx_curses.c -o $(PROGRAM) -lcurses
|
||||||
|
|
||||||
vt100: $(O_FILES)
|
terminal: $(FILTERED_C_FILES) src/gfx_terminal.c
|
||||||
$(CC) $(FILTERED_O_FILES) obj/merge_std.o obj/gfx_terminal.o -o $(PROGRAM)
|
$(CC) $(CFLAGS) $(FILTERED_C_FILES) $(MERGE_FILE) src/gfx_terminal.c -o $(PROGRAM)
|
||||||
|
|
||||||
sdl: $(O_FILES)
|
sdl: $(FILTERED_C_FILES) src/gfx_sdl.c
|
||||||
$(CC) $(FILTERED_O_FILES) obj/merge_std.o obj/gfx_sdl.o -o $(PROGRAM) -lSDL2 -lSDL2_ttf
|
$(CC) $(CFLAGS) $(FILTERED_C_FILES) $(MERGE_FILE) src/gfx_sdl.c -o $(PROGRAM) $(shell pkg-config --cflags sdl2) -lSDL2 -lSDL2_ttf
|
||||||
|
|
||||||
obj/%.o: src/%.c
|
|
||||||
$(CC) $(DEFINES) $(CFLAGS) -c -o $@ $<
|
|
||||||
|
|
||||||
remake: clean all
|
remake: clean all
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
rm -f $(O_FILES) $(PROGRAM)
|
rm -f $(PROGRAM)
|
||||||
|
|
||||||
.PHONY: clean remake
|
.PHONY: clean remake
|
||||||
|
|
15
README.md
15
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
|
git clone https://github.com/Tiehuis/2048-cli.git
|
||||||
make
|
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:
|
Scientific Linux, Oracle) and Fedora >= 19 using the package-manager:
|
||||||
|
|
||||||
sudo yum install 2048-cli[-nocurses]
|
sudo yum install 2048-cli[-nocurses]
|
||||||
|
|
2
src/ai.c
2
src/ai.c
|
@ -1,3 +1,4 @@
|
||||||
|
#include <stdlib.h>
|
||||||
#include "ai.h"
|
#include "ai.h"
|
||||||
#include "engine.h"
|
#include "engine.h"
|
||||||
#include "gfx.h"
|
#include "gfx.h"
|
||||||
|
@ -6,6 +7,7 @@ const char moves[] = {'w', 'a', 's', 'd'};
|
||||||
|
|
||||||
int ai_move(struct gamestate *g)
|
int ai_move(struct gamestate *g)
|
||||||
{
|
{
|
||||||
|
/* Ensure srand is called somewhere prior */
|
||||||
if (g->opts->interactive) gfx_sleep(50);
|
if (g->opts->interactive) gfx_sleep(50);
|
||||||
return moves[rand() % 4];
|
return moves[rand() % 4];
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <SDL.h>
|
#include <SDL.h>
|
||||||
#include <SDL_ttf.h>
|
#include <SDL_ttf.h>
|
||||||
|
#include "merge.h"
|
||||||
#include "gfx.h"
|
#include "gfx.h"
|
||||||
|
|
||||||
/* Side length of a 'pixel' in pixels */
|
/* Side length of a 'pixel' in pixels */
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <termios.h>
|
#include <termios.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
#include "merge.h"
|
||||||
#include "gfx.h"
|
#include "gfx.h"
|
||||||
|
|
||||||
#define iterate(n, expression)\
|
#define iterate(n, expression)\
|
||||||
|
@ -16,7 +17,10 @@ struct gfx_state {
|
||||||
|
|
||||||
struct gfx_state* gfx_init(struct gamestate *g)
|
struct gfx_state* gfx_init(struct gamestate *g)
|
||||||
{
|
{
|
||||||
|
(void) g;
|
||||||
|
|
||||||
struct gfx_state *s = malloc(sizeof(struct gfx_state));
|
struct gfx_state *s = malloc(sizeof(struct gfx_state));
|
||||||
|
if (!s) return NULL;
|
||||||
tcgetattr(STDIN_FILENO, &s->oldt);
|
tcgetattr(STDIN_FILENO, &s->oldt);
|
||||||
s->newt = s->oldt;
|
s->newt = s->oldt;
|
||||||
s->newt.c_lflag &= ~(ICANON | ECHO);
|
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 gfx_draw(struct gfx_state *s, struct gamestate *g)
|
||||||
{
|
{
|
||||||
|
(void) s;
|
||||||
|
|
||||||
#ifdef VT100
|
#ifdef VT100
|
||||||
printf("\033[2J\033[H");
|
printf("\033[2J\033[H");
|
||||||
#endif
|
#endif
|
||||||
|
@ -57,6 +63,7 @@ void gfx_draw(struct gfx_state *s, struct gamestate *g)
|
||||||
|
|
||||||
int gfx_getch(struct gfx_state *s)
|
int gfx_getch(struct gfx_state *s)
|
||||||
{
|
{
|
||||||
|
(void) s;
|
||||||
return getchar();
|
return getchar();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -65,8 +72,8 @@ void gfx_sleep(int ms)
|
||||||
usleep(ms * 1000);
|
usleep(ms * 1000);
|
||||||
}
|
}
|
||||||
|
|
||||||
void gfx_destroy(struct gfx_state *t)
|
void gfx_destroy(struct gfx_state *s)
|
||||||
{
|
{
|
||||||
tcsetattr(STDIN_FILENO, TCSANOW, &t->oldt);
|
tcsetattr(STDIN_FILENO, TCSANOW, &s->oldt);
|
||||||
free(t);
|
free(s);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user