Dynamic link library for Gaviota Tablebase (to Miguel)

Programming Topics (Computer Chess) and technical aspects as test techniques, book building, program tuning etc

Moderator: Andres Valverde

Dynamic link library for Gaviota Tablebase (to Miguel)

Postby Michel » 16 Nov 2010, 01:00

Hi. I added a target to the makefile that comes with GTB to create a dynamic link library.
I also added an install target. I have been using it in GnuChess and it seems to work fine.
It makes the deployment of GTB easier in Linux.

Code: Select all
INCLUDE = -Isysport/ \
     -Icompression/ \
     -Icompression/liblzf/ \
     -Icompression/zlib/ \
     -Icompression/lzma/ \
     -Icompression/huffman/

DEFAULT_CC = /usr/bin/gcc
DEFAULT_DEFINE = -DZ_PREFIX
DEFAULT_ARCHFLAGS = -m64
DEFAULT_CFLAGS = -Wall -Wextra -fPIC $(INCLUDE) $(DEFAULT_DEFINE) \
       $(DEFAULT_ARCHFLAGS)
PREFIX = /usr/local
OPTFLAGS = -fast -msse -DNDEBUG
DEBUGFLAGS = -O0 -g -DDEBUG
PGO1FLAGS = $(OPTFLAGS) -fprofile-generate
PGO2FLAGS = $(OPTFLAGS) -fprofile-use

SRCFILES := gtb-probe.c gtb-dec.c gtb-att.c sysport/sysport.c \
      compression/wrap.c compression/huffman/hzip.c \
      compression/lzma/LzmaEnc.c compression/lzma/LzmaDec.c \
      compression/lzma/Alloc.c compression/lzma/LzFind.c \
      compression/lzma/Lzma86Enc.c compression/lzma/Lzma86Dec.c \
      compression/lzma/Bra86.c compression/zlib/zcompress.c \
      compression/zlib/uncompr.c compression/zlib/inflate.c \
      compression/zlib/deflate.c compression/zlib/adler32.c \
      compression/zlib/crc32.c compression/zlib/infback.c \
      compression/zlib/inffast.c compression/zlib/inftrees.c \
      compression/zlib/trees.c compression/zlib/zutil.c \
      compression/liblzf/lzf_c.c compression/liblzf/lzf_d.c
OBJFILES := $(patsubst %.c,%.o,$(SRCFILES))
PROFFILES := $(SRCFILES:.c=.gcno) $(SRCFILES:.c=.gcda)
LIBNAME := libgtb.a
SONAME :=libgtb.so
SOVERSION := 1.0.1
SOMAJORVERSION := 1


.PHONY: all clean
.DEFAULT_GOAL := all

all:
   $(MAKE) $(LIBNAME) \
       CC='$(DEFAULT_CC)' \
       ARCHFLAGS='$(DEFAULT_ARCHFLAGS)' \
       DEFINE='$(DEFAULT_DEFINE)' \
       CFLAGS='$(OPPTFLAGS) $(DEFAULT_CFLAGS)'
   $(MAKE) $(SONAME) \
       CC='$(DEFAULT_CC)' \
       ARCHFLAGS='$(DEFAULT_ARCHFLAGS)' \
       DEFINE='$(DEFAULT_DEFINE)' \
       CFLAGS='$(OPPTFLAGS) $(DEFAULT_CFLAGS)'

$(LIBNAME): $(OBJFILES)
   $(AR) rcs $@ $(OBJFILES)

$(SONAME): $(OBJFILES)   
   $(CC) -shared $(OBJFILES) -Wl,-soname=$(SONAME).$(SOMAJORVERSION) -o $(SONAME).$(SOVERSION)

opt:
   $(MAKE) $(LIBNAME) \
       CC='$(DEFAULT_CC)' \
       ARCHFLAGS='$(DEFAULT_ARCHFLAGS)' \
       DEFINE='$(DEFAULT_DEFINE)' \
       CFLAGS='$(OPTFLAGS) $(DEFAULT_CFLAGS)' \
       LDFLAGS='$(LDFLAGS)'

debug:
   $(MAKE) $(LIBNAME) \
       CC='$(DEFAULT_CC)' \
       ARCHFLAGS='$(DEFAULT_ARCHFLAGS)' \
       DEFINE='$(DEFAULT_DEFINE)' \
       CFLAGS='$(DEBUGFLAGS) $(DEFAULT_CFLAGS)' \
       LDFLAGS='$(LDFLAGS)'

pgo-start:
   $(MAKE) $(LIBNAME) \
       CC='$(DEFAULT_CC)' \
       ARCHFLAGS='$(DEFAULT_ARCHFLAGS)' \
       DEFINE='$(DEFAULT_DEFINE)' \
       CFLAGS='$(PGO1FLAGS) $(DEFAULT_CFLAGS)' \
       LDFLAGS='$(LDFLAGS) -fprofile-generate'

