#===> generated by: genmakep.scr-00.00.12-031121 by cipo@ut.ee <===
#====================================================================
# Makefile for program MCGEN
#      Version: mcgen-00.00.05-040101 by esoolo@ut.ee
#       Author: cipo@ut.ee
#====================================================================
# note: do not forget to uncomment rules for INI files in install target

SHELL = /bin/bash

	EX = mcgen
   BINROOT = .
       EXE = $(BINROOT)/$(EX)
SOURCEROOT = $(DEV)
  HOSTTYPE = `uname -m`

    SRCDIR = src
INCLUDEDIR = $(SOURCEROOT)/include
    BINDIR = $(SOURCEROOT)/bin/$(HOSTTYPE)
    LIBDIR = $(SOURCEROOT)/lib/$(HOSTTYPE)
    INIDIR = $(SOURCEROOT)/ini
 SOURCEDIR = $(SOURCEROOT)/$(SRCDIR)

  CLASSDIR = $(SOURCEDIR)/class

#SOURCE = $(wildcard *.cpp)
SOURCE = \
	molecule.cpp \
	logfile.cpp \
	geomconstr.cpp \
	textfile.cpp \
	four_atomref.cpp \
	bond.cpp \
	bondlist.cpp \
	connectone.cpp \
	connect.cpp \
	bonddef.cpp \
	constdef.cpp \
	atomcommon.cpp \
	atomdef.cpp \
	atomarg.cpp \
	defs.cpp \
	unitdef.cpp \
	units.cpp \
	params.cpp \
	mathfunc.cpp \
	chains.cpp \
	atom.cpp \
	chain.cpp \
	unit.cpp \
	image.cpp \
	worklist.cpp \
	vdwrecord.cpp \
	vdw.cpp \
	unitid.cpp \
	genfieldoutini.cpp \
	genxyz.cpp \
	readxyz.cpp \
	bondinst.cpp \
	energy.cpp \
	replace_atom.cpp \
	mcgen.cpp

   OBJ = $(SOURCE:.cpp=.o)
   INI = $(wildcard *.ini)

LIB_OBJ = \
	$(LIBDIR)/sysutils.o \
	$(LIBDIR)/commline.o \
	$(LIBDIR)/randome.o \
	$(LIBDIR)/fieldin.o \
	$(LIBDIR)/fieldout2.o

ifeq ($(CC),cc)
	CC = g++
endif

GCC = $(CC)
STRIP=strip

CPPFLAGS = -c
GCCFLAGS = -x c++ -Wall -Wshadow -Werror -finline-limit=0 -O0 
LDFLAGS = $(LIB_OBJ) -lm -static 

ifeq ($(DEBUG),yes)
GCCFLAGS = -g -x c++ -Wall -Wshadow -Werror -finline-limit=0 -O0 
endif

# Define targets
#====================================================================

all:
	@echo "#===> command line error: usage...<==="
	@echo "# make  <target>"
	@echo "# Targets are: gcc-classes         - compile all related classes with GCC"
	@echo "#              gcc-classes-cvs     - download from cvs and compile all related"
	@echo "#                                    classes with GCC"
	@echo "#              gcc-compile         - compile program only with GCC"
	@echo "#              gcc-compile-all     - compile program and classes with GCC"
	@echo "#              gcc-compile-all-cvs - download from cvs related classes and"
	@echo "#                                    compile program and related classes"
	@echo "#                                    with GCC"
	@echo "#              install"
	@echo "#              gcc-complete        - compile all with GCC, install and clean"
	@echo "#              gcc-complete-cvs    - download all classes from cvs, compile all"
	@echo "#                                    with GCC, install and clean"
	@echo "#              upload-cvs          - upload changes into cvs"
	@echo "#              clean"
	@echo "#              test"

#====================================================================

#========== GCC: compile and install classes ========================

gcc-classes:
ifneq ($(SYSUTILS_M_DEFINE),1)
	@cd $(CLASSDIR)/sysutils/$(SRCDIR) && $(MAKE) -e DEV=$(DEV) \
	gcc-complete
