# 
# Copyright (C) 1994, 1995, 1996
#            Olav Woelfelschneider (wosch@rbg.informatik.th-darmstadt.de)
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program 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 General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
#

##############################################################################
# User configurable stuff below.
##############################################################################
#
# PC-linux
#
# - If you are running ELF and want the library built shared (saves memory!)
#   then make sure BUILD_SHARED is YES.
#   Beware, you will not be able to test the programs prior to installation
#   if you define this.
#   If you insist on testing (I would :), build it without BUILD_SHARED,
#   test the programs, and finally, if you like them (I hope so...),
#   define BUILD_SHARED and do make clean; make all; make install.
#   BUILD_SHARED WILL __NOT__ WORK ON A.OUT SYSTEMS!!!
#
# - Add -DUSE_META to CGLOBAL if your keyboard's Alt key is labelled Meta
#   and/or you want to see a `Meta' instead of an 'Alt' pictogram before
#   key-shortcuts in the menus.
#
# - You need LIBDIR only if you use BUILD_SHARED. A library libMcTools.so.1
#   will be installed there. Make sure the path is in /etc/ld.so.conf
#   (/usr/local/lib usually is).
#   
# - If you have at least gcc-2.7.0 and a pentium, the second OPTIMIZE line
#   should be your choice of the day.
#

#BUILD_SHARED = YES
BINDIR       = /usr/local/bin
DEFAULTDIR   = /usr/lib/X11/app-defaults
MANDIR       = /usr/local/man/man1
LIBDIR       = /usr/local/lib

MKDIR        = mkdirhier
HOSTOPTS     = -Dlinux -DHAS_GLOB
AR           = ar rcs
RANLIB       =
CEXTRA       =
LEXTRA       = -L/usr/X11R6/lib
OPTIMIZE    = -O2 -fomit-frame-pointer $(CEXTRA)
#OPTIMIZE     = -O2 -fomit-frame-pointer -pipe -m486 -malign-loops=2 -malign-jumps=2 -malign-functions=2 $(CEXTRA)

##############################################################################
# No user servicable parts below...
##############################################################################

CC       = gcc
CPP      = gcc -E
CGLOBAL  =  
LGLOBAL  = -lXpm -lm

ifdef DEBUG
COPTS  = -g -DDEBUG_CODE $(CEXTRA) -Wall -Wstrict-prototypes -Wmissing-prototypes -Wshadow -Wnested-externs -Winline -Wunused
LDOPTS = $(LEXTRA)
else
COPTS  = $(HOSTOPTS) $(OPTIMIZE)
LDOPTS = -s $(LEXTRA)
endif

# private stuff, it won't be of any use to you.
#USE_RC5    = 1

ifdef USE_RC5
RC5OPTS  =  -DUSE_RC5
LIBOPTS  = -lrc5
endif

all:: McTools xplaycd xmixer xgetfile xmdb xg3

ifeq (.depend,$(wildcard .depend))
include .depend
else
DEPEND=needdepend
endif

lib:: McTools

McTools:: $(DEPEND)
	cd McTools; make COPTS='$(COPTS) $(CGLOBAL)' CC='$(CC)' LDOPTS='$(LDOPTS)' AR='$(AR)' RANLIB='$(RANLIB)' BUILD_SHARED='$(BUILD_SHARED)'

xplaycd:: $(DEPEND)
	cd XPlaycd; make COPTS='$(COPTS) $(CGLOBAL) $(RC5OPTS)' CC='$(CC)' LDOPTS='$(LDOPTS)' XLIBS='$(XLIBS) $(LGLOBAL)' LIBOPTS='$(LIBOPTS)'
	if [ -f XPlaycd/xplaycd ]; then mv XPlaycd/xplaycd . ; fi
	sync

xmixer:: $(DEPEND)
	cd XMixer;  make COPTS='$(COPTS) $(CGLOBAL) $(RC5OPTS)' CC='$(CC)' LDOPTS='$(LDOPTS)' XLIBS='$(XLIBS) $(LGLOBAL)' LIBOPTS='$(LIBOPTS)'
	if [ -f XMixer/xmixer ];   then mv XMixer/xmixer .   ; fi
	sync

