#~~syntax:makefile
#==============================================================================
# ttyrpld - TTY replay daemon
#   Copyright © Jan Engelhardt <jengelh [at] linux01 gwdg de>, 2004 - 2005
#   -- License restrictions apply (GPL v2)
#
#   This file is part of ttyrpld.
#   ttyrpld 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; however ONLY version 2 of the License.
#
#   ttyrpld 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 kit; if not, write to:
#   Free Software Foundation, Inc., 59 Temple Place - Suite 330,
#   Boston, MA 02111-1307, USA.
#
#   -- For details, see the file named "LICENSE.GPL2"
#==============================================================================

include devel/makevars.inc
KERNEL_OS  := $(shell uname -s)
KERNEL_VER := $(shell uname -r | cut -d- -f1 | cut -d. -f1-2)
-include devel/Makefile.std.${KERNEL_OS}

CFLAGS   += ${EXT_CFLAGS}
CXXFLAGS += ${EXT_CXXFLAGS}
ASFLAGS  += ${EXT_ASFLAGS}
LDFLAGS  += ${EXT_LDFLAGS}
SOFLAGS  += ${EXT_SOFLAGS}
ARFLAGS  += ${EXT_ARFLAGS}

V_KMOD_SUCCESS := \
  echo "*** Kernel module compiled, installed and loaded. Either edit"; \
  echo "*** your system configuration files so that it is also loaded"; \
  echo "*** upon next bootup. You can leave it as it is if you use"; \
  echo "*** etc-init.d-rpld, since it will try to load it anyway.";

#------------------------------------------------------------------------------
.PHONY: all kmod clean cleanx locale bz

all: locale ttyreplay rpld rplctl

-include devel/Makefile.kmod.${KERNEL_OS}

locale:
	${MAKE} -C locale;

ttyreplay: user/replay.o user/pctrl.o user/global.o
	${VECHO_LD}
	${LD} ${LDFLAGS} -o $@ $^ -lHX -lpopt -lpthread ${EXT_LDLIBS};
	${STRIP} -s $@;

rpld: user/rpld.o user/infod.o user/rplctl.o user/rdsh.o user/global.o
	${VECHO_LD}
	${LD} ${LDFLAGS} -o $@ $^ -lHX -lpopt -lpthread ${EXT_LDLIBS};
	${STRIP} -s $@;

rplctl: rpld
	ln -fs $< $@;

user/%.o: user/%.c
	${VECHO_CC}
	${CC} ${CFLAGS} -c -o $@ $<;

install: ttyreplay rpld rplctl locale;
	@echo "Installing to ${ROOT}${PREFIX}/{s,}bin and /etc"
	install -dm0755 ${ROOT}/etc;
	install -dm0755 ${ROOT}${PREFIX}/bin
	install -dm0755 ${ROOT}${PREFIX}/sbin;
	install -pm0755 ttyreplay ${ROOT}${PREFIX}/bin/;
	install -pm0755 rpld ${ROOT}${PREFIX}/sbin/;
	ln -fs rpld ${ROOT}${PREFIX}/sbin/rplctl;
	[ ! -e ${ROOT}/etc/rpld.conf ] && \
	    install -pm0644 rpld.conf ${ROOT}/etc/ || :;
ifeq (${KERNEL_OS},Linux)
	install -dm0755 ${ROOT}/etc/init.d;
	perl -pe 's{^DAEMON_BIN=.*}{DAEMON_BIN="'"${PREFIX}"'/sbin/rpld";}' \
	 <etc-init.d-rpld >"${ROOT}/etc/init.d/rpld" && \
	 chmod a+x "${ROOT}/etc/init.d/rpld";
endif
	make -C locale install;

uninstall:
	rm -f ${ROOT}${PREFIX}/bin/ttyreplay ${ROOT}${PREFIX}/sbin/{rpld,rplctl};
	rm -f ${ROOT}/etc/rpld.conf;
	rm -f ${ROOT}/etc/init.d/rpld;
	rm -f ${ROOT}${PREFIX}/share/locale/*/LC_MESSAGES/ttyrpld.mo;

clean: ;
	rm -f user/*.o rpld rplctl ttyreplay;

cleanx: clean;
	rm -f user/*.d;
	${MAKE} -C locale clean;

include devel/autodeps.inc

#==============================================================================
