--- /dev/null
+# Sample Makefile to build simple project.
+#
+# This Makefile expect all source files (.c) to be at the same level, in the
+# $(SRC_PATH) directory.
+#
+# This Makefile expect all embedded library source files (.c) to be at the same level, in the
+# $(LIBRARY_PATH) directory.
+#
+# It will automatically generate dependencies, compile all files, and produce a
+# binary using the provided name linked against the library if necessary.
+#
+# Set BINARY_NAME to the name of the binary file to build.
+# Set LIBRARY_NAME to the name of the library file to build.
+# The default path for the library code and object is lib.
+# By default the linker will look for $(BINARY_NAME) library name.
+# Set BUILD_TYPE to either debug or release.
+#
+# Automatic dependencies code from:
+# http://make.mad-scientist.net/papers/advanced-auto-dependency-generation/#tldr
+BINARY_NAME:=othello
+SRC_PATH:=src
+# will add -lothello automagically linking flags
+LIBRARY_NAME:=libothello
+LIBRARY_PATH:=lib
+LDLIBS:=-lncurses -ltinfo
+BUILD_TYPE:=debug
+#BUILD_TYPE:=release
+
+# ====================================
+# DO NOT CHANGE STUFF BEYOND THIS LINE
+# ====================================
+
+CC=gcc
+LD=gcc
+AR=ar
+
+WARN_FLAGS = -Wall -Wextra
+STD_FLAG = -std=c11
+UNAME := $(shell uname -o)
+
+ifeq ($(BUILD_TYPE),debug)
+BUILDDIR := .build/debug
+DEBUG_FLAG = -g
+STRIP_FLAG =
+OPTI_FLAG = -O0
+LTO_SUPPORT = yes
+GOLD_SUPPORT = yes
+else
+BUILDDIR := .build/release
+DEBUG_FLAG =
+STRIP_FLAG = -s
+OPTI_FLAG = -O3
+LTO_SUPPORT = yes
+GOLD_SUPPORT = yes
+endif
+
+BINARY_SUFFIX :=
+DLIB_PREFIX :=
+SDLIB_PREFIX :=
+DLIB_SUFFIX := .so
+SLIB_SUFFIX := .a
+
+OBJDIR := $(BUILDDIR)/objs
+$(shell mkdir -p $(OBJDIR))
+
+SRCS=$(wildcard $(SRC_PATH)/*.c)
+LIBSRCS=$(wildcard $(LIBRARY_PATH)/*.c)
+OBJS=$(patsubst %.c,$(OBJDIR)/%.o,$(notdir $(SRCS)))
+LIBOBJS=$(patsubst %.c,$(OBJDIR)/%.o,$(notdir $(LIBSRCS)))
+
+DEPDIR := $(BUILDDIR)/deps
+$(shell mkdir -p $(DEPDIR))
+DEPFLAGS = -MT $@ -MMD -MP -MF $(DEPDIR)/$(notdir $*).Td
+POSTCOMPILE = mv -f $(DEPDIR)/$(notdir $*).Td $(DEPDIR)/$(notdir $*).d
+
+ifeq ($(UNAME),Cygwin)
+CYGWIN_DLIBRARY_NAME := $(subst lib,cyg,$(LIBRARY_NAME))
+GOLD_SUPPORT = no
+# Cygwin ncurses do not contain tinfo
+LDLIBS := $(filter-out -ltinfo,$(LDLIBS))
+BINARY_SUFFIX := .exe
+DLIB_SUFFIX := .dll
+# do not archive external libraries
+CYGWIN_LDLIBS_NOARCHIVE := $(LDLIBS)
+CYGWIN_LIBLDFLAGS := -Wl,--out-implib=$(LIBRARY_PATH)/$(DLIB_PREFIX)$(LIBRARY_NAME)$(DLIB_SUFFIX).a \
+ -Wl,--export-all-symbols \
+ -Wl,--enable-auto-import
+endif
+
+ifeq ($(LTO_SUPPORT),yes)
+CFLAGS_LTO = -flto -ffat-lto-objects
+LDFLAGS_LTO = -fuse-linker-plugin -flto
+endif
+
+ifeq ($(GOLD_SUPPORT),yes)
+LDFLAGS_GOLD = -fuse-ld=gold
+endif
+
+# Putting header files in the source directory is not the purpose of this INCLUDES_PATH variable
+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)
+STATICLIBLDFLAGS := -static $(LDFLAGS)
+LDLIBS := $(LDLIBS) -L$(LIBRARY_PATH) -l$(BINARY_NAME)
+
+all: $(BINARY_NAME)$(BINARY_SUFFIX) $(BINARY_NAME).dynamic$(BINARY_SUFFIX) $(BINARY_NAME).static$(BINARY_SUFFIX)
+
+$(LIBRARY_PATH)/$(SLIB_PREFIX)$(LIBRARY_NAME)$(SLIB_SUFFIX): $(LIBOBJS)
+ @echo "[AR StO] $@"
+ @$(AR) rcs $@ $^
+
+ifeq ($(UNAME),Cygwin)
+$(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] $@"
+ @$(LD) $(LIBCFLAGS) $(LIBLDFLAGS) $(CYGWIN_LIBLDFLAGS) -Wl,--whole-archive $^ -Wl,--no-whole-archive $(CYGWIN_LDLIBS_NOARCHIVE) -o $@
+else
+$(LIBRARY_PATH)/$(DLIB_PREFIX)$(LIBRARY_NAME)$(DLIB_SUFFIX): $(LIBOBJS)
+ @echo "[LD ShO] $@"
+ @$(LD) $(LIBCFLAGS) $(LIBLDFLAGS) $^ -o $@
+endif
+
+#$(BINARY_NAME)$(BINARY_SUFFIX): $(OBJS) $(LIBOBJS)
+# @echo "[LD ] $@"
+# @$(LD) $(CFLAGS) $(LDFLAGS) $^ $(LDLIBS) -o $@
+
+$(BINARY_NAME)$(BINARY_SUFFIX): $(OBJS) $(LIBRARY_PATH)/$(SLIB_PREFIX)$(LIBRARY_NAME)$(SLIB_SUFFIX)
+ @echo "[LD ] $@"
+ @$(LD) $(CFLAGS) $(LDFLAGS) $^ $(LDLIBS) -o $@
+
+$(BINARY_NAME).static$(BINARY_SUFFIX): $(OBJS) $(LIBRARY_PATH)/$(SLIB_PREFIX)$(LIBRARY_NAME)$(SLIB_SUFFIX)
+ @echo "[LD ] $@"
+ @$(LD) $(CFLAGS) $(STATICLIBLDFLAGS) $^ $(LDLIBS) -o $@
+
+ifeq ($(UNAME),Cygwin)
+$(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)
+endif
+ @echo "[LD ] $@"
+ @$(LD) $(CFLAGS) $(LDFLAGS) $^ $(LDLIBS) -o $@
+
+$(OBJDIR)/%.o: $(SRC_PATH)/%.c $(DEPDIR)/%.d
+ @echo "[C ] $(notdir $*)"
+ @$(CC) $(DEPFLAGS) $(CFLAGS) -c $< -o $@
+ @$(POSTCOMPILE)
+
+include $(wildcard $(patsubst %,$(DEPDIR)/%.d,$(basename $(SRCS))))
+
+$(OBJDIR)/%.o: $(LIBRARY_PATH)/%.c $(DEPDIR)/%.d
+ @echo "[C ] $(notdir $*)"
+ @$(CC) $(DEPFLAGS) $(LIBCFLAGS) -c $< -o $@
+ @$(POSTCOMPILE)
+
+include $(wildcard $(patsubst %,$(DEPDIR)/%.d,$(basename $(LIBSRCS))))
+
+$(DEPDIR)/%.d: ;
+
+.PRECIOUS: $(DEPDIR)/%.d
+
+#FIXME: add an install target
+
+clean:
+ @echo "[CLN]"
+ -@rm -r $(BUILDDIR)
+ -@rm $(BINARY_NAME)$(BINARY_SUFFIX)
+ -@rm $(BINARY_NAME).static$(BINARY_SUFFIX)
+ -@rm $(BINARY_NAME).dynamic$(BINARY_SUFFIX)
+ -@rm $(LIBRARY_PATH)/$(SLIB_PREFIX)$(LIBRARY_NAME)$(SLIB_SUFFIX)
+ifeq ($(UNAME),Cygwin)
+ -@rm $(LIBRARY_PATH)/$(DLIB_PREFIX)$(CYGWIN_DLIBRARY_NAME)$(DLIB_SUFFIX)
+ -@rm $(LIBRARY_PATH)/$(DLIB_PREFIX)$(LIBRARY_NAME)$(DLIB_SUFFIX).a
+else
+ -@rm $(LIBRARY_PATH)/$(DLIB_PREFIX)$(LIBRARY_NAME)$(DLIB_SUFFIX)
+endif
+
+disassemble: $(BINARY_NAME)$(BINARY_SUFFIX)
+ objdump -d $< | less
+
+symbols: $(BINARY_NAME)$(BINARY_SUFFIX)
+ objdump -t $< | sort | less
/* FIXME: one can split this shape in building blocks and build it using them */
void print_board(int y, int x) {
- mvprintw(y, x, " | |");
- mvprintw(y+1, x, " | |");
- mvprintw(y+2, x, "----+----+----");
- mvprintw(y+3, x, " | |");
- mvprintw(y+4, x, " | |");
- mvprintw(y+5, x, "----+----+----");
- mvprintw(y+6, x, " | |");
- mvprintw(y+7, x, " | |");
+ mvprintw(y, x, " A | B | C | D | E | F | G | H");
+ mvprintw(y+1, x, " -----+----+----+----+----+----+----+-----");
+ mvprintw(y+2, x, "1| | | | | | | | |");
+ mvprintw(y+3, x, " | | | | | | | | |");
+ mvprintw(y+4, x, " +----+----+----+----+----+----+----+----+");
+ mvprintw(y+5, x, "2| | | | | | | | |");
+ mvprintw(y+6, x, " | | | | | | | | |");
+ mvprintw(y+7, x, " +----+----+----+----+----+----+----+----+");
+ mvprintw(y+8, x, "3| | | | | | | | |");
+ mvprintw(y+9, x, " | | | | | | | | |");
+ mvprintw(y+10, x, " +----+----+----+----+----+----+----+----+");
+ mvprintw(y+11, x, "4| | | | | | | | |");
+ mvprintw(y+12, x, " | | | | | | | | |");
+ mvprintw(y+13, x, " +----+----+----+----+----+----+----+----+");
+ mvprintw(y+14, x, "5| | | | | | | | |");
+ mvprintw(y+15, x, " | | | | | | | | |");
+ mvprintw(y+16, x, " +----+----+----+----+----+----+----+----+");
+ mvprintw(y+17, x, "7| | | | | | | | |");
+ mvprintw(y+18, x, " | | | | | | | | |");
+ mvprintw(y+19, x, " +----+----+----+----+----+----+----+----+");
+ mvprintw(y+20, x, "8| | | | | | | | |");
+ mvprintw(y+21, x, " | | | | | | | | |");
+ mvprintw(y+22, x, " -----+----+----+----+----+----+----+-----");
}
-static void print_x(int y, int x) {
+static void print_x(int y, int x, int type) {
mvprintw(y, x, "\\/");
mvprintw(y+1, x,"/\\");
}
-static void print_o(int y, int x) {
+static void print_o(int y, int x, int type) {
mvprintw(y, x, "/\\");
mvprintw(y+1, x, "\\/");
}
-/* y: 1 -> +0 x: 1 -> +1
- * 2 -> +3 2 -> +6
- * 3 -> +6 3 -> +11 */
+/* y = 1: y -> 0 x = 1: 1 -> 1
+ * y > 2: y -> y + 3 2 -> +6 */
+
static int remap_y(int y) {
if (y == 1) {
return 0;
- } else if (y == 2) {
- return 3;
- } else {
- return 6;
+ } else if (y > 1) {
+ return y + 3;
}
}
if (x == 1) {
return 1;
- } else if (x == 2) {
- return 6;
- } else {
- return 11;
+ } else if (x > 2) {
+ return x + 5;
}
}