endif
ifneq ($(COMMLINE_M_DEFINE),1)
	@cd $(CLASSDIR)/commline/$(SRCDIR) && $(MAKE) -e DEV=$(DEV) \
	SYSUTILS_M_DEFINE=1 \
	gcc-complete
endif
ifneq ($(RANDOME_M_DEFINE),1)
	@cd $(CLASSDIR)/randome/$(SRCDIR) && $(MAKE) -e DEV=$(DEV) \
	SYSUTILS_M_DEFINE=1 \
	COMMLINE_M_DEFINE=1 \
	gcc-complete
endif
ifneq ($(FIELDIN_M_DEFINE),1)
	@cd $(CLASSDIR)/fieldin/$(SRCDIR) && $(MAKE) -e DEV=$(DEV) \
	SYSUTILS_M_DEFINE=1 \
	COMMLINE_M_DEFINE=1 \
	RANDOME_M_DEFINE=1 \
	gcc-complete
endif
ifneq ($(FIELDOUT2_M_DEFINE),1)
	@cd $(CLASSDIR)/fieldout2/$(SRCDIR) && $(MAKE) -e DEV=$(DEV) \
	SYSUTILS_M_DEFINE=1 \
	COMMLINE_M_DEFINE=1 \
	RANDOME_M_DEFINE=1 \
	FIELDIN_M_DEFINE=1 \
	gcc-complete
endif

#========== GCC: download, compile and install classes ==============

gcc-classes-cvs:
ifneq ($(SYSUTILS_M_DEFINE),1)
	if test ! -e $(CLASSDIR); then \
		mkdir -p $(CLASSDIR); \
	fi; \
	cd $(CLASSDIR); \
	if test ! -e sysutils; then \
		cvs checkout sysutils; \
	else \
		cvs update sysutils; \
	fi; \
	cd $(CLASSDIR)/sysutils/$(SRCDIR) && $(MAKE) -e DEV=$(DEV) \
	gcc-complete-cvs
endif
ifneq ($(COMMLINE_M_DEFINE),1)
	if test ! -e $(CLASSDIR); then \
		mkdir -p $(CLASSDIR); \
	fi; \
	cd $(CLASSDIR); \
	if test ! -e commline; then \
		cvs checkout commline; \
	else \
		cvs update commline; \
	fi; \
	cd $(CLASSDIR)/commline/$(SRCDIR) && $(MAKE) -e DEV=$(DEV) \
	SYSUTILS_M_DEFINE=1 \
	gcc-complete-cvs
endif
ifneq ($(RANDOME_M_DEFINE),1)
	if test ! -e $(CLASSDIR); then \
		mkdir -p $(CLASSDIR); \
	fi; \
	cd $(CLASSDIR); \
	if test ! -e randome; then \
		cvs checkout randome; \
	else \
		cvs update randome; \
	fi; \
	cd $(CLASSDIR)/randome/$(SRCDIR) && $(MAKE) -e DEV=$(DEV) \
	SYSUTILS_M_DEFINE=1 \
	COMMLINE_M_DEFINE=1 \
	gcc-complete-cvs
endif
ifneq ($(FIELDIN_M_DEFINE),1)
	if test ! -e $(CLASSDIR); then \
		mkdir -p $(CLASSDIR); \
	fi; \
	cd $(CLASSDIR); \
	if test ! -e fieldin; then \
		cvs checkout fieldin; \
	else \
		cvs update fieldin; \
	fi; \
	cd $(CLASSDIR)/fieldin/$(SRCDIR) && $(MAKE) -e DEV=$(DEV) \
	SYSUTILS_M_DEFINE=1 \
	COMMLINE_M_DEFINE=1 \
	RANDOME_M_DEFINE=1 \
	gcc-complete-cvs
