##########################################################################
# $Id: Makefile,v 1.42 2001/05/17 16:49:50 dpotter Exp $
#
# Makefile -- for building irmp3
#
# Copyright (C) by Andreas Neuhaus <andy@fasta.fh-dortmund.de>
#		and David Potter <dp-irmp3@dpotter.com>


##########################################################################
# CONFIGURATION (change to your needs before doing "make all")
#

#-------------------------------------------------------------------------
# General settings:
#	Specify install paths and compiler flags

# Edited for Debian GNU/Linux
DESTDIR =
# Install destination paths
PREFIX = /usr/local
BINDIR = $(DESTDIR)/usr/bin
SBINDIR = $(DESTDIR)/usr/sbin
SHAREDIR = $(DESTDIR)/usr/share/irmp3
SOUNDSHAREDIR = $(DESTDIR)/usr/share/sounds/irmp3
CONFDIR = $(DESTDIR)/etc/irmp3

# Compiler/linker settings
CC = gcc
LD = ld
EXTRA_CFLAGS = -O3 -m486 
#EXTRA_CFLAGS = -O3 -m486 -g
EXTRA_LDFLAGS = 
#EXTRA_LDFLAGS = -g


#-------------------------------------------------------------------------
# MPG123 module:
#	For playing mp3 files and streams
#	You need the external program mpg123. See README.

# Undefine this if you don't want MPG123 support
MOD_MPG123 = 1

# Player binary (usually mpg123)
# if mpg123 is not in the path, put the whole pathname here
# e.g. /usr/local/bin/mpg123
MOD_MPG123_BIN = /etc/alternatives/mpg123


#-------------------------------------------------------------------------
# PLAYLIST module:
#	For playing more than one song in a row. Supports
#	Loading playlists from file, scanning dirs/subdirs,
#	shuffle and repeat function.

# Undefine this if you don't want playlist support
MOD_PLAYLIST = 1


#-------------------------------------------------------------------------
# PLAYLISTLIST module:
#	For loading a list of playlists.  That way we can go backward 
#	and forward through our playlists.

# Undefine this if you don't want playlistlist support
MOD_PLAYLISTLIST = 1


#-------------------------------------------------------------------------
# BEEP module:
#	 Provides optional audible beeps for keypresses
#        Requires a secondary DSP device and a program to play
#	 soundfiles (like sox)
#
#	 This module currently only makes noise for sleep
#	 and shuffle commands.

# Undefine this if you don't want any beeps.
MOD_BEEP = 1


#-------------------------------------------------------------------------
# MIXER module:
#	For controlling mixer settings (volume, etc).

# Undefine this if you don't want mixer support
MOD_MIXER = 1

# The mixer device (usually /dev/mixer)
MOD_MIXER_DEV = /dev/mixer


#-------------------------------------------------------------------------
# ENV module:
#	 Provides "environment" settings.  This allows you to
#	 execute several IRMP3 commands at once to set up a
#	 specific environment.
#
#	 For example, I use a "bedtime environment" to set a
#	 low volume, sleep mode on, shuffle on, and load a relaxing
#	 playlist.

# Undefine this if you don't want environment support.
MOD_ENV = 1


#-------------------------------------------------------------------------
# TIMER module:
#	A sleep timer which can fade-out and stop playing
#	after a specified amount of time.

# Undefine this if you don't want timer support
MOD_TIMER = 1


#-------------------------------------------------------------------------
# ALARM module:
#       A module which can act as an alarm clock.
#       It receives a SIG_USR1 or SIG_USR2 signal from an external process
#       (like cron) and executes an environment named
#       "alarm".  It requires MOD_ENV.
# Undefine this if you don't want alarm support
MOD_ALARM = 1


#-------------------------------------------------------------------------
# LIRC module:
#	For controlling IRMP3 with an IR remote control
#	You need the external program LIRC. See README.

# Undefine this if you don't want LIRC support
MOD_LIRC = 1

# Comment this out if you have LIRC version 0.5.x
MOD_LIRC_V06 = 1

# We need the path where to find LIRC (only for 0.5.x)
# MOD_LIRC_DIR = ../lirc-0.5.4


#-------------------------------------------------------------------------
# LCDproc module:
#	For use of an LCDisplay for output and optionally keypad input
#	You need the external program LCDproc. See README.

# Undefine this if you don't want LCDproc support
MOD_LCDPROC = 1

# If this is set to 1, IRMP3 will not try to display a character at the
# upper right corner of the display, because the LCDproc heartbeat
# is displayed there
MOD_LCDPROC_PRESERVEUPPERRIGHT = 1


#-------------------------------------------------------------------------
# CD module
MOD_CD = 1

