# Makefile for whatfor

%.o:%.c
	gcc -DEOF=1 -o $@ $< 

whatfor: whatfor.c
	gcc -DEOF=1 -o whatfor.o whatfor.c -lc
	chmod 755 whatfor.o

whatfor_db: X11R6_db bin_db boot_db default_db dev_db etc_db \
include_db lib_db misc_db proc_db sbin_db src_linux_db var_db

	@cat default_db misc_db etc_db sbin_db bin_db X11R6_db \
boot_db dev_db include_db lib_db proc_db var_db > whatfor_db
	@echo "Making whatfor_db..."

	@if [ -d /usr/src/linux ]; then \
	echo "with src_linux_db included."; \
	cat src_linux_db >> whatfor_db; else \
	echo "but leaving out src_linux_db since no /usr/src/linux directory found."; fi
	chmod 644 whatfor_db

install: whatfor.o whatfor_db whatfor.1 whatfor_db.1
	make uninstall
	cp -p whatfor.o /usr/local/bin/whatfor
	@if [ ! -d /usr/local/share/misc ]; then \
	     mkdir /usr/local/share/misc; fi
	cp -p whatfor_db /usr/local/share/misc
	cp -p whatfor.1 /usr/local/man/man1
	cp -p whatfor_db.1 /usr/local/man/man1
	@echo "whatfor has been installed - testing it with this dir."
	@echo ""
	@whatfor

nocomp-install: whatfor whatfor_db whatfor.1 whatfor_db.1
	make uninstall
	cp -p whatfor /usr/local/bin/whatfor
	@if [ ! -d /usr/local/share/misc ]; then \
	     mkdir /usr/local/share/misc; fi
	cp -p whatfor_db /usr/local/share/misc
	cp -p whatfor.1 /usr/local/man/man1
	cp -p whatfor_db.1 /usr/local/man/man1
	@echo "whatfor has been installed."
	@echo ""
	@whatfor

clean:
	@if [ -f whatfor.o  ]; then rm whatfor.o;  fi
	@if [ -f whatfor_db ]; then rm whatfor_db; fi
	@echo "cleaned up"

# A small earlier release used non-standard locations for the installed
# files.  In case this new release is being installed on one of those
# systems, "make uninstall" removes the offending files.

uninstall:
	@if [ -f /usr/bin/whatfor                    ]; then \
              rm /usr/bin/whatfor;        fi
	@if [ -f /usr/man/man1/whatfor.1             ]; then \
              rm /usr/man/man1/whatfor.1; fi
	@if [ -f /etc/whatfor_db                     ]; then \
              rm /etc/whatfor_db;         fi
	@if [ -f /usr/local/bin/whatfor              ]; then \
              rm /usr/local/bin/whatfor;  fi
	@if [ -f /usr/local/man/man1/whatfor.1       ]; then \
              rm /usr/local/man/man1/whatfor.1; fi
	@if [ -f /usr/local/lib/whatfor_db           ]; then \
              rm /usr/local/lib/whatfor_db; fi
	@if [ -f /usr/local/share/misc/whatfor_db    ]; then \
              rm /usr/local/share/misc/whatfor_db; fi
	@if [ -f /usr/local/man/man1/whatfor_db.1    ]; then \
              rm /usr/local/man/man1/whatfor_db.1; fi
	@echo "whatfor has been uninstalled."