endif
ifneq ($(FIELDOUT2_M_DEFINE),1)
	if test ! -e $(CLASSDIR); then \
		mkdir -p $(CLASSDIR); \
	fi; \
	cd $(CLASSDIR); \
	if test ! -e fieldout2; then \
		cvs checkout fieldout2; \
	else \
		cvs update fieldout2; \
	fi; \
	cd $(CLASSDIR)/fieldout2/$(SRCDIR) && $(MAKE) -e DEV=$(DEV) \
	SYSUTILS_M_DEFINE=1 \
	COMMLINE_M_DEFINE=1 \
	RANDOME_M_DEFINE=1 \
	FIELDIN_M_DEFINE=1 \
	gcc-complete-cvs
endif

#========== GCC: serial version =====================================

gcc-compile:
	$(GCC) $(CPPFLAGS) $(GCCFLAGS) -I$(INCLUDEDIR) $(SOURCE)
	$(GCC) -o $(EXE) $(OBJ) $(LDFLAGS)

#========== GCC: compile program and classes ========================

gcc-compile-all: gcc-classes gcc-compile

#========== GCC: download, compile program and classes ==============

gcc-compile-all-cvs: gcc-classes-cvs gcc-compile

#========== install =================================================

install:
	@if test ! -e $(BINDIR); then \
		mkdir -p $(BINDIR); \
		echo "created diretory:" $(LIBDIR); \
	fi
	mv $(EXE) $(BINDIR)/
#	@if test ! -d $(INIDIR); then \
		mkdir -p $(INIDIR); \
		echo "created diretory:" $(INIDIR); \
#	fi
#	cp $(INI) $(INIDIR)/

#========== GCC: compile all and install ============================

gcc-complete: gcc-compile-all install clean

#========== GCC: download, compile all and install ==================

gcc-complete-cvs: gcc-compile-all-cvs install clean

#========== upload into cvs =========================================

upload-cvs:
	cvs commit -R *
	cd $(BINDIR); cvs commit -R *
ifneq ($(SYSUTILS_M_DEFINE),1)
	cd $(CLASSDIR)/sysutils/$(SRCDIR) && $(MAKE) -e DEV=$(DEV) \
	upload-cvs
endif
ifneq ($(COMMLINE_M_DEFINE),1)
	cd $(CLASSDIR)/commline/$(SRCDIR) && $(MAKE) -e DEV=$(DEV) \
	SYSUTILS_M_DEFINE=1 \
	upload-cvs
endif
ifneq ($(RANDOME_M_DEFINE),1)
	cd $(CLASSDIR)/randome/$(SRCDIR) && $(MAKE) -e DEV=$(DEV) \
	SYSUTILS_M_DEFINE=1 \
	COMMLINE_M_DEFINE=1 \
	upload-cvs
endif
ifneq ($(FIELDIN_M_DEFINE),1)
	cd $(CLASSDIR)/fieldin/$(SRCDIR) && $(MAKE) -e DEV=$(DEV) \
	SYSUTILS_M_DEFINE=1 \
	COMMLINE_M_DEFINE=1 \
	RANDOME_M_DEFINE=1 \
	upload-cvs
endif

#========== remove object files and binary ==========================

clean:
	rm -f $(EXE) $(OBJ)

#========== compile and run the program with simple test data =======

test:
	./mcgen -d defs.ini -u units.ini -r randomseed.ini -p params.ini -c chains.ini -f field.ini

%.o:	%.cpp %.h
	$(GCC) $(CPPFLAGS) $(GCCFLAGS) -I$(INCLUDEDIR) $< -o $@

mcgen:	$(OBJ)
	$(GCC) -o $(EXE) $(OBJ) $(LDFLAGS)
ifneq ($(DEBUG),yes)
	$(STRIP) mcgen
endif
	# ---------- COMPILATION OK ----------

mcgen.xyz:	mcgen defs.ini units.ini randomseed.ini params.ini chains.ini field.ini
	./mcgen -d defs.ini -u units.ini -r randomseed.ini -p params.ini -c chains.ini -f field.ini
