# ########################################################################
#
#                   Makefile for Y Utility Programs
#
#   Rules:
#
#       all     -- builds program.
#       install -- install program.
#       clean   -- remove object and other work files.
#
#       If no arguments are givin, the program is built by default.
#

# ########################################################################
# Installation Options:
#
#   You may modify any value as needed. Change only the ones you are
#   absolutly sure that requires modification.
#
PREFIX = /usr


# ########################################################################
# Compiler Flags:
#
#   These are definations to enable or disable certain compile time
#   options. Omitting a defination turns that option off.
#
#   Each argument is of the format -D<option> where <option> is
#   one of the following:
#
#	* None available *
#
#   Other arguments include:
#
#       -O#                     Specifies the optimization level the
#                               compiler is to compile at. This (attempts)
#                               to improve the efficiency of the generated
#                               program when it runs. Available values for
#                               # are from 0 to 2 (some compilers allow
#                               higher values). When in doubt, set # to 2.
#
#       -g                      Compile with debugging information,
#                               this is useful for determining why this
#                               program (if it did) crash. However this
#                               may hinder performance, so don't use
#                               this option unless you are attempting
#                               to debug the program.
#

CFLAGS = -Wall -O2 -g
#CFLAGS = -Wall -O2 \
#         -fomit-frame-pointer -funroll-loops -finline-functions \
#         -ffast-math -march=i586


# ########################################################################
# Dependant Libraries:
#
#   These are dynamic (sometimes called shared) libraries that this
#   program is to be `linked' to.
#
#   Each argument is of the format -l<name> where <name> is the name
#   of the library. You may have to add one or more -l<name> arguments
#   to the LIB line depending on what you have set in the CFLAGS line
#   farther above.
#
LIB = -lY2

# Library Directories:
#
#   All libraries are looked for in the directories specified below.
#
#   Each argument is of the format -L<dir> where <dir> is the full
#   path to the directory.
#
LIB_DIR = -L../libY2

# Header File Directories:
#
#   Required header files that are not in the standard locations are
#   searched for in the directories specified below.
#
#   Each argument is of the format -I<dir> where <dir> is the full
#   path to the directory.
#
INC =


# ########################################################################
# Program Source and Header Files:
#
PROGS  = helloworld yaudiocd yclientmessage yhost ymixer yplay \
         yrecinfo yset yshutdown
CC     = cc
CPP    = c++


# ########################################################################
# Build rules:
#

all: $(PROGS)

helloworld:
	$(CC) $(CFLAGS) $(INC) $(LIB_DIR) $(LIB) \
	helloworld.c -o helloworld

yaudiocd:
	$(CC) $(CFLAGS) $(INC) $(LIB_DIR) $(LIB) \
	string.cpp \
	yaudiocd.c -o yaudiocd

yclientmessage:
	$(CC) $(CFLAGS) $(INC) $(LIB_DIR) $(LIB) \
	string.cpp \
        yclientmessage.c -o yclientmessage

yhost:
	$(CC) $(CFLAGS) $(INC) $(LIB_DIR) $(LIB) \
	string.cpp \
	yhost.c -o yhost

ymixer:
	$(CC) $(CFLAGS) $(INC) $(LIB_DIR) $(LIB) \
	string.cpp \
	ymixer.c -o ymixer

yplay:
	$(CC) $(CFLAGS) $(INC) $(LIB_DIR) $(LIB) \
	disk.cpp string.cpp \
	yplay.c -o yplay

yrecinfo:
	$(CC) $(CFLAGS) $(INC) $(LIB_DIR) $(LIB) $(STDSRC) \
	string.cpp \
	yrecinfo.c -o yrecinfo

yset:
	$(CC) $(CFLAGS) $(INC) $(LIB_DIR) $(LIB) $(STDSRC) \
	string.cpp \
	yset.c -o yset