#-------------------------------------------------------------------------
# NETCTL module:
#	Turns IRMP3 into a network server.  Clients can attach to
#	this server to monitor the status of IRMP3 and/or control it.
#	(experimental)

# Undefine this if you don't want to be a network server
MOD_NETCTL=1
#
# Maximum number of simultaneously attached clients
MOD_NETCTL_MAXCLIENTS=15

#-------------------------------------------------------------------------
# IDLE module:
#	Announces idle time to other modules

# Define this if you want IRMP3 to use mod_autoshutdown or if you
# want to enable clock functionality on the LCD display
MOD_IDLE=1


#-------------------------------------------------------------------------
# AUTOSHUTDOWN module:
#	Automatically terminates IRMP3 after a period of inactivity.
#   Requires mod_idle!

# Define this if you want IRMP3 to automatically shut down
#MOD_AUTOSHUTDOWN=1

#-------------------------------------------------------------------------
# SAVE module:
#      Saves last played song or playlist (with song within that playlist)
#      and position (time) in that song, so that when IRMP3 is restarted
#      it'll start playing the last played song (or song withing playlist)
#      at the exact time where it stopped.
#      Especially useful for those using IRMP3 in car jukeboxes.
      
# Undefine this if you don't want IRMP3 to save the last played 
# song/playlist.
MOD_SAVE = 1

#-------------------------------------------------------------------------
# Debug module:
#	For debugging purpose

# Defining this module will include support for debug output
# and forground operation of IRMP3 (with stdin command control).
#
# check the -f and -v cmdline parameters.
# MOD_DEBUG = 1


##########################################################################
# STOP STOP STOP STOP STOP STOP STOP STOP STOP STOP STOP STOP STOP STOP
# You shouldn't need to edit anything beyond this line!
#

#-------------------------------------------------------------------------
# Target configuration

VERSION = 0.4.3pre6
CFLAGS = -Wall -fno-builtin $(EXTRA_CFLAGS)
LDFLAGS = $(EXTRA_LDFLAGS)
OBJS =	irmp3.o tools.o log.o config.o mod.o
MODS =	

ifdef MOD_MPG123
	OBJS += mod_mpg123.o
	MODS += -DMOD_MPG123
endif

ifdef MOD_PLAYLIST
	OBJS += mod_playlist.o
	MODS += -DMOD_PLAYLIST
endif

ifdef MOD_PLAYLISTLIST
	OBJS += mod_playlistlist.o
	MODS += -DMOD_PLAYLISTLIST
endif

ifdef MOD_BEEP
	OBJS += mod_beep.o
	MODS += -DMOD_BEEP
endif

ifdef MOD_MIXER
	OBJS += mod_mixer.o
	MODS += -DMOD_MIXER
endif

ifdef MOD_ENV
	OBJS += mod_env.o
	MODS += -DMOD_ENV
endif
	
ifdef MOD_TIMER
	OBJS += mod_timer.o
	MODS += -DMOD_TIMER
endif

ifdef MOD_ALARM
        OBJS += mod_alarm.o
        MODS += -DMOD_ALARM
endif

ifdef MOD_LIRC
ifdef MOD_LIRC_V06
	OBJS += mod_lirc.o
	LDFLAGS += -llirc_client
else
	OBJS += $(MOD_LIRC_DIR)/tools/lirc_client.o mod_lirc.o
endif
	MODS += -DMOD_LIRC
endif

ifdef MOD_LCDPROC
	OBJS += mod_lcdproc.o
	MODS += -DMOD_LCDPROC
endif

ifdef MOD_NETCTL
	OBJS += mod_netctl.o
	MODS += -DMOD_NETCTL
endif

ifdef MOD_IDLE
	OBJS += mod_idle.o
	MODS += -DMOD_IDLE
endif

ifdef MOD_AUTOSHUTDOWN
	OBJS += mod_autoshutdown.o
	MODS += -DMOD_AUTOSHUTDOWN
endif

ifdef MOD_CD
	OBJS += mod_cd.o
	MODS += -DMOD_CD
endif

ifdef MOD_SAVE      
	OBJS += mod_save.o
	MODS += -DMOD_SAVE
endif

ifdef MOD_DEBUG
	OBJS += mod_debug.o
	MODS += -DMOD_DEBUG
endif


#-------------------------------------------------------------------------
# Main Targets

all:	irmp3-target

