############################################################################
#** interpcom-3.1    (command interpreter)                                **
#** general makefile                                                      **
#**                                                                       **
#** Copyright (C) 2003  Jean-Marc Drezet                                  **
#**                                                                       **
#**  This library is free software; you can redistribute it and/or        **
#**  modify it under the terms of the GNU Library General Public          **
#**  License as published by the Free Software Foundation; either         **
#**  version 2 of the License, or (at your option) any later version.     **
#**									  **
#**  This library is distributed in the hope that it will be useful,      **
#**  but WITHOUT ANY WARRANTY; without even the implied warranty of       **
#**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU    **
#**  Library General Public License for more details. 			  **
#**									  **
#**  You should have received a copy of the GNU Library General Public    **
#**  License along with this library; if not, write to the Free		  **
#**  Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.   **
#**                                                                       **
#** Please mail any bug reports/fixes/enhancements to me at:              **
#**      drezet@math.jussieu.fr                                           **
#** or                                                                    **
#**      Jean-Marc Drezet                                                 **
#**      Institut de Mathematiques                                        **
#**      UMR 7586 du CNRS                                                 **
#**      173, rue du Chevaleret                                           **
#**      75013 Paris                                                      **
#**      France			 					  **
#**                                                                       **
############################################################################


export CC=gcc

#---------------------------------------------------------------------------
# optimization
#---------------------------------------------------------------------------
# optimization for gcc-2.95.3
#export _OPTIM= -O6 -funroll-loops -fomit-frame-pointer -fno-schedule-insns -fschedule-insns2 -malign-double -fstrict-aliasing -mcpu=pentiumpro

# optimization for gcc-3
#export _OPTIM = -O3 -fomit-frame-pointer -ffast-math -march=pentium4 -mcpu=pentium4

# debug
export _OPTIM = -g
#---------------------------------------------------------------------------



#---------------------------------------------------------------------------
# language
#---------------------------------------------------------------------------
# english
export _LANG= -D_ENG_LANG

# french
# export _LANG= -D_FR_LANG
#---------------------------------------------------------------------------



#---------------------------------------------------------------------------
# command line editing library
#---------------------------------------------------------------------------
# GNU readline library
export LINE_ED= -D__WITH_READLINE
export LINE_ED_LIBS= -lhistory -lreadline -ltermcap 

# libtecla  library
#export LINE_ED= -D__WITH_LIBTECLA
#export LINE_ED_LIBS= -ltecla_r

# no command line editing library
#export LINE_ED= 
#export LINE_ED_LIBS= 
#---------------------------------------------------------------------------



export CFLAGS= -Wall $(_LANG) $(_OPTIM) $(LINE_ED) 
export LIBS= -lpthread $(LINE_ED_LIBS)
#export LIBS= $(LINE_ED_LIBS) 

init :
	@echo
	@echo Options for make :
	@echo "        "   tests "            " : the minimal applications
	@echo "        "   world "            " : the libraries, tests and the application
	@echo "                              "with thread support
	@echo "        "   clean "            " : deletes the object files
	@echo "        "   clean-all "        " : deletes the object files, the libraries 
	@echo "                              "and the executables
	@echo "        "   install "          " : installs the libraries with thread support


world : threads tests help

static : libinter.a libinter_nothr.a convert/interp-convert convert/help_convert

shared : libinter.so.3.1 libinter_nothr.so.3.1 convert/interp-convert convert/help_convert

threads : libinter.a libinter.so.3.1 convert/interp-convert convert/help_convert

nothreads : libinter_nothr.a libinter_nothr.so.3.1 convert/interp-convert convert/help_convert

static-threads : libinter.a convert/interp-convert convert/help_convert

static-nothreads : libinter_nothr.a convert/interp-convert convert/help_convert

shared-threads : libinter.so.3.1 convert/interp-convert convert/help_convert

shared-nothreads : libinter_nothr.so.3.1 convert/interp-convert convert/help_convert

tests : libinter.a convert/interp-convert convert/help_convert
	cd ./test; $(MAKE)

tests-nothr : libinter_nothr.a convert/interp-convert convert/help_convert
	cd ./test; $(MAKE) nothr

pg : libinter_p.a

tests-shared :
	cd ./test; $(MAKE) shared

convert/interp-convert :
	cd ./convert; make

convert/help_convert :
	cd ./convert; make

OBJS =  command_.o complex_.o com_sys_.o ee_.o interp_.o mem_.o objdef_.o \
int_def_.o messg_.o

$(OBJS) : %_.o : %.c
#	$(CC) -c $(CFLAGS)  $< -o $@
	$(CC) -c $(CFLAGS) -D_HAVE_THREADS -D_REENTRANT $< -o $@

