#
# NET-BASE	A collection of programs that form the base set of the
#		NET-2 Networking Distribution for the LINUX operating
#		system.
#
# Version:	@(#)Makefile	0.32	01/16/94
#
# Author:	Fred N. van Kempen, <waltje@uwalt.nl.mugnet.org>
#		Copyright 1988-1993 MicroWalt Corporation
#
#		Extensively modified from 01/21/94 onwards by
#		Alan Cox <A.Cox@swansea.ac.uk>
#		Copyright 1993-1994 Swansea University Computer Society
#
#		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.
#

RELEASE	= tools-1.2.0

# set default language (DEF_LANG) to en_US.88591 if you DON'T use NLS
DEF_LANG = en_US.88591

# install national language support for the following languages
ADD_LANG = # fr_FR.88591

.EXPORT_ALL_VARIABLES:

CC	= gcc -O6 -Wall
LD	= gcc

CFLAGS	= -I. -I.. -Ilib -I../lib -DLINUX #-DDEBUG
LDFLAGS	= -Llib -L../lib -s

LIBS	= -lsupport


PROGS	= slattach plipconfig # ifconfig arp netstat route rarp ipfw hostname dnsdomainname
SUBDIRS	= nls

.c.o:		$<
		$(CC) $(CFLAGS) -c $<


all:		config.h version.h subdirs $(PROGS)

install:	all installdata
#	install -o root -g root -m 0755 arp ${BASEDIR}/usr/sbin
#	install -o root -g root -m 0755 ifconfig ${BASEDIR}/sbin
#	install -o root -g root -m 0755 ipfw ${BASEDIR}/sbin
#	install -o root -g root -m 0755 netstat ${BASEDIR}/bin
	install -o root -g root -m 0755 plipconfig ${BASEDIR}/usr/sbin
#	install -o root -g root -m 0755 rarp ${BASEDIR}/sbin
#	install -o root -g root -m 0755 route ${BASEDIR}/sbin
	install -o root -g root -m 0755 slattach ${BASEDIR}/usr/sbin

USE_NLS := $(shell grep 'define NLS 1' config.h)

installdata:
#	install -o root -g root -m 0644 man/${DEF_LANG}/arp.8 ${BASEDIR}/usr/man/man8
#	install -o root -g root -m 0644 man/${DEF_LANG}/ifconfig.8 ${BASEDIR}/usr/man/man8
#	install -o root -g root -m 0644 man/${DEF_LANG}/ipfw.8 ${BASEDIR}/usr/man/man8
#	install -o root -g root -m 0644 man/${DEF_LANG}/netstat.8 ${BASEDIR}/usr/man/man8
	install -o root -g root -m 0644 man/${DEF_LANG}/plipconfig.8 ${BASEDIR}/usr/man/man8
#	install -o root -g root -m 0644 man/${DEF_LANG}/rarp.8 ${BASEDIR}/usr/man/man8
#	install -o root -g root -m 0644 man/${DEF_LANG}/route.8 ${BASEDIR}/usr/man/man8
	install -o root -g root -m 0644 man/${DEF_LANG}/slattach.8 ${BASEDIR}/usr/man/man8
ifneq ($(USE_NLS), "")
	if [ "${DEF_LANG}" != "en_US.88591" ]; then \
		install -o root -g root -m 0755 -d ${BASEDIR}/usr/lib/locale/${DEF_LANG} ;\
		install -o root -g root -m 0644 nls/${DEF_LANG}/nettools.cat ${BASEDIR}/usr/lib/locale/${DEF_LANG} ;\
	fi
	for i in $(ADD_LANG); do \
	install -o root -g root -m 0755 -d ${BASEDIR}/usr/man/$$i/man5 ;\
	install -o root -g root -m 0755 -d ${BASEDIR}/usr/man/$$i/man8 ;\
	install -o root -g root -m 0755 -d ${BASEDIR}/usr/lib/locale/$$i ;\
	install -o root -g root -m 0644 nls/$$i/nettools.cat ${BASEDIR}/usr/lib/locale/$$i ;\
	install -o root -g root -m 0644 man/$$i/arp.8 ${BASEDIR}/usr/man/$$i/man8 ;\
	install -o root -g root -m 0644 man/$$i/ifconfig.8 ${BASEDIR}/usr/man/$$i/man8 ;\
	install -o root -g root -m 0644 man/$$i/ipfw.8 ${BASEDIR}/usr/man/$$i/man8 ;\
	install -o root -g root -m 0644 man/$$i/netstat.8 ${BASEDIR}/usr/man/$$i/man8 ;\
	install -o root -g root -m 0644 man/$$i/plipconfig.8 ${BASEDIR}/usr/man/$$i/man8 ;\
	install -o root -g root -m 0644 man/$$i/rarp.8 ${BASEDIR}/usr/man/$$i/man8 ;\
	install -o root -g root -m 0644 man/$$i/route.8 ${BASEDIR}/usr/man/$$i/man8 ;\
	install -o root -g root -m 0644 man/$$i/slattach.8 ${BASEDIR}/usr/man/$$i/man8 ;\
	install -o root -g root -m 0644 man/$$i/resolver.5 ${BASEDIR}/usr/man/$$i/man5 ;\
	done
endif

clean:
		rm -f $(PROGS) *.o config.new version.h *~
		@for i in lib $(SUBDIRS); do cd $$i && make clean && cd ..; done

clobber:	clean
		rm -f $(PROGS) config.h config.status
		@for i in lib $(SUBDIRS); do cd $$i && make clobber && cd ..; done

dist:
		@echo Creating net-$(RELEASE) in ..
		@tar cfvz ../net-$(RELEASE).tar.gz *

config.h:	Makefile config.in
		@echo "Configuring the NET-3 Base Utilities..." ; echo
		@if [ -f config.status ]; \
			then /bin/sh ./Configure.sh <config.status; \
		   else /bin/sh ./Configure.sh <config.in; \
		 fi

version.h:	Makefile
		@echo "#define RELEASE \"NET-3 Base Utilities release $(RELEASE)\"" >version.h

ifconfig:	lib/libsupport.a ifconfig.o
		$(CC) $(LDFLAGS) -o ifconfig ifconfig.o $(LIBS)

hostname:	hostname.o
		$(CC) $(LDFLAGS) -o hostname hostname.o

plipconfig:	plipconfig.o
		$(CC) $(LDFLAGS) -N -o plipconfig plipconfig.o

route:		lib/libsupport.a route.o
		$(CC) $(LDFLAGS) -o route route.o $(LIBS)

arp:		lib/libsupport.a arp.o
		$(CC) $(LDFLAGS) -o arp arp.o $(LIBS)

rarp:		lib/libsupport.a rarp.o
		$(CC) $(LDFLAGS) -N -o rarp rarp.o $(LIBS)

slattach:	lib/libsupport.a slattach.o
		$(CC) $(LDFLAGS) -o slattach slattach.o $(LIBS)

netstat:	lib/libsupport.a netstat.o
		$(CC) $(LDFLAGS) -o netstat netstat.o $(LIBS)

ipfw:		ipfw.o
		$(CC) $(LDFLAGS) -o ipfw ipfw.o $(LIBS)

dnsdomainname:	hostname
		ln -f hostname dnsdomainname

subdirs:	
		@for i in $(SUBDIRS); do (cd $$i; $(MAKE)); done

lib/libsupport.a:
		@(cd lib ; $(MAKE))

netstat.o:	netstat.c
		$(CC) $(CFLAGS) -D__KERNEL__ -c $<

# End of Makefile.