install:irmp3-target
	install -m 755 -o root -g root -s irmp3 $(BINDIR)
	install -d -m 755 -o root -g root $(CONFDIR)
	if [ ! -f $(CONFDIR)/irmp3.conf ]; then install -m 644 -o root -g root examples/irmp3.conf $(CONFDIR); fi
	#if [ ! -f $(CONFDIR)/lirc.conf ]; then install -m 644 -o root -g root examples/lircrc.advanced $(CONFDIR)/lirc.conf; fi
	install -d -m 755 -o root -g root $(SOUNDSHAREDIR)
	install -m 644 -o root -g root share/*.au $(SOUNDSHAREDIR)
	#install -d $(DESTDIR)/usr/share/doc/irmp3
	#cp COMMANDS CONFIG DEVELOPER FAQ HISTORY PROBLEMS README TODO $(DESTDIR)/usr/share/doc/irmp3 
	

clean:
	rm -f *.o *core *~ irmp3

dist:	clean
	tar -C .. -zcf ../irmp3-$(VERSION).tar.gz --exclude=*.log --exclude=*.m3u --exclude=*.mp3 irmp3
	tar -ztf ../irmp3-$(VERSION).tar.gz


#-------------------------------------------------------------------------
# Core Targets

irmp3-target:	$(OBJS)
		$(CC) $(LDFLAGS) -o irmp3 $(OBJS)

irmp3.o:	irmp3.c
		$(CC) $(CFLAGS) -DVERSION=\"$(VERSION)\" -c irmp3.c -o irmp3.o
tools.o:	tools.c
		$(CC) $(CFLAGS) -c tools.c -o tools.o
log.o:		log.c
		$(CC) $(CFLAGS) -c log.c -o log.o
config.o:	config.c
		$(CC) $(CFLAGS) -c config.c -o config.o
mod.o:		mod.c modules.inc
		$(CC) $(CFLAGS) $(MODS) -c mod.c -o mod.o


#-------------------------------------------------------------------------
# Module Targets

mod_mpg123.o:	mod_mpg123.c
		$(CC) $(CFLAGS) -DMOD_NETCTL=0$(MOD_NETCTL) -DMOD_NETCTL_MAXCLIENTS=$(MOD_NETCTL_MAXCLIENTS) -DMOD_MPG123_BIN=\"$(MOD_MPG123_BIN)\" -c mod_mpg123.c -o mod_mpg123.o
mod_playlist.o:	mod_playlist.c
		$(CC) $(CFLAGS) -c mod_playlist.c -o mod_playlist.o
mod_playlistlist.o:	mod_playlistlist.c
		$(CC) $(CFLAGS) -c mod_playlistlist.c -o mod_playlistlist.o
mod_beep.o: 	mod_beep.c
		$(CC) $(CFLAGS) -c mod_beep.c -o mod_beep.o
mod_mixer.o:	mod_mixer.c
		$(CC) $(CFLAGS) -DMOD_MIXER_DEV=\"$(MOD_MIXER_DEV)\" -c mod_mixer.c -o mod_mixer.o
mod_env.o: 	mod_env.c
		$(CC) $(CFLAGS) -c mod_env.c -o mod_env.o
mod_timer.o:	mod_timer.c
		$(CC) $(CFLAGS) -c mod_timer.c -o mod_timer.o
mod_alarm.o:    mod_alarm.c
		$(CC) $(CFLAGS) -c mod_alarm.c -o mod_alarm.o
mod_lirc.o:	mod_lirc.c
ifdef MOD_LIRC_V06
		$(CC) $(CFLAGS) -DMOD_LIRC_V06=1 -c mod_lirc.c -o mod_lirc.o
else
		$(CC) $(CFLAGS) -I$(MOD_LIRC_DIR)/tools -c mod_lirc.c -o mod_lirc.o
endif
mod_lcdproc.o:	mod_lcdproc.c
		$(CC) $(CFLAGS) -DMOD_LCDPROC_PRESERVEUPPERRIGHT=$(MOD_LCDPROC_PRESERVEUPPERRIGHT) -c mod_lcdproc.c -o mod_lcdproc.o
mod_netctl.o: 	mod_netctl.c
		$(CC) $(CFLAGS) -c mod_netctl.c -DVERSION=\"$(VERSION)\" -DMOD_NETCTL_MAXCLIENTS=$(MOD_NETCTL_MAXCLIENTS) -o mod_netctl.o
mod_idle.o: mod_idle.c
		$(CC) $(CFLAGS) -c mod_idle.c -o mod_idle.o
mod_autoshutdown.o: mod_autoshutdown.c
		$(CC) $(CFLAGS) -DMOD_IDLE=0$(MOD_IDLE) -c mod_autoshutdown.c -o mod_autoshutdown.o
mod_cd.o:	mod_cd.c
		$(CC) $(CFLAGS) -c mod_cd.c -o mod_cd.o
mod_save.o:	mod_save.c
		$(CC) $(CFLAGS) -c mod_save.c -o mod_save.o
mod_debug.o:	mod_debug.c
		$(CC) $(CFLAGS) -c mod_debug.c -o mod_debug.o


##########################################################################
# EOF
#
