############################################################################
#** interpcom-2.3    (command interpreter)                                **
#** general makefile                                                      **
#**                                                                       **
#** Copyright (C) 2001  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                                        **
#**      Aile 45-55                                                       **
#**      2, place Jussieu                                                 **
#**      75251 Paris Cedex 05                                             **
#**      France			 					  **
#**                                                                       **
############################################################################


#---------------------------------------------------------------------------
# optimization
#---------------------------------------------------------------------------
export _OPTIM= -O6 -funroll-loops -malign-double 

# the best optimization for pentiums pro, II, III
# export _OPTIM= -O6 -fomit-frame-pointer -fno-schedule-insns -fschedule-insns2 -malign-double -fstrict-aliasing -mcpu=pentiumpro

# no optimization
# export _OPTIM = -g
#---------------------------------------------------------------------------



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

# french
# export _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

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



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


init :
	@echo
	@echo Options for make :
	@echo "        "   static-threads "   " : static library with thread support
	@echo "        "   static-nothreads " " : static library with no thread support
	@echo "        "   static "           " : the two static libraries
	@echo "        "   shared-threads "   " : shared library with thread support
	@echo "        "   shared-nothreads " " : shared library with no thread support
	@echo "        "   shared "           " : the two shared libraries
	@echo "        "   threads "          " : the static and shared libraries with thread
	@echo "                              "support
	@echo "        "   nothreads "        " : the static and shared libraries with no thread
	@echo "                              "support
	@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
	@echo "        "   install-nothreads "" : installs the libraries with no thread support
	@echo "        "   install-all "      " : installs the two kinds of libraries


world : threads tests

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

shared : libinter.so.2.3 libinter_nothr.so.2.3 convert/interp-convert

threads : libinter.a libinter.so.2.3 convert/interp-convert

nothreads : libinter_nothr.a libinter_nothr.so.2.3 convert/interp-convert

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

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

shared-threads : libinter.so.2.3 convert/interp-convert

shared-nothreads : libinter_nothr.so.2.3 convert/interp-convert

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

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

pg : libinter_p.a

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

convert/interp-convert :
	cd convert; make

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

$(OBJS) : %_.o : %.c
	$(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

$(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

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

libinter.a : $(OBJS)
	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

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

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

shared : libinter.so.2.3 libinter_nothr.so.2.3

libinter.so.2.3 : $(OBJSD)
	$(CC) -shared -Wl,-soname,libinter.so.2 -o libinter.so.2.3 *_.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.2.3 : $(OBJSD_NOTHR)
	$(CC) -shared -Wl,-soname,libinter_nothr.so.2 -o libinter_nothr.so.2.3 *_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.2.3 /usr/local/lib
	install -m 644 interp.h /usr/local/include
	install convert/interp-convert /usr/local/bin
	ln -s /usr/local/lib/libinter.so.2.3 /usr/local/lib/libinter.so.2
	ln -s /usr/local/lib/libinter.so.2 /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.2.3 /usr/local/lib
	install -m 644 interp.h /usr/local/include
	install convert/interp-convert /usr/local/bin
	ln -s /usr/local/lib/libinter_nothr.so.2.3 /usr/local/lib/libinter_nothr.so.2
	ln -s /usr/local/lib/libinter_nothr.so.2 /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.2.3 /usr/local/lib
	install -m 644 libinter_nothr.a /usr/local/lib
	install -m 644 libinter_nothr.so.2.3 /usr/local/lib
	install -m 644 interp.h /usr/local/include
	install convert/interp-convert /usr/local/bin
	ln -s /usr/local/lib/libinter.so.2.3 /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.2.3 /usr/local/lib/libinter_nothr.so.2
	ln -s /usr/local/lib/libinter_nothr.so.2 /usr/local/lib/libinter_nothr.so
	ldconfig

cpp :
	mkdir cpp
	cp Makefiles/makefile.cpp cpp/makefile
	cd cpp; make









