all: nodeusers uronode axdigi calibrate @FLEXNET@

CC = gcc
LD = $(CC)
INSTALL ?= install
# CFLAGS = -O2 -g -s -Wno-unused-result -Wstrict-prototypes
# CFLAGS = -DUNIX -g3 -DDEBUG
CPPFLAGS:=$(shell dpkg-buildflags --get CPPFLAGS)
CFLAGS:=$(shell dpkg-buildflags --get CFLAGS)
CXXFLAGS:=$(shell dpkg-buildflags --get CXXFLAGS)
LDFLAGS:=$(shell dpkg-buildflags --get LDFLAGS)
LIBS = -lax25 -lax25io

include Makefile.include

COMMON_SRC =		user.c util.c
NODE_SRC =		node.c cmdparse.c config.c command.c jheard.c axcalluser.c \
			gateway.c extcmd.c procinfo.c router.c system.c sysinfo.c ipc.c
NODEUSERS_SRC =		nodeusers.c
FLEXD_SRC = 		flexd.c procinfo.c
DIGI_SRC =		axdigi.c
CALIBRATE_SRC =		calibrate.c

COMMON_OBJS =		$(COMMON_SRC:.c=.o)
NODE_OBJS =		$(NODE_SRC:.c=.o)
NODEUSERS_OBJS =	$(NODEUSERS_SRC:.c=.o)
FLEXD_OBJS =		$(FLEXD_SRC:.c=.o)
DIGI_OBJS =		$(DIGI_SRC:.c=.o)
CALIBRATE_OBJS =	$(CALIBRATE_SRC:.c=.o)
.c.o:
	$(CC) $(CPPFLAGS) $(CFLAGS) $(CXXFLAGS) $(LDFLAGS)  -c $<

install: installbin installman installhelp installconf
	$(INSTALL) -b -m 755    -D -d	$(VAR_DIR)
	$(INSTALL) -b -m 755    -D -d	$(VAR_DIR)/node
	$(INSTALL) -b -m 644    -p etc/loggedin	$(VAR_DIR)/node
	$(INSTALL) -b -m 644    -p etc/lastlog	$(VAR_DIR)/node
	$(INSTALL) -b -m 755    -D -d	$(VAR_DIR)/flex
	$(INSTALL) -b -m 644    -p etc/gateways	 $(VAR_DIR)/flex
	
installbin: all
	$(INSTALL) -b -m 755    -D -d		$(SBIN_DIR)
	$(INSTALL) -m 755 	-s -p	uronode		$(SBIN_DIR)
	$(INSTALL) -m 755  -s -p	nodeusers	$(SBIN_DIR)
	$(INSTALL) -m 755  -s -p	axdigi		$(SBIN_DIR)
	$(INSTALL) -m 755	-s -p	calibrate	$(SBIN_DIR)
@IN@	$(INSTALL) -m 755  -s -p	flexd		$(SBIN_DIR)

installhelp:
	$(INSTALL) -b -m 755    -D -d		 $(VAR_DIR)
	$(INSTALL) -b -m 755    -D -d		 $(VAR_DIR)/node/help
	$(INSTALL) -b -m 644    -p etc/help/*.hlp $(VAR_DIR)/node/help

installconf: installhelp
	$(INSTALL) -b -m 755    -D -d		 $(ETC_DIR)
	$(INSTALL) -b -m 600    -p etc/uronode.announce  $(ETC_DIR)
	$(INSTALL) -b -m 600    -p etc/uronode.conf  $(ETC_DIR)
	$(INSTALL) -b -m 600    -p etc/uronode.perms $(ETC_DIR)
	$(INSTALL) -b -m 600    -p etc/uronode.info  $(ETC_DIR)
	$(INSTALL) -b -m 600    -p etc/uronode.motd  $(ETC_DIR)
	$(INSTALL) -b -m 600    -p etc/uronode.users $(ETC_DIR)
	$(INSTALL) -b -m 600    -p etc/uronode.routes   $(ETC_DIR)
	$(INSTALL) -b -m 600    -p etc/flexd.conf  $(ETC_DIR)

installman:
	$(INSTALL) -m 755	  -D -d $(MAN_DIR)/man1 $(MAN_DIR)/man5 $(MAN_DIR)/man8
	$(INSTALL) -m 644    -p man/nodeusers.1  $(MAN_DIR)/man1
	$(INSTALL) -m 644    -p man/uronode.conf.5  $(MAN_DIR)/man5
	$(INSTALL) -m 644    -p man/uronode.perms.5 $(MAN_DIR)/man5
	$(INSTALL) -m 644    -p man/flexd.conf.5 $(MAN_DIR)/man5
	$(INSTALL) -m 644    -p man/uronode.8       $(MAN_DIR)/man8
	$(INSTALL) -m 644	  -p man/calibrate.8	 $(MAN_DIR)/man8
	$(INSTALL) -m 644	  -p man/axdigi.8	 $(MAN_DIR)/man8
	$(INSTALL) -m 644	  -p man/flexd.8	 $(MAN_DIR)/man8

upgrade: installbin installman installhelp
	$(INSTALL) -b -m 600    -p etc/uronode.announce  $(ETC_DIR)
	$(INSTALL) -m 755 -p uronode       $(SBIN_DIR)
	$(INSTALL) -m 755 -p nodeusers     $(SBIN_DIR)
	$(INSTALL) -m 755 -p calibrate	$(SBIN_DIR)
@IN@	$(INSTALL) -m 755 -p flexd		$(SBIN_DIR)
	$(INSTALL) -m 755 -p axdigi	$(SBIN_DIR)

 
clean:
	rm -f *.o *~ *.bak *.orig make.debug nodeusers uronode flexd axdigi calibrate
	rm -f etc/*~ etc/*.bak etc/*.orig
	rm -f etc/help/*~ etc/help/*.bak etc/help/*.orig

distclean: clean
	rm -f .depend Makefile.include config.h
	rm -f uronode nodeusers axdigi calibrate @FLEXNET@
	rm -f Makefile make.debug

depend:
	$(CC) $(CFLAGS) -M $(COMMON_SRC) $(NODE_SRC) $(NODEUSERS_SRC) $(FLEXD_SRC) $(CALIBRATE_SRC) > .depend

uronode: $(COMMON_OBJS) $(NODE_OBJS)
	$(LD) $(LDFLAGS) -o uronode $(COMMON_OBJS) $(NODE_OBJS) $(LIBS) $(ZLIB)

nodeusers: $(COMMON_OBJS) $(NODEUSERS_OBJS)
	$(LD) $(LDFLAGS) -o nodeusers $(COMMON_OBJS) $(NODEUSERS_OBJS) $(LIBS) $(ZLIB)

flexd: $(FLEXD_OBJS)
	$(LD) $(LDFLAGS) -o flexd $(FLEXD_OBJS) $(LIBS) $(ZLIB)

calibrate: $(CALIBRATE_OBJS)
	 $(LD) $(LDFLAGS) -o calibrate $(CALIBRATE_OBJS) $(LIBS) $(ZLIB)

axdigi: $(DIGI_OBJS)
	$(LD) $(LDFLAGS) -o axdigi $(DIGI_OBJS) $(LIBS) $(ZLIB)

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