################################################################################
# project               : Powermanga
# type 			: Game (Shoot'em up)
# company		: TLK Games (http://www.tlk.fr)
# programmers           : Jean-Michel Martin de Santero	mailto:jmm@tlk.fr
#                         Bruno Ethvignot mailto:bruno@tlk.fr
#                         Etienne Sobole  mailto:e.sobole@nexcom.fr
#                         Andre Majorel mailto:amajorel@teaser.fr	
#                         Emmanuel Founaud
# Linux port            : Bruno Ethvignot and Andre Majorel			
# Makefile              : Andre Majorel	mailto:amajorel@teaser.fr
# development           : Linux 2.2 (Red-Hat 6.2 et Mandrake 7.1) / XFree86 3.3
#                       : and 4.0 / GNOME / gcc 2.95    
#                       : Code Crusader 2.1.2, Nedit 5.1.1 and VIM 5.6  
#
# This program is free software; you can redistribute it and/or modify it under
# the terms of the  GNU General Public License as published by the Free
# Software Foundation; either version 2 of the License, or (at your option) any
# later version.  This program is distributed in the hope that it will be
# useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General
# Public License for more details.
#  
# You should have received a copy of the GNU General Public License along with
# this program; if not, write to the Free Software Foundation, Inc., 59 Temple
# Place - Suite 330, Boston, MA  02111-1307, USA.
################################################################################

# This makefile requires GNU make.

CC       = gcc
CXX    	 = g++
CXXFLAGS = -O3 -Wall -g
PROG     = powermanga
SCORE    = powermanga.hi
PREFIX   = /usr/local
LIBPATH  = -L/usr/X11R6/lib -L.

# Don't change anything below this line if you don't know what
# you're doing.

VERSION  = $(shell sed -ne 's/^.*NGA \([a-z0-9.]\+\) .*$$/\1/p' powermanga.hpp)
ARC      = $(PROG)-$(VERSION)
TMPDIR   = /var/tmp/powermanga.dist
ifeq ($(PREFIX),)
EXEDIR   = $(HOME)/bin
MANDIR   = $(HOME)/man
DATADIR  = $(HOME)/.powermanga
SCOREDIR = $(DATADIR)
else
EXEDIR   = $(PREFIX)/games
MANDIR   = $(PREFIX)/share/man
DATADIR  = $(PREFIX)/share/games/powermanga
SCOREDIR = /var/games
endif

MODS =  assembler     assembler_opt
MODC =  main          linuxroutines   xwindow          inits_game\
        powmangasub1  powmangasub2    powermanga       explosionExecution\
        fntscrol      vaisseau        metors           congratulations\
        _caractere    _chaine         _etb             _etbfonte1\
        _gardien12    _gardien13      _gardien14       _initialiseGameOver\
        bonus         courbe          playanim         afficheEtoiles\
        _score        tirsJoueur      eclairExecution  ennemis_execution\
        menu          touchesTriches  keymap           tirsExecutions\
        grille        options         seal             gardiens\
        gfxbase       displayFonte    onde             special_enemy\
        noassembler   firstwindow     xfree

MODULES = $(MODC) $(MODS)
OBJ     = $(addsuffix .o,   $(MODULES))
SRCC    = $(addsuffix .cpp, $(MODC))
SRCS    = $(addsuffix .S,   $(MODS))


all: $(PROG)

.cpp.o: powermanga.hpp
	$(CXX) $(CXXFLAGS) -DPROG=\"$(PROG)\" -o $@ -c $(DEFINES) $<

.S.o:
	$(CC) -DASMLANGUAGE -o $@ -c -x assembler-with-cpp \
	  $(AFLAGS) $(DEFINES) $(INCLUDES) $<


$(PROG): $(OBJ)
	printf 'extern const char nomfichierscore[]="%s";\n' "$(SCOREDIR)/$(SCORE)" > nomfichierscore.cc
	printf 'extern const char nomprefix[]="%s";\n' "$(PREFIX)" >> nomfichierscore.cc
	$(CXX) -c nomfichierscore.cc 
	$(CXX) -c nomfichierscore.cc 
	$(CXX) $(LIBPATH) $(OBJ) nomfichierscore.o $(PROFLAG) -lpthread -lm -lX11\
	  -lXext -lXxf86dga -lXxf86vm -laudio -o $@

install:
	mkdir -p $(EXEDIR)
	cp -p $(PROG) $(EXEDIR)
	chgrp games $(EXEDIR)/$(PROG)
	chmod g+s $(EXEDIR)/$(PROG) 
	mkdir -p $(MANDIR)
	cp -p powermanga.6 $(MANDIR)/man6
	mkdir -p $(DATADIR)
	cp -pR graphics sounds $(DATADIR)
	mkdir -p $(SCOREDIR)
	touch $(SCOREDIR)/$(SCORE)
	chown root:games $(SCOREDIR)/$(SCORE)
	chmod 664 $(SCOREDIR)/$(SCORE)

clean:
	rm -f $(OBJ)  

cleanall:
	rm -f $(PROG) $(OBJ)  

dist:
	mkdir -p $(TMPDIR)/$(ARC)
	cp -a . $(TMPDIR)/$(ARC)
	cd $(TMPDIR) && tar -czf $(ARC).tar.gz $(ARC)
	rm -fr $(TMPDIR)/$(ARC)
	echo "The distribution archive is $(TMPDIR)/$(ARC).tar.gz"

