# =============================================================================
# 
# @(#) $Id: Makefile,v 0.7.2.7 2000/09/21 05:19:39 brian Exp $
# 
# -----------------------------------------------------------------------------
# 
# Copyright (C) 1997, 1998, 1999, 2000  Brian Bidulock <bidulock@dallas.net>
# 
# All Rights Reserved.
# 
# This program 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; either version 2 of the License, or (at your option) any later
# version.
# 
# This program 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; if not, write to the Free Software Foundation, Inc., 675 Mass
# Ave, Cambridge, MA 02139, USA.
# 
# Last Modified $Date: 2000/09/21 05:19:39 $ by $Author: brian $
# 
# -----------------------------------------------------------------------------
# 
# $Log: Makefile,v $
# Revision 0.7.2.7  2000/09/21 05:19:39  brian
# Made dependencies.
#
# Revision 0.7.2.6  2000/09/13 13:47:06  brian
# A lot of work in state machine: haven't check compile yet,
# just wanting to save work for later.
#
# Revision 0.7.2.5  2000/09/12 18:45:22  brian
# Lots of work within the MTP state machine files.
#
# Revision 0.7.2.4  2000/09/11 20:20:47  brian
# Cleaned up routing structure.
#
# Revision 0.7.2.3  2000/09/11 14:53:01  brian
# State machines compile.
#
# Revision 0.7.2.2  2000/09/11 14:08:18  brian
# Remove and updated some files for better structure.  Most compile now...
#
# Revision 0.7.2.1  2000/09/11 07:21:34  brian
# Doing a lot of work in socket code files.
#
# Revision 0.7  2000/09/07 11:12:13  brian
# Initial import of OpenSS7.
#
# Revision 1.1.1.1  2000/09/05 11:00:20  brian
# Initial import of new OpenSS7 stack for Linux.
#
# =============================================================================

INCLUDEDIR = /usr/src/linux/include
MOREINCLUDE = # -I/home/brian/openss7/linux/include

COFLAGS = -l

DFLAGS = \
	-DHAVE_SU_COMPRESSION \
	-DTAKE_STATS

# DFLAGS = \
#	-DHAVE_SU_COMPRESSION \
#	-DDEBUG_PRINT_SNIBS \
#	-DDEBUG_PRINT_TIMER \
#	-DDEBUG_PRINT_STATE \
#	-DDEBUG_PRINT_IAC \
#	-DDEBUG_PRINT_RC \
#	-DDEBUG_PRINT_TXC \
#	-DDEBUG_PRINT_L3 \
#	-DDEBUG_PRINT_LSC \
#	-DDEBUG_PRINT_ASP \
#	-DTAKE_STATS

CFLAGS  = \
	-nostdlib \
	-D__KERNEL__ \
	-DMODULE \
	-DMODVERSIONS \
	-DEXPORT_SYMTAB \
	-O0 \
	-fstrength-reduce \
	-fthread-jumps \
	-fcse-follow-jumps \
	-fcse-skip-blocks \
	-frerun-cse-after-loop \
	-fexpensive-optimizations \
	-fcaller-saves \
	-funroll-loops \
	-funroll-all-loops \
	-Wall \
	-Winline \
	-I$(INCLUDEDIR) \
	$(MOREINCLUDE)

CPPFLAGS  = \
	-nostdinc \
	-D__KERNEL__ \
	-DMODULE \
	-DMODVERSIONS \
	-DEXPORT_SYMTAB \
	$(MOREINCLUDE)

CCFLAGS = \
	-nostdlib \
	-D__KERNEL__ \
	-DMODULE \
	-DMODVERSIONS \
        -DEXPORT_SYMTAB \
	-O0 \
	-w \
	-Wall \
	-W \
	-Winline \
	-I$(INCLUDEDIR) \
	$(MOREINCLUDE)

CC = gcc
CCC = g++

%_i.c : %.c ; $(CC) -E $(DFLAGS) $(CPPFLAGS) $< | sed -e "/^ *$$/d" > $@
%.s : %.c ; $(CC) -S $(DFLAGS) $(CFLAGS) $< -o $@
%.o : %.c ; $(CC) -c $(DFLAGS) $(CFLAGS) $< -o $@
%.ii : %.cc ; $(CCC) -E $(DFLAGS) $(CCFLAGS) $< | sed -e "/^ *$$/d" > $@
%.s : %.cc ; $(CCC) -S $(DFLAGS) $(CCFLAGS) $< -o $@
%.o : %.cc ; $(CCC) -c $(DFLAGS) $(CCFLAGS) $< -o $@

