diff --git a/.gitignore b/.gitignore index 39f9245..2f5fb48 100644 --- a/.gitignore +++ b/.gitignore @@ -1,23 +1,17 @@ core vgcore.* -GPATH -GRTAGS -GTAGS -fen -pool -piece -move -bits -eval -debug -brchess -*.o *.s +*.i *.old *.save -# /test/ +/.ccls-root +/.ccls-cache/ /obj/ /lib/ -/deps/ +/libobj/ +/bin/ +/dep/ +/tmp/ /notused/ valgrind.out +compile_commands.json diff --git a/FENTESTS.txt b/FENTESTS.txt deleted file mode 100644 index fcab929..0000000 --- a/FENTESTS.txt +++ /dev/null @@ -1,38 +0,0 @@ -4k3/4p3/8/b7/1BR1p2p/1Q3P2/5N2/4K3 w - - 0 1 -r1bq1rk1/pppp1ppp/2n2n2/4p3/2B1P3/3PPN2/PPP3PP/RN1QK2R b KQ - 1 7 -6k1/6pp/R2p4/p1p5/8/1P1r3P/6P1/6K1 b - - 3 37 - -# both can castle queen only -r3k2r/8/3B4/8/8/3b4/8/R3K2R w KQkq - 0 1 -r3k2r/8/3BB3/8/8/3bb3/8/R3K2R w KQkq - 0 1 -r2bkb1r/8/8/8/8/3bb3/8/R2BKB1R w KQkq - 0 1 - -# 4 castle possible, only K+R -r3k2r/8/8/8/8/8/8/R3K2R w KQkq - 0 1 - -# illegal positions -4k3/8/8/8/7b/8/8/4K3 b - - 0 1 -2r1k3/3P4/8/8/8/8/8/4K3 w - - 0 1 - -# only kings on A1/A8, white to play -k7/8/8/8/8/8/8/K7 w - - 0 1 - -# only one move possible (Pf2xBg3) -k7/8/8/1p1p4/pPpPp3/P1PpPpb1/NBNP1P2/KBB1B3 w - - 0 1 - -# only 2 moves possible (Ph5xg6 e.p., Ph5-h6) -k7/8/8/1p1p2pP/pPpPp3/P1PpPp2/NBNP1P2/KBB1B3 w - g6 0 1 - -# 2 Kings, W/B/ pawns on 7th for promotion -k4n2/4P3/8/8/8/8/4p3/K4N2 w - - 0 1 - -# position after 1.e4 -rnbqkbnr/pppppppp/8/8/4P3/8/PPPP1PPP/RNBQKBNR b KQkq - 0 1 -# position after 1.Nh3 -rnbqkbnr/pppppppp/8/8/8/7N/PPPPPPPP/RNBQKB1R b KQkq - 1 1 - -# white castled, and can e.p. on c6 black can castle -# white is a pawn down -# white has 35 or 36 moves: P=11 + 1 e.p. N=6+3 B=5+5 R=1 Q=3 K=1 + 1 e.p. -# black has 32 or 33 moves: P=11 N=2+7 B=5 R=3 Q=3 K=1 + castle -rnbqk2r/pp1pbpp1/7p/2pPp3/4n3/3B1N2/PPP2PPP/RNBQ1RK1 w kq c6 0 7 diff --git a/Makefile b/Makefile index 6162446..dfea2f4 100644 --- a/Makefile +++ b/Makefile @@ -18,9 +18,6 @@ TOUCH := touch RM := rm RMDIR := rmdir -CCLSROOT := .ccls-root -CCLSFILE := compile_commands.json - SRCDIR := ./src INCDIR := ./include OBJDIR := ./obj @@ -30,16 +27,18 @@ LIBOBJDIR := ./libobj BINDIR := ./bin LIBDIR := ./lib -DEPDIR := ./deps +DEPDIR := ./dep + +CCLSROOT := .ccls-root +CCLSFILE := compile_commands.json SRC := $(wildcard $(SRCDIR)/*.c) # project sources SRC_FN := $(notdir $(SRC)) # source basename OBJ := $(addprefix $(OBJDIR)/,$(SRC_FN:.c=.o)) LIBSRC := $(wildcard $(LIBSRCDIR)/*.c) # lib sources -LIBSRC_FN := $(notdir $(LIBSRC)) # lib sources basename +LIBSRC_FN := $(notdir $(LIBSRC)) # lib sources basename LIBOBJ := $(addprefix $(LIBOBJDIR)/,$(LIBSRC_FN:.c=.o)) # and lib obj ones -#LIBOBJ := $(patsubst %.c,%.o,$(LIBSRC)) LIB := br_$(shell uname -m) # library name SLIB := $(addsuffix .a, $(LIBDIR)/lib$(LIB)) # static lib @@ -48,7 +47,6 @@ DLIB := $(addsuffix .so, $(LIBDIR)/lib$(LIB)) # dynamic lib DEP_FN := $(SRC_FN) $(LIBSRC_FN) DEP := $(addprefix $(DEPDIR)/,$(DEP_FN:.c=.d)) -#TARGETS := fen piece move eval brchess TARGET_FN := brchess TARGET := $(addprefix $(BINDIR)/,$(TARGET_FN)) @@ -67,6 +65,7 @@ CPPFLAGS += -DDEBUG_EVAL # eval functions CPPFLAGS += -DDEBUG_PIECE # piece list management CPPFLAGS += -DDEBUG_SEARCH # move search +# remove extraneous spaces (due to spaces before comments) CPPFLAGS := $(strip $(CPPFLAGS)) ##################################### compiler flags @@ -87,7 +86,7 @@ CFLAGS := $(strip $(CFLAGS)) ##################################### archiver/linker/dependency flags ARFLAGS := rcs LDFLAGS := -L$(LIBDIR) -DEPFLAGS := -MMD -MP -MF $(DEPDIR)/$*.d +DEPFLAGS = -MMD -MP -MF $(DEPDIR)/$*.d ##################################### General targets .PHONY: all clean cleanall @@ -130,9 +129,9 @@ define rmdir @#echo "rmdir +$(1)+" $(eval $@_EXIST = $(wildcard $(1))) @#echo "existdir=+${$@_EXIST}+" - @if [[ -n "${$@_EXIST}" ]]; then \ - echo "removing $(2) dir." ; \ - $(RMDIR) ${$@_EXIST} ; \ + @if [[ -n "${$@_EXIST}" ]]; then \ + echo "removing $(2) dir." ; \ + $(RMDIR) ${$@_EXIST} ; \ fi endef @@ -145,13 +144,13 @@ alldirs: $(ALLDIRS) # Here, we have something like: # a: a -# a will be built if older than a, or does not exist. +# a will be built if (1) older than a, or (2) does not exist. Here only (2). $(ALLDIRS): $@ @echo creating $@ directory. @mkdir -p $@ ##################################### Dependencies files -.PHONY: cleandeps cleandepsdir +.PHONY: cleandep cleandepdir -include $(wildcard $(DEP)) @@ -195,10 +194,10 @@ cleanlibobjdir: $(call rmdir,$(LIBOBJDIR),brlib objects) $(LIBOBJDIR)/%.o: $(LIBSRCDIR)/%.c | $(LIBOBJDIR) $(DEPDIR) - @echo compiling $<. - @$(CC) -c $(DEPFLAGS) $(CPPFLAGS) $(CFLAGS) $< -o $@ + @echo compiling library $< "->" $@. + $(CC) -c $(DEPFLAGS) $(CPPFLAGS) $(CFLAGS) $< -o $@ -##################################### libraries +##################################### brlib libraries .PHONY: libs cleanlib cleanlibdir cleanlib: @@ -209,13 +208,6 @@ cleanlibdir: libs: $(DLIB) $(SLIB) -# remove default rule -%.o: %.c - -$(LIBOBJDIR)/%.o: $(LIBSRCDIR)/%.c | $(LIBOBJDIR) $(DEPDIR) - @echo compiling library $< "->" $@. - @$(CC) -c $(DEPFLAGS) $(CPPFLAGS) $(CFLAGS) $< -o $@ - $(DLIB): CFLAGS += -fPIC $(DLIB): LDFLAGS += -shared $(DLIB): $(LIBOBJ) | $(LIBDIR) @@ -237,7 +229,8 @@ cleanbin: cleanbindir: $(call rmdir,$(BINDIR),binaries) -$(TARGET): $(DLIB) $(OBJ) | $(BINDIR) +# We don't use static lib, but we could build it here +$(TARGET): $(DLIB) $(OBJ) | $(BINDIR) $(SLIB) @echo generating $@ executable. @$(CC) $(LDFLAGS) $(OBJ) $(LIBS) -o $@ @@ -270,7 +263,7 @@ $(CCLSFILE): cleanobj cleanlibobj $(SRC) $(LIBSRC) | $(CCLSROOT) #.PHONY: bear #bear: cleanobj cleanlibobj Makefile | $(CCLSROOT) -# @$(BEAR) -- make compile +# @$(BEAR) -- make compile ##################################### valgrind (mem check) .PHONY: memcheck @@ -300,13 +293,8 @@ showflags: wtf: @printf "LIBOBJDIR=%s\n\n" "$(LIBOBJDIR)" @printf "LIBOBJ=%s\n\n" "$(LIBOBJ)" - @printf "OBJDIR=%s\n\n" "$(OBJDIR)" @printf "OBJ=%s\n\n" "$(OBJ)" - @#echo LIBOBJ=$(LIBOBJ) - @#echo DEPS=$(DEPS) - @#echo LIBSRC=$(LIBSRC) - @#echo LIBOBJ=$(LIBOBJ) - @#echo DEPS=$(DEPS) + @#echo DEP=$(DEP) @#echo LIBSRC=$(LIBSRC)