xgetfile:: $(DEPEND)
	cd XGetFile;  make COPTS='$(COPTS) $(CGLOBAL) $(RC5OPTS)' CC='$(CC)' LDOPTS='$(LDOPTS)' XLIBS='$(XLIBS) $(LGLOBAL)' LIBOPTS='$(LIBOPTS)'
	if [ -f XGetFile/xgetfile ];   then mv XGetFile/xgetfile .   ; fi
	sync

xmdb:: $(DEPEND)
	cd XMdb;  make COPTS='$(COPTS) $(CGLOBAL) $(RC5OPTS)' CC='$(CC)' LDOPTS='$(LDOPTS)' XLIBS='$(XLIBS) $(LGLOBAL)' LIBOPTS='$(LIBOPTS)'
	if [ -f XMdb/xmdb ];   then mv XMdb/xmdb .   ; fi
	sync

xg3:: $(DEPEND)
	cd XG3;  make COPTS='$(COPTS) $(CGLOBAL) $(RC5OPTS)' CC='$(CC)' LDOPTS='$(LDOPTS)' XLIBS='$(XLIBS) $(LGLOBAL)' LIBOPTS='$(LIBOPTS)'
	if [ -f XG3/xg3 ];   then mv XG3/xg3 .   ; fi
	sync

custom:: $(DEPEND)
	cd $(CUSTOM);  make COPTS='$(COPTS) $(CGLOBAL) $(RC5OPTS)' CC='$(CC)' LDOPTS='$(LDOPTS)' XLIBS='$(XLIBS) $(LGLOBAL)' LIBOPTS='$(LIBOPTS)'

clean::
	cd McTools;    make clean
	cd XPlaycd;    make clean
	cd XMixer;     make clean
	cd XGetFile;   make clean
	cd XMdb;       make clean
	cd XG3;        make clean

proper::
	rm -f .depend xplaycd xmixer xgetfile xmdb xg3
	find . -name "\#*\#" -exec rm {} \;
	find . -name "*.bak" -exec rm {} \;
	find . -name "*~" -exec rm {} \;
	cd McTools;    make proper
	cd XPlaycd;    make proper
	cd XMixer;     make proper
	cd XGetFile;   make proper
	cd XMdb;       make proper
	cd XG3;        make proper

depend::
	cd McTools;    make CPP='$(CPP)' depend
	cd XPlaycd;    make CPP='$(CPP)' depend
	cd XMixer;     make CPP='$(CPP)' depend
	cd XGetFile;   make CPP='$(CPP)' depend
	cd XMdb;       make CPP='$(CPP)' depend
	cd XG3;        make CPP='$(CPP)' depend
	touch .depend

install:
	-$(MKDIR) $(BINDIR)
	-$(MKDIR) $(DEFAULTDIR)
	-$(MKDIR) $(MANDIR)
ifeq ($(BUILD_SHARED),YES)
	$(MKDIR) $(LIBDIR)
	install -o root -m 755 McTools/libMcTools.so $(LIBDIR)/libMcTools.so.1
	ldconfig
endif
	install -s -o root -m 755 xplaycd xmixer xgetfile xmdb xg3 $(BINDIR)
	install -o root -m 644 XPlaycd/XPlaycd            $(DEFAULTDIR)
	install -o root -m 644 XPlaycd/xplaycd.1          $(MANDIR)
	install -o root -m 644 XMixer/XMixer              $(DEFAULTDIR)
	install -o root -m 644 XMixer/xmixer.1            $(MANDIR)
	install -o root -m 644 XGetFile/xgetfile.1        $(MANDIR)

dist::
	(cd ..; tar cvzf multimedia.tar.gz multimedia/[A-Z]* multimedia/[a-z]*)

needdepend: depend
	@echo
	@echo "Dependency information created, please re-run make and ignore"
	@echo "the error that follows."
	@echo
	@exit 1



