# ARS Makefile
#
# Copyright (C) 2001 by Salvatore Sanfilippo
# See the LICENSE file for more information.

.SUFFIXES:
.SUFFIXES: .c .o

NAME=ARS
FILES=*.[ch] *.sh configure RFCs PROPOSAL Makefile MD5SUM.SIGNED.asc APD.txt \
	LICENSE kernel-modules

SHELL= /bin/sh
CFLAGS= -Wall -O2 -g
AR=/usr/bin/ar
RANLIB=/usr/bin/ranlib

INSTALL= /usr/bin/install
INSTALL_PROGRAM= $(INSTALL)
INSTALL_DATA= $(INSTALL) -m 644
DESTDIR= /usr/local/bin/

PROGRAMS= 		libars.a example1 example2 example3 arstest arstcp
ARSLIB_OBJECTS= 	systype.h ars.o apd.o getif.o split.o

all: systype.h .depend $(PROGRAMS)

.depend:
	@$(CC) -MM *.c > .depend
	@echo Making dependences

.c.o:
	$(CC) -I. $(CFLAGS) $(DEFS) -c $< -o $@

libars.a: $(ARSLIB_OBJECTS)
	$(AR) rc $@ $^
	$(RANLIB) $@

example1: example1.o libars.a
	$(CC) $(LDFLAGS) $^ -o $@ -L. -lars
example2: example2.o libars.a
	$(CC) $(LDFLAGS) $^ -o $@ -L. -lars
example3: example3.o libars.a
	$(CC) $(LDFLAGS) $^ -o $@ -L. -lars
arstest: arstest.o libars.a
	$(CC) $(LDFLAGS) $^ -o $@ -L. -lars -lpcap
arstcp: arstcp.o libars.a
	$(CC) $(LDFLAGS) $^ -o $@ -L. -lars -lpcap

systype.h: configure
	./configure

strip:
	strip $(PROGRAMS)
	@ls -l $(PROGRAMS)

install:
	@echo See the INSTALL file

clean:
	rm -f $(ARSLIB_OBJECTS) *.o core .depend .nfs* */.nfs* .*.swp $(PROGRAMS)

success:
	@echo
	@echo Compilation successful!
	@echo Now you can read the INSTALL file

distclean:
mostlyclean:

dist: clean sign tar

tar:
	d=`date -Iseconds | cut -d+ -f1 | tr -- :T -.`; \
	v=`grep VERSION config.h | cut -d\" -f2`; \
	b=`echo $(NAME)-$$v-$$d`; mkdir $$b; \
	cp -a $(FILES) $$b; \
	read; tar cvzf $$b.tar.gz $$b; \
	ls -l $$b.tar.*

wc:
	cat *.[ch] | sed -e /^$$/d | wc -l

sign:
	rm -f MD5SUM.SIGNED*
	-(md5sum * 2> /dev/null > MD5SUM.SIGNED)
	pgp -sta MD5SUM.SIGNED
	rm -f MD5SUM.SIGNED

check:
	md5sum -c MD5SUM.SIGNED.asc

ifeq (.depend,$(wildcard .depend))
include .depend
endif
