! Makefile.conf
!    Makefile template for ScidCommunity for Unix operating systems.
!
! This file is NOT an actual Makefile; it is a template file used by 
! the configure program to produce the actual Makefile for ScidCommunity with
! approriate settings for your system. Just type "./configure" in the 
! current directory to run the configuration program.
!
! All lines starting with "!" (such as these) are removed, and certain
! variables enclosed in "@" symbols (such as @TCL_VERSION@) are set.
!
##### Makefile for ScidCommunity for Unix operating systems.

### Compiler: Most Unix systems use g++ for compiling and linking.
#
COMPILE = @COMPILE@
LINK = @LINK@
LIBS = @LIBS@
INSTALL = @INSTALL@

# BINDIR: where the Scid programs are copied for "make install".
#
BINDIR = @BINDIR@

# SHAREDIR: where scidCommunity data files are copied for "make install".
#
SHAREDIR = @SHAREDIR@

### TCL_VERSION: Set this according to the version of Tcl/Tk you have
#   installed that you want Scid to use: 8.0, 8.1, 8.2, 8.3, etc.
#
TCL_VERSION = @TCL_VERSION@

# TCL_INCLUDE, TCL_LIBRARY: these are the compiler options
#    needed for linking Scid with Tcl/Tk.  The program "./configure"
#    will try to determine them automatically, but if it cannot, you
#    can use the examples below for help in setting these variables.
#
# @CONFIG_RESULT@
#
TCL_INCLUDE = @TCL_INCLUDE@
TCL_LIBRARY = @TCL_LIBRARY@


########################################
### Compiler options:

### SCIDFLAGS: Scid customization flags.
#
SCID_VERSION = @SCID_VERSION@
SCID_DATE = @SCID_DATE@
SCIDFLAGS = @SCIDFLAGS@ -DSCID_VERSION_STRING="\"$(SCID_VERSION)\"" -DSCID_BUILD_DATE="\"$(SCID_DATE)\""

### OPTIMIZE: Optimization options for C++ compiler.
#      -O3 is the most optimization for g++. I have found -O2 to do
#      just as well, but someone reported a noticeable difference in speed
#      between -O3 and -O2 so the default here is -O3.
#      On some systems, adding "-fno-rtti" and "-fno-exceptions" produces
#      smaller, faster programs since Scid does not use those C++ features.
#
OPTIMIZE = @OPTIMIZE@ @THREADS@

### DEBUG: Debug flags. Use "-g" to include debugging information and
#       "-DNDEBUG" to disable debugging information and assertions.
#
DEBUG = @DEBUG@

### WARNINGS: I always compile with all warnings on (-Wall), and all the
#       files should compile warning-free using g++.
#
WARNINGS = @WARNINGS@

### PROFILE: Set this to "-pg" for profiling in g++ and gcc.
#
PROFILE = @PROFILE@

### CPP_FLAGS: Flags for C++ compilation.
#
CPP_FLAGS = $(CXXFLAGS) $(CPPFLAGS) $(PROFILE) $(OPTIMIZE) $(WARNINGS) $(DEBUG) $(SCIDFLAGS) $(TB)

############################################################
#
# You should not need to edit anything below this line.
#
############################################################

### EXECS: executable programs compiled from C++ files.
#
EXECS= scidCommunity

### SCIDOBJS:
SCIDCPP= $(wildcard src/*.cpp)
SCIDOBJS= $(SCIDCPP:.cpp=.o)

POLYGLOT= $(wildcard src/polyglot/*.cpp)
XOBJS= $(POLYGLOT:.cpp=.o)

DEPENDS = ${SCIDOBJS:.o=.d} ${XOBJS:.o=.d}

### OBJS: Will be "$(SCIDOBJS)", "$(POLYGLOTOBJS)"
OBJS= @OBJS@

### SCRIPTS:
# Small extra programs. Most are written in Tcl using tkscid, but
# a few contributed ones may be in Python or other languages.
#
SCRIPTS= sc_epgn.tcl sc_spell.tcl sc_eco.tcl sc_import.tcl sc_remote.tk scidpgn.tcl spliteco.tcl spf2spi.tcl

####################

### Type "make" or "make all" to make all programs:
#
all: scidCommunity all_engines
all_engines: phalanx-scid

scidCommunity: $(OBJS) $(XOBJS)
	$(LINK) $(CPP_FLAGS) $(XOBJS) $(OBJS) $(TCL_LIBRARY) $(LIBS) -o $(EXECS)

phalanx-scid:
	cd engines/phalanx-scid/ && $(MAKE) && cd ../../

### To copy all executables to $BINDIR, with read and execute permission 
#   for all users, and put extra files in $SHAREDIR, type "make install".
#

install: $(INSTALL)

install_shared: scidCommunity
	install -m 755 -d "$(SHAREDIR)"
	cp scidCommunity "$(SHAREDIR)"
	cp *.eco "$(SHAREDIR)"
	cp -r bitmaps "$(SHAREDIR)"
	cp -r bitmaps2 "$(SHAREDIR)"
	cp -r books "$(SHAREDIR)"
	cp -r html "$(SHAREDIR)"
	cp -r img "$(SHAREDIR)"
	cp -r scripts "$(SHAREDIR)"
	cp -r sounds "$(SHAREDIR)"
	cp -r tcl "$(SHAREDIR)"

install_scid: install_shared
	install -m 755 -d "$(BINDIR)"
	ln -sf "$(SHAREDIR)/scidCommunity" "$(BINDIR)/scidCommunity"
	@for script in $(SCRIPTS); do \
		cp "scripts/$$script" "$(BINDIR)"; \
		chmod +x "$(BINDIR)/$$script"; \
	done

install_engines: all_engines
	install -m 755 -d "$(SHAREDIR)/engines"
	install -m 755 -d "$(SHAREDIR)/engines/phalanx-scid"
	install ./engines/phalanx-scid/phalanx-scid "$(SHAREDIR)/engines/phalanx-scid"

uninstall:
	cd $(BINDIR) && rm -f $(EXECS) $(SCRIPTS)
	rm -rf $(SHAREDIR)

### To remove object and executable files: type "make clean".
#
clean:
	rm -f scidlet scidlet.d src/*.o src/polyglot/*.o $(EXECS) scidCommunity $(SCRIPTS)
	rm -f src/*.d src/polyglot/*.d
	cd engines/phalanx-scid/ && make clean && cd ../../
	rm -Rf dist

### To make the executable files smaller: type "make strip".
#
strip:
	strip $(EXECS)

### Generic rule for .cpp files:
#
src/%.o: src/%.cpp
	$(COMPILE) $(CPP_FLAGS) $(TCL_INCLUDE) -o $@ -c $<

-include ${DEPENDS}
### End of Makefile
