# Very basic and very simple Makefile. Maybe it would be nice to make it
# in ac/am.... but I'm too lazy ;)
# 
VERSION		= 2.4.4

CC		= gcc
OPT_FLAGS	= -O2 -g
CFLAGS		= $(OPT_FLAGS) -Wall
INSTALL		= install
SBINDIR		= /sbin
ETCDIR		= /etc
PROFILEDIR	= $(ETCDIR)/profile.d
#########################################

BIN_FILES	= joinpasswd
DOCS		= ChangeLog
ETC_FILES	= filesystems fstab group host.conf hosts motd mtab \
	    netgroup passwd profile protocols resolv.conf securetty \
	    services shells
PROFILE_FILES	= tmp-dir.csh tmp-dir.sh

SOURCES		= joinpasswd.c
CLEAN		= $(BIN_FILES) *.o core *.tar.gz *.tar.bz2 *~ *.swp

#########################################
all: joinpasswd

joinpasswd: joinpasswd.o

.c.o:
	$(CC) $(CPPFLAGS) $(CFLAGS) $(CDEFS) -c $< -o $@

clean:
	rm -f $(CLEAN)
	cd etc; rm -f $(CLEAN)
	cd etc/profile.d; rm -f $(CLEAN)

install:
	$(INSTALL) -d $(DESTDIR)/$(SBINDIR)
	$(INSTALL) -d $(DESTDIR)/$(ETCDIR)
	$(INSTALL) -d $(DESTDIR)/$(PROFILEDIR)
	$(INSTALL) $(BIN_FILES) $(DESTDIR)/$(SBINDIR)
	cd etc; $(INSTALL) $(ETC_FILES) $(DESTDIR)/$(ETCDIR)
	cd etc/profile.d; $(INSTALL) $(PROFILE_FILES) $(DESTDIR)/$(PROFILEDIR)

dist: clean
	
	$(INSTALL) -d setup-$(VERSION)/etc/profile.d
	$(INSTALL) $(DOCS) $(SOURCES) Makefile setup-$(VERSION)
	for file in $(ETC_FILES); do \
		$(INSTALL) etc/$$file setup-$(VERSION)/etc; \
	done
	for file in $(PROFILE_FILES); do \
		$(INSTALL) etc/profile.d/$$file setup-$(VERSION)/etc/profile.d; \
	done
	tar -cvjf setup-$(VERSION).tar.bz2 setup-$(VERSION)
	rm -rf setup-$(VERSION)