pgo-finish:
   $(MAKE) $(LIBNAME) \
       CC='$(DEFAULT_CC)' \
       ARCHFLAGS='$(DEFAULT_ARCHFLAGS)' \
       DEFINE='$(DEFAULT_DEFINE)' \
       CFLAGS='$(PGO2FLAGS) $(DEFAULT_CFLAGS)' \
       LDFLAGS='$(LDFLAGS) -fprofile-generate'

clean:
   $(RM) -f $(OBJFILES) $(LIBNAME) $(SONAME)

pgo-clean:
   $(RM) -f $(PROFFILES)

install:
   install -m 755 -o root -g root $(LIBNAME) $(SONAME).$(SOVERSION) $(PREFIX)/lib
   ln -sf $(SONAME).$(SOMAJORVERSION) $(PREFIX)/lib/$(SONAME)
   install -m 644 -o root -g root gtb-probe.h $(PREFIX)/include
   ldconfig

.depend:
   $(CC) -MM $(DEFAULT_CFLAGS) $(SRCFILES) > $@

include .depend
Michel
 
Posts: 513
Joined: 01 Oct 2008, 12:15

Re: Dynamic link library for Gaviota Tablebase (to Miguel)

Postby Miguel A. Ballicora » 18 Nov 2010, 09:42

Michel wrote:Hi. I added a target to the makefile that comes with GTB to create a dynamic link library.
I also added an install target. I have been using it in GnuChess and it seems to work fine.
It makes the deployment of GTB easier in Linux.

Code: Select all
INCLUDE = -Isysport/ \
     -Icompression/ \
     -Icompression/liblzf/ \
     -Icompression/zlib/ \
     -Icompression/lzma/ \
     -Icompression/huffman/

DEFAULT_CC = /usr/bin/gcc
DEFAULT_DEFINE = -DZ_PREFIX
DEFAULT_ARCHFLAGS = -m64
DEFAULT_CFLAGS = -Wall -Wextra -fPIC $(INCLUDE) $(DEFAULT_DEFINE) \
       $(DEFAULT_ARCHFLAGS)
PREFIX = /usr/local
OPTFLAGS = -fast -msse -DNDEBUG
DEBUGFLAGS = -O0 -g -DDEBUG
PGO1FLAGS = $(OPTFLAGS) -fprofile-generate
PGO2FLAGS = $(OPTFLAGS) -fprofile-use

SRCFILES := gtb-probe.c gtb-dec.c gtb-att.c sysport/sysport.c \
      compression/wrap.c compression/huffman/hzip.c \
      compression/lzma/LzmaEnc.c compression/lzma/LzmaDec.c \
      compression/lzma/Alloc.c compression/lzma/LzFind.c \
      compression/lzma/Lzma86Enc.c compression/lzma/Lzma86Dec.c \
      compression/lzma/Bra86.c compression/zlib/zcompress.c \
      compression/zlib/uncompr.c compression/zlib/inflate.c \
      compression/zlib/deflate.c compression/zlib/adler32.c \
      compression/zlib/crc32.c compression/zlib/infback.c \
      compression/zlib/inffast.c compression/zlib/inftrees.c \
      compression/zlib/trees.c compression/zlib/zutil.c \
      compression/liblzf/lzf_c.c compression/liblzf/lzf_d.c
OBJFILES := $(patsubst %.c,%.o,$(SRCFILES))
PROFFILES := $(SRCFILES:.c=.gcno) $(SRCFILES:.c=.gcda)
LIBNAME := libgtb.a
SONAME :=libgtb.so
SOVERSION := 1.0.1
SOMAJORVERSION := 1


.PHONY: all clean
.DEFAULT_GOAL := all

all:
   $(MAKE) $(LIBNAME) \
       CC='$(DEFAULT_CC)' \
       ARCHFLAGS='$(DEFAULT_ARCHFLAGS)' \
       DEFINE='$(DEFAULT_DEFINE)' \
       CFLAGS='$(OPPTFLAGS) $(DEFAULT_CFLAGS)'
   $(MAKE) $(SONAME) \
       CC='$(DEFAULT_CC)' \
       ARCHFLAGS='$(DEFAULT_ARCHFLAGS)' \
       DEFINE='$(DEFAULT_DEFINE)' \
       CFLAGS='$(OPPTFLAGS) $(DEFAULT_CFLAGS)'

$(LIBNAME): $(OBJFILES)
   $(AR) rcs $@ $(OBJFILES)

$(SONAME): $(OBJFILES)   
   $(CC) -shared $(OBJFILES) -Wl,-soname=$(SONAME).$(SOMAJORVERSION) -o $(SONAME).$(SOVERSION)

opt:
   $(MAKE) $(LIBNAME) \
       CC='$(DEFAULT_CC)' \
       ARCHFLAGS='$(DEFAULT_ARCHFLAGS)' \
       DEFINE='$(DEFAULT_DEFINE)' \
       CFLAGS='$(OPTFLAGS) $(DEFAULT_CFLAGS)' \
       LDFLAGS='$(LDFLAGS)'

