# Makefile for Powertweak Linux
# (c) 2000 Dave Jones <dave@powertweak.com>

VERSION=0.1.7
SUFFIX=
DATE=00-1-29

OPT= -O2 -fomit-frame-pointer
CFLAGS=$(OPT) -W -Wno-parentheses -Wstrict-prototypes -g `gtk-config --cflags --libs`
LCFLAGS=$(OPT) -W -Wno-parentheses -Wstrict-prototypes -g

PREFIX=/usr

export

all: 			version lib powertweak powertweak-config powertweak.8

version:
				echo \#define POWERTWEAK_VERSION \"$(VERSION)$(SUFFIX)\" >version.h

lib:			lib/config.h
				$(MAKE) -C lib all CFLAGS="$(LCFLAGS)"
lib/config.h:
				cd lib && ./configure $(PREFIX) $(VERSION)

powertweak:		powertweak.o common.o lib/libpci.a

powertweak.o:	powertweak.c pciutils.h lib/libpci.a
				$(CC) $(LCFLAGS) -c $<

common.o:		common.c pciutils.h lib/libpci.a
				$(CC) $(LCFLAGS) -c $<

powertweak-config:	common.o lib/libpci.a powertweak-config.c

%.8: %.man
	sed <$< >$@ "s/@TODAY@/`date -d $(DATE) '+%d %B %Y'`/;s/@VERSION@/powertweak-$(VERSION)$(SUFFIX)/"

clean:
	rm -f `find . -name "*~" -or -name "*.[oa]" -or -name "\#*\#" -or -name TAGS -or -name core`
	rm -f version.h powertweak powertweak-config *.8 lib/config.*

install: all uninstall
	install -m 755 -s powertweak $(PREFIX)/sbin
	install -m 755 -s powertweak-config $(PREFIX)/sbin
	install -m 644 pci.ids $(PREFIX)/share
	install -m 644 powertweak.8 $(PREFIX)/man/man8

uninstall:
	rm -rf $(PREFIX)/share/powertweak/
	rm -f /sbin/powertweak /sbin/powertweak-config
	rm -f $(PREFIX)/sbin/powertweak
	rm -f $(PREFIX)/sbin/powertweak-config
	rm -f $(PREFIX)/man/man8/powertweak.8

.PHONY: all lib clean install man
