CPP = g++
SDL_LIBS = `sdl-config --libs`
SDL_CFLAGS = `sdl-config --cflags`
## dirs must be appended with a / character!
LOCAL = /usr/local/
SHAREDIR = $(LOCAL)share/phatbeat/
D_PFLAGS = -Wall -g 	## For debugging, use this.
PFLAGS = -Wall -finline-functions -O3 $(SDL_CFLAGS)
XFLAGS = $(PFLAGS) $(SDL_LIBS) -lSDL_image -lm
PROGS = phatbeat phatx

.PHONY: clean all phatbeat phatx

## To make for GNU/Linux, just issue 'make', then 'make install' as root.
## If you want to put your shared files somewhere other than the default 
## directory, change the SHAREDIR variable defined above.

all: $(PROGS)

phatbeat: BeatCounter.o phatbeat.o
	$(CPP) $(PFLAGS) phatbeat.o BeatCounter.o -o phatbeat

phatx: BeatCounter.o phatx.o numbers.o resize.o portability.o
	$(CPP) $(XFLAGS) portability.o phatx.o resize.o numbers.o BeatCounter.o -o phatx

BeatCounter.o: BeatCounter.h BeatCounter.cpp
	$(CPP) $(PFLAGS) -c BeatCounter.cpp

numbers.o: numbers.h numbers.cpp portability.o
	$(CPP) $(PFLAGS) -c numbers.cpp
	
resize.o: resize.h resize.cpp
	$(CPP) $(PFLAGS) -c resize.cpp

phatbeat.o: phatbeat.cpp
	$(CPP) $(PFLAGS) -c phatbeat.cpp 

phatx.o: phatx.cpp
	$(CPP) $(PFLAGS) -c phatx.cpp 

portability.o: portability.cpp
	$(CPP) $(PFLAGS) -D'SHAREDIR="$(SHAREDIR)"' -c portability.cpp 

## For compiling a win32 version under cygwin, issue
## 'make phat_win', and it will do so.

phat_win: BeatCounter.o phatx.o numbers.o resize.o phatres.o
	$(CPP) -o phat_win.exe phatx.o resize.o numbers.o BeatCounter.o portability.o phatres.o $(XFLAGS)

phatres.o: phatres.rc
	windres phatres.rc phatres.o

clean:
	-rm -f *.o $(PROGS)

## Installation routines for unix.   
install: 
	## First, install the programs.
	/usr/bin/install -c -m 755 phatbeat $(LOCAL)/bin
	/usr/bin/install -c -m 755 phatx $(LOCAL)/bin
	/usr/bin/install -c -m 444 phatbeat.1 $(LOCAL)/man/man1
	## Then, the images
	mkdir -p $(SHAREDIR)/images
	/usr/bin/install -c -m 444 images/* $(SHAREDIR)/images
