# =============================================================================
#
# @(#) Makefile,v SS7preBetaRelease(0.8.2.6) 2002/04/13 18:57:06
#
# -----------------------------------------------------------------------------
#
# Copyright (c) 2001 OpenSS7 Corporation <http://www.openss7.com/>
# Copyright (c) 1997-2000 Brian F. G. Bidulock <bidulock@dallas.net>
#
# All Rights Reserved.
#
# Unauthorized distribution or duplication is prohibited.
#
# This software and related documentation is protected by copyright and
# distributed under licenses restricting its use, copying, distribution and
# decompilation.  No part of this software or related documentation may be
# reproduced in any form by any means without the prior written
# authorization of the copyright holder, and licensors, if any.
#
# The recipient of this document, by its retention and use, warrants that
# the recipient will protect this information and keep it confidential, and
# will not disclose the information contained in this document without the
# written permission of its owner.
#
# The author reserves the right to revise this software and documentation
# for any reason, including but not limited to, conformity with standards
# promulgated by various agencies, utilization of advances in the state of
# the technical arts, or the reflection of changes in the design of any
# techniques, or procedures embodied, described, or referred to herein.
# The author is under no obligation to provide any feature listed herein.
#
# -----------------------------------------------------------------------------
#
# U.S. GOVERNMENT RESTRICTED RIGHTS.  If you are licensing this Software on
# behalf of the U.S. Government ("Government"), the following provisions apply
# to you.  If the Software is supplied by the Department of Defense ("DoD"),
# it is classified as "Commercial Computer Software" under paragraph
# 252.227-7014 of the DoD Supplement to the Federal Acquisition Regulations
# ("DFARS") (or any successor regulations) and the Government is acquiring
# only the license rights granted herein (the license rights customarily
# provided to non-Government users).  If the Software is supplied to any unit
# or agency of the Government other than DoD, it is classified as "Restricted
# Computer Software" and the Government's rights in the Software are defined
# in paragraph 52.227-19 of the Federal Acquisition Regulations ("FAR") (or
# any success regulations) or, in the cases of NASA, in paragraph 18.52.227-86
# of the NASA Supplement to the FAR (or any successor regulations).
#
# -----------------------------------------------------------------------------
#
# Last Modified 2002/04/13 18:57:06 by <bidulock@openss7.org>
#
# =============================================================================

INCDIR ?= "../include"
SRCDIR ?= "."
LISINCL ?= /usr/src/LiS/include
LISLFLAGS ?= '-lLiS'

INCLUDES = \
	-I$(LISINCL) \
	-I/usr/include \
	-I$(INCDIR) \

MAKEFILE = Makefile

COFLAGS = -l

DFLAGS ?= \
    -D_DEBUG \

WFLAGS ?= \
    -Wall \

MFLAGS ?= \
    -mpreferred-stack-boundary=2 \

CFLAGS ?= \
    -DLINUX \
    -D__KERNEL__ \
    -DMODULE \
    -DMODVERSIONS \
    $(OFLAGS) \
    $(WFLAGS) \
    $(INCLUDES) \
    -O3 \
    -pipe \

CCFLAGS = \
    -nostdlib \
    -D__KERNEL__ \
    -DMODULE \
    -DMODVERSIONS \
    -DEXPORT_SYMTAB \
    -O3 \
    -W \
    -Wall \
    -Winline \
    $(INCLUDES)

CC ?= gcc
CCC ?= g++

%_i.c : %.c ; $(CC) -E $(DFLAGS) $(CFLAGS) $< | sed -e "/^ *$$/d" > $@
%.s : %.c ; $(CC) -S $(DFLAGS) $(CFLAGS) $< -o $@
%.o : %.c ; $(CC) -c $(DFLAGS) $(CFLAGS) $< -o $@
%_i.cc : %.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}' /usr/src/linux/include/linux/version.h)

TSRC = $(wildcard test-*.c)
XCCP =
XPRG =
CTST =
TSTS = $(TSRC:%.c=%)
OBJS = $(TSTS) $(CTST) $(XPRG) $(XCPP)
BINS = 
SRCS = 
INCS = 

RMES = # README.thingstodo README.plan
CVSS = $(SRCS) $(INCS) $(RMES) $(TSRC) $(XPRG:%=%.c) $(CTST:%=%.cc) $(XCPP:%=%.cc) $(MAKEFILE)
LOGS = $(CVSS:%=%.log)