# Extract version number from headers.

VER = $(shell awk -F\" '/REL/ {print $$2}' $(INCLUDEDIR)/linux/version.h)
    
XCPP = 
XPRG = # xss7cntl
CTST = # ss7cntl
TSTS = 
OBJS = ss7.o $(TSTS) $(CTST) $(XPRG) $(XCPP)
BINS = af_ss7.o mtp.o sccp.o mtp_route.o mtp_sm.o
SRCS = af_ss7.c mtp.c sccp.c mtp_route.c mtp_sm.c
INCS = \
../../include/linux/if_arp.h \
../../include/linux/if_ether.h \
../../include/linux/netdevice.h \
../../include/linux/proc_fs.h \
../../include/linux/socket.h \
../../include/linux/ss7.h \
../../include/linux/ss7_timers.h \
../../include/linux/ss7link.h \
../../include/linux/ss7mtp.h \
../../include/linux/ss7sccp.h \
../../include/linux/sysctl.h \
../../include/net/sock.h \
../../include/net/ss7.h \
../../include/net/ss7call.h \
../../include/net/ss7link.h \
../../include/net/ss7mtp.h \
../../include/net/ss7mtpcall.h \
../../include/net/ss7sccp.h \
../../include/net/ss7sccpcall.h
RMES = # README.thingstodo README.plan
CVSS = $(SRCS) $(INCS) $(RMES) $(TSTS:%=%.c) $(XPRG:%=%.c) $(CTST:%=%.cc) $(XCPP:%=%.cc) Makefile
LOGS = $(CVSS:%=%.log)

all:: $(OBJS) tags

#$(CVSS):
#	cvs update $@

$(SRCS): Makefile
$(INCS): Makefile

ss7.o: $(BINS)
	$(LD) -r $^ -o $@

$(XCPP): %: %.cc
	$(CCC) -Wall -ggdb -O2 -I/usr/X11/include -L/usr/X11/lib -lXaw -lc $< -o $@
$(XCPP:%=%.s): %.s: %.cc
	$(CCC) -S -Wall -ggdb -O2 -I/usr/X11/include -L/usr/X11/lib $< -o $@
$(XCPP:%=%.ii): %.ii: %.cc
	$(CCC) -E -Wall -ggdb -O2 -I/usr/X11/include -L/usr/X11/lib $< | sed -e "/^ *$$/d" > $@

$(XPRG): %: %.c
	$(CC) -Wall -ggdb -O2 -I/usr/X11/include -L/usr/X11/lib -lXaw -lc $< -o $@
$(XPRG:%=%.s): %.s: %.c
	$(CC) -S -Wall -ggdb -O2 -I/usr/X11/include -L/usr/X11/lib $< -o $@
$(XPRG:%=%.i): %.i: %.c
	$(CC) -E -Wall -ggdb -O2 -I/usr/X11/include -L/usr/X11/lib $< | sed -e "/^ *$$/d" > $@

$(TSTS): %: %.c
	$(CC) -Wall -ggdb -O2 -lpanel -lncurses $< -o $@
$(TSTS:%=%.s): %.s: %.c
	$(CC) -S -Wall -ggdb -O2 $< -o $@
$(TSTS:%=%.i): %.i: %.c
	$(CC) -E -Wall -ggdb -O2 $< | sed -e "/^ *$$/d" >  $@

$(CTST): %: %.cc
	$(CCC) -Wall -ggdb -O2 -lpanel -lncurses $< -o $@
$(CTST:%=%.s): %.s: %.cc
	$(CCC) -S -Wall -ggdb -O2 $< -o $@
$(CTST:%=%.ii): %.ii: %.cc
	$(CCC) -E -Wall -ggdb -O2 $< | sed -e "/^ *$$/d" > $@

assem:: $(BINS:%.o=%.s) $(TSTS:%=%.s) $(CTST:%=%.s) $(XPRG:%=%.s) $(XCPP:%=%.s)
prep:: $(BINS:%.o=%.i) $(TSTS:%=%.i) $(CTST:%=%.ii) $(XPRG:%=%.i) $(XCPP:%=%.ii)
tags: $(SRCS) $(INCS)
	ctags $(SRCS) $(INCS)

$(LOGS): %.log: %
	cvs log $< | sed -e "1d" > $@
logs:: $(LOGS)

depend::
	mv Makefile Makefile.bak
	cat Makefile.bak | sed -e "/^# Depend/,$$ d" > Makefile
	echo "# Dependencies" >> Makefile
	echo "" >> Makefile
	for i in $(SRCS); do $(CC) -MM -I$(INCLUDEDIR) $(MOREINCLUDE) $(CFLAGS) $$i >> Makefile; done
	for i in $(CTST); do $(CCC) -MM $$i.cc | sed -e "s/\.o:/:/" >> Makefile; done
	for i in $(TSTS); do $(CC) -MM $$i.c | sed -e "s/\.o:/:/" >> Makefile; done
	for i in $(XPRG); do $(CC) -MM -I/usr/X11/include $$i.c | sed -e "s/\.o:/:/" >> Makefile; done
	for i in $(XCPP); do $(CC) -MM -I/usr/X11/include $$i.cc | sed -e "s/\.o:/:/" >> Makefile; done
	mv Makefile Makefile~
	cat Makefile~ | sed -e "/^# Depend/,$$ s/:/: Makefile/" > Makefile
	rm Makefile~

install::
	install -d /lib/modules/$(VER)/misc /lib/modules/misc
	install -c ss7link.o /lib/modules/$(VER)/misc
	install -c ss7link.o /lib/modules/misc
	rm -f /dev/escc0; mknod -m 666 /dev/escc0 c 63 0
	rm -f /dev/escc1; mknod -m 666 /dev/escc1 c 63 1
	rm -f /dev/escc2; mknod -m 666 /dev/escc2 c 63 2
	rm -f /dev/escc3; mknod -m 666 /dev/escc3 c 63 3
	rm -f /dev/esccM0; mknod -m 666 /dev/esccM0 c 62 0
	rm -f /dev/esccM1; mknod -m 666 /dev/esccM1 c 62 1
	rm -f /dev/esccM2; mknod -m 666 /dev/esccM2 c 62 2
	rm -f /dev/esccM3; mknod -m 666 /dev/esccM3 c 62 3

clean::
	rm -f *.o *.s *.i *.ii *.log *~ core $(TSTS) $(CTST) $(XPRG) $(XCPP) tags

realclean::
	cvs commit
	rm -f $(SRCS) $(INCS) $(RMES) $(BINS) $(OBJS) \
		$(BINS:%.o=%.s) $(BINS:%.o=%.i) \
		Makefile.bak *~ core \
	$(TSTS) $(TSTS:%=%.c) $(TSTS:%=%.s) $(TSTS:%=%.i) \
	$(XPRG) $(XPRG:%=%.c) $(XPRG:%=%.s) $(XPRG:%=%.i) \
	$(XCPP) $(XCPP:%=%.cc) $(XCPP:%=%.s) $(XCPP:%=%.ii) \
	$(CTST) $(CTST:%=%.cc) $(CTST:%=%.s) $(CTST:%=%.ii)

.lines:   $(SRCS) $(INCS) Makefile
	cat $^ | wc -l > .lines
	cat .lines

# Dependencies

af_ss7.o: Makefile af_ss7.c af_ss7.h mtp.h mtp_route.h sccp.h \
 ../../include/net/ss7link.h ../../include/linux/ss7link.h
mtp.o: Makefile mtp.c af_ss7.h mtp.h mtp_sm.h mtp_route.h mtp_parse.h
sccp.o: Makefile sccp.c af_ss7.h mtp.h mtp_sm.h mtp_route.h mtp_parse.h sccp.h \
 sccp_gtt.h
mtp_route.o: Makefile mtp_route.c af_ss7.h mtp_route.h mtp_sm.h \
 ../../include/net/ss7link.h ../../include/linux/ss7link.h
mtp_sm.o: Makefile mtp_sm.c mtp_parse.h af_ss7.h mtp_route.h mtp_sm.h \
 ../../include/net/ss7link.h ../../include/linux/ss7link.h
