# $Id: Makefile.in,v 1.67 2004/10/22 07:22:54 musirc Exp $

CC		= @CC@
AR		= @AR@
RM		= @RM@
SED		= @SED@
SEDOBJ		= @SEDOBJ@
STDOUT		= @STDOUT@
CFLAGS		= @IRC_CFLAGS@
PICFLAGS	= @PICFLAGS@
MKDEP		= @MKDEP@
INSTALL		= @INSTALL@
INSTALL_DATA	= @INSTALL_DATA@
MV		= @MV@
LD		= @LD@

prefix		= $(DESTDIR)@prefix@
moduledir	= ${prefix}/modules
automoduledir	= ${moduledir}/autoload

INCLUDES	= -I../include
CPPFLAGS	= ${INCLUDES} @CPPFLAGS@

CORE_SRCS = \
  core/m_channel.c \
  core/m_message.c \
  core/m_nick.c \
  core/m_server.c

SRCS =       \
  m_accept.c \
  m_admin.c \
  m_away.c \
  m_bans.c \
  m_flags.c \
  m_help.c \
  m_info.c \
  m_invite.c \
  m_ison.c \
  m_knock.c \
  m_links.c \
  m_list.c \
  m_manage.c \
  m_motd.c \
  m_names.c \
  m_oper.c \
  m_ping.c \
  m_set.c \
  m_stats.c \
  m_topic.c \
  m_trace.c \
  m_users.c \
  m_wallops.c \
  m_who.c \
  m_whois.c

ALL_SRCS = $(CORE_SRCS) $(SRCS)

SH_OBJS = ${SRCS:.c=.so}
SH_CORE_OBJS = ${CORE_SRCS:.c=.so}

HPUX_OBJS = ${SH_OBJS:.so=.sl}
HPUX_CORE_OBJS = ${SH_CORE_OBJS:.so=.sl}

S_OBJS = ${ALL_SRCS:.c=.o}

default:	build
build: all
all: .depend @MOD_TARGET@

shared_modules: $(SH_CORE_OBJS) $(SH_OBJS)

hpux_shared: $(SH_CORE_OBJS) $(SH_OBJS) $(HPUX_CORE_OBJS) $(HPUX_OBJS)

libmodules.a: $(S_OBJS)
	$(RM) -f $@
	$(AR) csrv $@ $(S_OBJS)


install-mkdirs:
	mkdir -p $(prefix)
	mkdir -p $(moduledir) $(automoduledir)

install: install_@MOD_TARGET@

install_libmodules.a: libmodules.a

install_shared_modules: install-mkdirs
	@for file in $(SH_CORE_OBJS); do \
		$(INSTALL_DATA) $$file $(moduledir); \
	done
	@for file in $(SH_OBJS); do \
		$(INSTALL_DATA) $$file $(automoduledir); \
	done

install_hpux_shared: install-mkdirs
	@for file in $(HPUX_CORE_OBJS); do \
		$(INSTALL_DATA) $$file $(moduledir); \
	done
	@for file in $(HPUX_OBJS); do \
		$(INSTALL_DATA) $$file $(automoduledir); \
	done

.SUFFIXES: .sl .so .o

.c.o:
	${CC} ${CPPFLAGS} ${CFLAGS} -c $< -o $@

.c.so:
	${CC} ${PICFLAGS} ${CPPFLAGS} ${CFLAGS} $< -o $@

.so.sl:
	$(LD) -b $< -o $@

.depend:
	${MKDEP} ${CPPFLAGS} ${ALL_SRCS} ${STDOUT}
	${SED} -e '${SEDOBJ}' < .depend > .depend.tmp-1
	${SED} -e 's/^m_\(server\|message\|nick\|channel\)/core\/m_\1/' .depend.tmp-1 > .depend.tmp
	@${SED} -e '/^# Autogenerated - do not delete/,$$d' <Makefile >Makefile.depend
	@echo '# Autogenerated - do not delete' >>Makefile.depend
	@echo 'include .depend' >> Makefile.depend
	@${MV} Makefile.depend Makefile
	${MV} -f .depend.tmp .depend
	${RM} -f .depend.tmp-1

clean:
	${RM} -f *.so *.sl *~ *.o *.a
	${RM} -f core/*.so core/*.sl core/*~ core/*.o

distclean: clean
	${RM} -f Makefile .depend

.PHONY: clean distclean install install_hpux_shared hpux_shared install_shared_modules shared_modules install_libmodules.a install-mkdirs build