all:: $(TSTS) # tags

#$(CVSS):
#	cvs update $@

#$(SRCS): $(MAKEFILE)
#$(INCS): $(MAKEFILE)

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

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

$(TSTS): %: %.c
	$(CC) -Wall -ggdb -O3 -pipe $(INCLUDES) $(LISLFLAGS) $< -o $@
$(TSTS:%=%.s): %.s: %.c
	$(CC) -S -Wall -ggdb -O3 -pipe $(INCLUDES) $(LISLFLAGS) $< -o $@
$(TSTS:%=%_i.c): %_i.c: %.c
	$(CC) -E -Wall -ggdb -O3 -pipe $(INCLUDES) $(LISLFLAGS) $< | sed -e "/^ *$$/d" >  $@

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

assem:: $(BINS:%.o=%.s) $(TSTS:%=%.s) $(CTST:%=%.s) $(XPRG:%=%.s) $(XCPP:%=%.s)
prep:: $(BINS:%.o=%_i.c) $(TSTS:%=%_i.c) $(CTST:%=%_i.ci) $(XPRG:%=%_i.c) $(XCPP:%=%_i.cc)
tags: $(SRCS) $(INCS) $(wildcard $(INCDIR)/sys/*.h) $(wildcard $(INCDIR)/ss7/*.h)
	ctags $(SRCS) $(INCS) $(wildcard $(INCDIR)/sys/*.h) $(wildcard $(INCDIR)/ss7/*.h)

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

$(MAKEFILE): $(SRCS) $(INCS) $(TSRC)
	mv $(MAKEFILE) $(MAKEFILE).bak
	cat $(MAKEFILE).bak | sed -e "/^# Depend/,$$ d" > $(MAKEFILE)
	echo "# Dependencies" >> $(MAKEFILE)
	echo "" >> $(MAKEFILE)
	files="$(SRCS)"; if [ -n "$$files" ]; then { for i in $$files; do $(CC) -MM $(INCLUDES) $(CFLAGS) $$i >> $(MAKEFILE); done; }; fi
	files="$(CTST)"; if [ -n "$$files" ]; then { for i in $$files; do $(CCC) -MM $$i.cc | sed -e "s/\.o:/:/" >> $(MAKEFILE); done; }; fi
	files="$(TSTS)"; if [ -n "$$files" ]; then { for i in $$files; do $(CC) -MM $(INCLUDES) $$i.c | sed -e "s/\.o:/:/" >> $(MAKEFILE); done; }; fi
	files="$(XPRG)"; if [ -n "$$files" ]; then { for i in $$files; do $(CC) -MM -I/usr/X11/include $$i.c | sed -e "s/\.o:/:/" >> $(MAKEFILE); done; }; fi
	files="$(XCPP)"; if [ -n "$$files" ]; then { for i in $$files; do $(CC) -MM -I/usr/X11/include $$i.cc | sed -e "s/\.o:/:/" >> $(MAKEFILE); done; }; fi
#	mv $(MAKEFILE) $(MAKEFILE)~
#	cat $(MAKEFILE)~ | sed -e "/^# Depend/,$$ s/:/: $(MAKEFILE)/" > $(MAKEFILE)
#	rm $(MAKEFILE)~

depend:: $(MAKEFILE)

install::

clean::
	rm -f *.o *.s *_i.c *_i.cc *.log *~ core $(TSTS) $(CTST) $(XPRG) $(XCPP) Makefile.bak

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

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

# Dependencies

test-inet_raw: test-inet_raw.c
test-inet_tcp: test-inet_tcp.c
test-inet_udp: test-inet_udp.c
test-m2pa: test-m2pa.c
test-m2pa-sdl: test-m2pa-sdl.c
test-m2pa-sl: test-m2pa-sl.c
test-q781: test-q781.c
test-sctp: test-sctp.c
test-sctp_n: test-sctp_n.c
test-sctp_nc: test-sctp_nc.c
test-sctp_ns: test-sctp_ns.c
test-sctp_t: test-sctp_t.c
test-sdlacb: test-sdlacb.c
test-sdlsctp: test-sdlsctp.c
test-sdludp: test-sdludp.c
test-sdt: test-sdt.c
test-sl: test-sl.c
test-tcpc: test-tcpc.c
test-tcps: test-tcps.c
test-udpc: test-udpc.c
test-udps: test-udps.c
