
# -*- sh_mode -*-

# Makefile -- written for Juice
#  Copyright (C) 2000, 2001, 2002 Abraham vd Merwe
#
#  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.

ifeq (${SYSTYPE},"debian")
prefix = ${DESTDIR}/usr
bindir = ${prefix}/bin
datadir = ${prefix}/share
sysconfdir = ${DESTDIR}/etc
#localstatedir = ${DESTDIR}/var/lib
CPPFLAGS = -DDEBIAN
else
ifeq (${SYSTYPE},"default")
prefix = /usr/local
bindir = ${prefix}/bin
datadir = ${prefix}/lib
sysconfdir = /etc
#localstatedir = /var/local/lib
CPPFLAGS = -DDEFAULT
else
TEST_ONLY = 1
CPPFLAGS = -DTEST
endif
endif

BIN = juice
BINGRP = bin
BINOWN = root
BINMODE = 0555

DATAGRP = bin
DATAOWN = root
DATAMODE = 0444

CFGGRP = bin
CFGOWN = root
CFGMODE = 0644

DATADIR = ${datadir}/juice
HLPDIR = ${DATADIR}/help

##
## Source variables
##

SUBDIRS = dialogs config mixer mpg123 player

OBJECTS = mpg123.o mixer.o playlist.o menus.o juice.o

DIALOG_OBJECTS = regexp.o vfs.o windows.o background.o dialogs.o utils.o
CONFIG_OBJECTS = config.o
MIXER_OBJECTS = mixer.o
MPG123_OBJECTS = utils.o queue.o id3.o describe.o mpg123.o
PLAYER_OBJECTS = cmd.o console.o child.o

##
## Automatically generated variables
##

DLGOBJS = ${addprefix dialogs/,${DIALOG_OBJECTS}}
CFGOBJS = ${addprefix config/,${CONFIG_OBJECTS}}
MIXOBJS = ${addprefix mixer/,${MIXER_OBJECTS}}
MPGOBJS = ${addprefix mpg123/,${MPG123_OBJECTS}}
PLROBJS = ${addprefix player/,${PLAYER_OBJECTS}}

HLPFILES = ${wildcard help/*.hlp}

PRGOBJS = ${OBJECTS} ${DLGOBJS} ${CFGOBJS} ${MIXOBJS} ${MPGOBJS} ${PLROBJS}

SOURCES = ${OBJECTS:.o=.C}

##
## Program flags
##

CPPFLAGS += # -DDEBUG

CC = g++
CFLAGS = -Wall -O2 -Winline

CXX = g++
CXXFLAGS = ${CFLAGS}

LD = ld
LDFLAGS =
LDLIBS = -lncurses -lpanel

INSTALL = install
INSTALL_PROGRAM = ${INSTALL} #-s
INSTALL_DATA = ${INSTALL}

##
## Rules
##

.PHONY: all clean install uninstall distclean do-it-all with-depends without-depends ${SUBDIRS}

all: do-it-all

ifeq (.depends,${wildcard .depends})
include .depends
do-it-all: with-depends
else
do-it-all: without-depends
endif

without-depends: depend with-depends

with-depends: ${SUBDIRS} ${BIN}

${BIN}: ${PRGOBJS}

${SUBDIRS}:
	${MAKE} -C $@ all

# Figure out a way to create dependencies for the header file as well
depend: ${SOURCES}
	rm -f .depends
	set -e; for F in ${SOURCES}; do ${CC} -MM ${CPPFLAGS} $$F >> .depends; done

clean:
	rm -f .depends *~ ${OBJECTS} ${BIN}

# Figure out a way to make a clean rule for recursive make's as well
distclean: clean
	rm -f saved.jpl
	for DIR in ${SUBDIRS}; do ${MAKE} -C $$DIR clean; done

ifndef TEST_ONLY
install: ${HLPFILES} ${BIN}
	${INSTALL} -d ${bindir} ${sysconfdir} ${DATADIR} ${HLPDIR}
	${INSTALL_PROGRAM} -g ${BINGRP} -o ${BINOWN} -m ${BINMODE} ${BIN} ${bindir}
	${INSTALL_DATA} -g ${DATAGRP} -o ${DATAOWN} -m ${DATAMODE} ${HLPFILES} ${HLPDIR}
	${INSTALL_DATA} -g ${CFGGRP} -o ${CFGOWN} -m ${CFGMODE} setup.cfg ${sysconfdir}/juice.conf

uninstall:
	rm -f ${bindir}/${BIN} ${sysconfdir}/juice.conf
	rm -rf ${DATADIR} ${HELPDIR}
endif

