# ########################################################################
#
#                       Makefile for libY2
#
#   Rules:
#
#	all	-- builds library.
#	install -- installs library.
#	clean	-- remove object and other work files.
#


# ########################################################################
# Install Options:
#
PREFIX = /usr


# ########################################################################
# Library Name and Version:
#
#   Note, do not change major version number. That would imply that the
#   entire Y protocol has changed.
#
LIBPFX = libY2
LIBVER = 6


# ########################################################################
# 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.
#
#	-shared			Compile this program as a shared library.
#
CFLAGS  = -Wall -O2 -shared


# ########################################################################
# 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 =

# 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 =

# 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:
#
include Makefile.srclist

CC = gcc


# ########################################################################
# Build Rules:
#
all:
	$(CC) $(SRC) $(CFLAGS) $(LIB) $(LIB_DIR) -o $(LIBPFX).so.$(LIBVER)


# ########################################################################
# Install Rules:
#

INSTALL      = install
INSTBINFLAGS = -m 0755
INSTUIDFLAGS = -m 4755
INSTLIBFLAGS = -m 0755
INSTINCFLAGS = -m 0444
INSTMANFLAGS = -m 0444
INSTCFGFLAGS = -m 0644
INSTDATFLAGS = -m 0444

COPY      = cp
COPYFLAGS = -i -v

LINK      = ln
LINKFLAGS = -sf

MKDIR      = mkdir
MKDIRFLAGS = -p

YLIB_DIR = $(PREFIX)/lib
YINC_DIR = $(PREFIX)/include/Y2
YMAN_DIR = $(PREFIX)/man/man3


install:
	$(MKDIR) $(MKDIRFLAGS) $(YLIB_DIR)
	$(INSTALL) $(INSTLIBFLAGS) $(LIBPFX).so.$(LIBVER) $(YLIB_DIR)
	$(LINK) $(LINKFLAGS) $(LIBPFX).so.$(LIBVER) $(YLIB_DIR)/$(LIBPFX).so

	$(MKDIR) $(MKDIRFLAGS) $(YINC_DIR)
	$(INSTALL) $(INSTINCFLAGS) ../include/Y.h $(YINC_DIR)
	$(INSTALL) $(INSTINCFLAGS) ../include/Ylib.h $(YINC_DIR)
	$(INSTALL) $(INSTINCFLAGS) ../include/Yclientnet.h $(YINC_DIR)
	$(INSTALL) $(INSTINCFLAGS) ../include/Ymixercodes.h $(YINC_DIR)

	$(MKDIR) $(MKDIRFLAGS) $(YMAN_DIR)
	$(INSTALL) $(INSTMANFLAGS) man/* $(YMAN_DIR)

	@echo "---------------------------------------------------------------"
	@echo "Library $(LIBPFX) installed in:"
	@echo " "
	@echo "        $(YLIB_DIR)"
	@echo " "
	@echo "Header files are installed in:"
	@echo " "
	@echo "        $(YINC_DIR)"
	@echo " "
	@echo "Manual pages are installed in:"
	@echo " "
	@echo "        $(YMAN_DIR)"
	@echo " "
	@echo "To link your programs to this library add -lY2 to the compiler"
	@echo "command."
	@echo " "
	@echo "You may also need to recompile some programs which are linked"
	@echo "to this program in case of protocol value changes. Modification"
	@echo "to their code is unnessasary if the major version number matches."
	@echo " "


# ########################################################################
# Maintainance and Misc Rules:
#
clean:
	rm -f a.out core *.o $(LIBPFX).so.$(LIBVER)


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