yshutdown:
	$(CC) $(CFLAGS) $(INC) $(LIB_DIR) $(LIB) $(STDSRC) \
	string.cpp \
	yshutdown.c -o yshutdown


# ########################################################################
# Install Rules:
#
INSTALL      = install

LS      = ls
LSFLAGS = -a -l

RM      = rm
RMFLAGS = -f

COPY      = cp
COPYFLAGS = -f

MKDIR        = mkdir
MKDIRFLAGS   = -p

INSTBINFLAGS = -m 0755 -s
INSTUIDFLAGS = -m 4755
INSTLIBFLAGS = -m 0755 -s
INSTINCFLAGS = -m 0644
INSTMANFLAGS = -m 0644
INSTCFGFLAGS = -m 0644
INSTDATFLAGS = -m 0644

BIN_DIR = $(PREFIX)/bin
MAN_DIR = $(PREFIX)/man/man1

install:
	$(MKDIR) $(MKDIRFLAGS) $(BIN_DIR)
	$(MKDIR) $(MKDIRFLAGS) $(MAN_DIR)

	@$(RM) $(RMFLAGS) $(MAN_DIR)/yaudiocd.1
	@$(RM) $(RMFLAGS) $(MAN_DIR)/yclientmessage.1
	@$(RM) $(RMFLAGS) $(MAN_DIR)/yhost.1
	@$(RM) $(RMFLAGS) $(MAN_DIR)/ymixer.1
	@$(RM) $(RMFLAGS) $(MAN_DIR)/yplay.1
	@$(RM) $(RMFLAGS) $(MAN_DIR)/yrecinfo.1
	@$(RM) $(RMFLAGS) $(MAN_DIR)/yset.1
	@$(RM) $(RMFLAGS) $(MAN_DIR)/yshutdown.1

	-$(INSTALL) $(INSTBINFLAGS) yaudiocd $(BIN_DIR)
	-$(INSTALL) $(INSTMANFLAGS) yaudiocd.1.bz2 $(MAN_DIR)

	-$(INSTALL) $(INSTBINFLAGS) yclientmessage $(BIN_DIR)
	-$(INSTALL) $(INSTMANFLAGS) yclientmessage.1.bz2 $(MAN_DIR)

	-$(INSTALL) $(INSTBINFLAGS) yhost $(BIN_DIR)
	-$(INSTALL) $(INSTMANFLAGS) yhost.1.bz2 $(MAN_DIR)

	-$(INSTALL) $(INSTBINFLAGS) ymixer $(BIN_DIR)
	-$(INSTALL) $(INSTMANFLAGS) ymixer.1.bz2 $(MAN_DIR)

	-$(INSTALL) $(INSTBINFLAGS) yplay $(BIN_DIR)
	-$(INSTALL) $(INSTMANFLAGS) yplay.1.bz2 $(MAN_DIR)

	-$(INSTALL) $(INSTBINFLAGS) yrecinfo $(BIN_DIR)
	-$(INSTALL) $(INSTMANFLAGS) yrecinfo.1.bz2 $(MAN_DIR)

	-$(INSTALL) $(INSTBINFLAGS) yset $(BIN_DIR)
	-$(INSTALL) $(INSTMANFLAGS) yset.1.bz2 $(MAN_DIR)

	-$(INSTALL) $(INSTBINFLAGS) yshutdown $(BIN_DIR)
	-$(INSTALL) $(INSTMANFLAGS) yshutdown.1.bz2 $(MAN_DIR)

	@echo "-------------------------------------------------------------------------"
	@echo "Y utility programs have been installed in:"
	@echo " "
	@echo "        $(BIN_DIR)"
	@echo " "
	@echo "Manual pages have been installed in:"
	@echo " "
	@echo "        $(MAN_DIR)"
	@echo " "


# ########################################################################
# Maintainance and Misc Rules:
#
clean:
	$(RM) $(RMFLAGS) a.out core *.o $(PROGS)


# ########################################################################