OBJS_NOTHR =  command_nothr.o complex_nothr.o com_sys_nothr.o ee_nothr.o \
interp_nothr.o mem_nothr.o objdef_nothr.o int_def_nothr.o messg_nothr.o

$(OBJS_NOTHR) : %_nothr.o : %.c
	$(CC) -c $(CFLAGS) $< -o $@

OBJSP =  command_p.o complex_p.o com_sys_p.o ee_p.o interp_p.o \
mem_p.o objdef_p.o int_def_p.o messg_p.o

$(OBJSP) : %_p.o : %.c
	$(CC) -c $(CFLAGS) -pg  $< -o $@

libinter.a : $(OBJS) help
	ar cr libinter.a *_.o

libinter_p.a : $(OBJSP)
	ar cr libinter_p.a *_p.o

libinter_nothr.a : $(OBJS_NOTHR)
	ar cr libinter_nothr.a *_nothr.o

help : convert/help_convert
	convert/help_convert test/data/interp0.dat test/data/interp.dat 1

clean-all :
	rm -f *.o *.lo *.a *.so.3.1 *% *bck *~
	rm -rf cpp
	cd ./test; $(MAKE) clean-all
	cd ./convert; $(MAKE) clean-all
	rm -f test/data/interp.dat

clean :
	rm -f *.o *.lo *bck *% *~
	cd ./test; $(MAKE) clean
	cd ./convert; $(MAKE) clean

OBJSD = command_.lo complex_.lo com_sys_.lo ee_.lo interp_.lo mem_.lo\
objdef_.lo int_def_.lo messg_.lo

shared : libinter.so.3.1 libinter_nothr.so.3.1

libinter.so.3.1 : $(OBJSD)
	$(CC) -shared -Wl,-soname,libinter.so.3 -o libinter.so.3.1 *_.lo

OBJSD_NOTHR = command_nothr.lo complex_nothr.lo com_sys_nothr.lo \
ee_nothr.lo interp_nothr.lo mem_nothr.lo objdef_nothr.lo int_def_nothr.lo

libinter_nothr.so.3.1 : $(OBJSD_NOTHR)
	$(CC) -shared -Wl,-soname,libinter_nothr.so.3 -o libinter_nothr.so.3.1 *_nothr.lo

$(OBJSD_NOTHR) : %_nothr.lo : %.c
	$(CC) -c $(CFLAGS) -fPIC $< -o $@

$(OBJSD) : %_.lo : %.c
	$(CC) -c $(CFLAGS) -D_HAVE_THREADS -D_REENTRANT -fPIC $< -o $@


install :
	rm -f /usr/local/lib/libinter.so*
	install -m 644 libinter.a /usr/local/lib
	install -m 644 libinter.so.3.1 /usr/local/lib
	install -m 644 interp.h /usr/local/include
	install convert/interp-convert /usr/local/bin
	install convert/help_convert /usr/local/bin
	ln -s /usr/local/lib/libinter.so.3.1 /usr/local/lib/libinter.so.3
	ln -s /usr/local/lib/libinter.so.3 /usr/local/lib/libinter.so
	ldconfig

install-nothreads :
	rm -f /usr/local/lib/libinter_nothr.so*
	install -m 644 libinter_nothr.a /usr/local/lib
	install -m 644 libinter_nothr.so.3.1 /usr/local/lib
	install -m 644 interp.h /usr/local/include
	install convert/interp-convert /usr/local/bin
	install convert/help_convert /usr/local/bin
	ln -s /usr/local/lib/libinter_nothr.so.3.1 /usr/local/lib/libinter_nothr.so.2
	ln -s /usr/local/lib/libinter_nothr.so.3 /usr/local/lib/libinter_nothr.so
	ldconfig

install-all :
	rm -f /usr/local/lib/libinter.so*
	rm -f /usr/local/lib/libinter_nothr.so*
	install -m 644 libinter.a /usr/local/lib
	install -m 644 libinter.so.3.1 /usr/local/lib
	install -m 644 libinter_nothr.a /usr/local/lib
	install -m 644 libinter_nothr.so.3.1 /usr/local/lib
	install -m 644 interp.h /usr/local/include
	install convert/interp-convert /usr/local/bin
	install convert/help_convert /usr/local/bin
	ln -s /usr/local/lib/libinter.so.3.1 /usr/local/lib/libinter.so.2
	ln -s /usr/local/lib/libinter.so.2 /usr/local/lib/libinter.so
	ln -s /usr/local/lib/libinter_nothr.so.3.1 /usr/local/lib/libinter_nothr.so.2
	ln -s /usr/local/lib/libinter_nothr.so.3 /usr/local/lib/libinter_nothr.so
	ldconfig