debug:
   $(MAKE) $(LIBNAME) \
       CC='$(DEFAULT_CC)' \
       ARCHFLAGS='$(DEFAULT_ARCHFLAGS)' \
       DEFINE='$(DEFAULT_DEFINE)' \
       CFLAGS='$(DEBUGFLAGS) $(DEFAULT_CFLAGS)' \
       LDFLAGS='$(LDFLAGS)'

pgo-start:
   $(MAKE) $(LIBNAME) \
       CC='$(DEFAULT_CC)' \
       ARCHFLAGS='$(DEFAULT_ARCHFLAGS)' \
       DEFINE='$(DEFAULT_DEFINE)' \
       CFLAGS='$(PGO1FLAGS) $(DEFAULT_CFLAGS)' \
       LDFLAGS='$(LDFLAGS) -fprofile-generate'

pgo-finish:
   $(MAKE) $(LIBNAME) \
       CC='$(DEFAULT_CC)' \
       ARCHFLAGS='$(DEFAULT_ARCHFLAGS)' \
       DEFINE='$(DEFAULT_DEFINE)' \
       CFLAGS='$(PGO2FLAGS) $(DEFAULT_CFLAGS)' \
       LDFLAGS='$(LDFLAGS) -fprofile-generate'

clean:
   $(RM) -f $(OBJFILES) $(LIBNAME) $(SONAME)

pgo-clean:
   $(RM) -f $(PROFFILES)

install:
   install -m 755 -o root -g root $(LIBNAME) $(SONAME).$(SOVERSION) $(PREFIX)/lib
   ln -sf $(SONAME).$(SOMAJORVERSION) $(PREFIX)/lib/$(SONAME)
   install -m 644 -o root -g root gtb-probe.h $(PREFIX)/include
   ldconfig

.depend:
   $(CC) -MM $(DEFAULT_CFLAGS) $(SRCFILES) > $@

include .depend


Thanks!
Seems to compile fine (after I figure that the code here removed the tabs :-)). I will test it later and 'push' it to the repository.
I also needed to remove DEFAULT_ARCHFLAGS = -m64 for 32 bits.
Do we really need that if we are in 64 bits? Is not that for cross compilation?

Miguel
User avatar
Miguel A. Ballicora
 
Posts: 160
Joined: 03 Aug 2005, 02:24
Location: Chicago, IL, USA

Re: Dynamic link library for Gaviota Tablebase (to Miguel)

Postby Michel » 19 Nov 2010, 05:39

Seems to compile fine (after I figure that the code here removed the tabs :-)). I will test it later and 'push' it to the repository.
I also needed to remove DEFAULT_ARCHFLAGS = -m64 for 32 bits.
Do we really need that if we are in 64 bits? Is not that for cross compilation?


I did not look at the rest of the makefile figuring you had a good reason for doing things the
way you did. Privately I also made an autoconf/automake version but it requires
rather intrusive changes (files like NEWS, TODO, README, CHANGELOG, COPYING,...).

I have also not tried to adapt the Mingw makefile. A dll on windows would
be interesting if it was also usable byh MSVC. MSVC needs an import library
to use a .dll, I am not entirely sure that an import library produced by Mingw would
be useable with MSVC (I don't use MSVC, there seems to be no way to install only
the command line tools). Perhaps the compiler experts on this forum know.
Michel
 
Posts: 513
Joined: 01 Oct 2008, 12:15

Re: Dynamic link library for Gaviota Tablebase (to Miguel)

Postby Miguel A. Ballicora » 19 Nov 2010, 08:06

Michel wrote:
Seems to compile fine (after I figure that the code here removed the tabs :-)). I will test it later and 'push' it to the repository.
I also needed to remove DEFAULT_ARCHFLAGS = -m64 for 32 bits.
Do we really need that if we are in 64 bits? Is not that for cross compilation?


I did not look at the rest of the makefile figuring you had a good reason for doing things the
way you did. Privately I also made an autoconf/automake version but it requires
rather intrusive changes (files like NEWS, TODO, README, CHANGELOG, COPYING,...).


Actually, the Makefile to obtain the static library was written by Aaron Becker. He forked the project in github to make customized modifications. I just copied the makefile because I thought it could be interesting for somebody. I acknowledged this in the readme file but now I see that i should have done it in the same Makefile source.

Miguel

I have also not tried to adapt the Mingw makefile. A dll on windows would
be interesting if it was also usable byh MSVC. MSVC needs an import library
to use a .dll, I am not entirely sure that an import library produced by Mingw would
be useable with MSVC (I don't use MSVC, there seems to be no way to install only
the command line tools). Perhaps the compiler experts on this forum know.
User avatar
Miguel A. Ballicora
 
Posts: 160
Joined: 03 Aug 2005, 02:24
Location: Chicago, IL, USA


Return to Programming and Technical Discussions

Who is online

Users browsing this forum: No registered users and 18 guests

cron