# Makefile for NetWinder Utility Programs

NAME 	:= nwutil
VER	:= 1.8

CC	?= gcc
CFLAGS	?= -O2
CFLAGS  += -Wall -fsigned-char -Iinclude
LDFLAGS ?= -s

OBJS 	:= start_wdog set_therm fan_ctrl nwdebug fand
MANPGS	:= start_wdog.8 set_therm.8 fan_ctrl.8 nwdebug.8 fand.8
DOCDIR	:= /usr/share/doc/$(NAME)-$(VER)

export NAME VER

all: $(OBJS)
	$(MAKE) -C tools tools

install: all
	install -d $(DESTDIR)/usr/sbin
	install -m 700 $(OBJS) $(DESTDIR)/usr/sbin
	install -d $(DESTDIR)/usr/share/man/man8
	install -m 644 $(MANPGS) $(DESTDIR)/usr/share/man/man8
	install -d $(DESTDIR)/$(DOCDIR)
	install -m 444 welcome.au $(DESTDIR)/$(DOCDIR)
	$(MAKE) -C tools install

clean:
	rm -f .*~ *~ *.o $(OBJS) $(NAME)-$(VER).tar.gz
	$(MAKE) -C tools clean

#
# Packaging rules - warning: will destroy /tmp/$NAME-$VER
#
tar:	clean
	-which cvs2cl.pl 2>/dev/null && rm -f ChangeLog* && cvs2cl.pl
	-rm -rf /tmp/$(NAME)-$(VER)
	mkdir /tmp/$(NAME)-$(VER)
	cp -a * /tmp/$(NAME)-$(VER)
	tar -C /tmp --exclude=CVS --exclude=genflash.c --exclude=gzip_patch.c \
		-zcf `pwd`/$(NAME)-$(VER).tar.gz $(NAME)-$(VER)
	rm -rf /tmp/$(NAME)-$(VER)

rpm:	tar
	sed -e "s/@NAME@/$(NAME)/g" -e "s/@VER@/$(VER)/g" \
		rpmspec.template > /usr/src/redhat/SPECS/$(NAME)-$(VER).spec
	mv $(NAME)-$(VER).tar.gz /usr/src/redhat/SOURCES/
	rpm -ba /usr/src/redhat/SPECS/$(NAME)-$(VER).spec

