#
# This doesn't actually work!! It's provided in the hope
# that someone might be able to sort out the linking errors
#

PROG = blobAndConquer.exe
PAKNAME = blobAndConquer.pak
DOCS = doc/*
ICONS = icons/

PAKDIRS = data gfx music sound textures

VERSION = 1.10
RELEASE = 1
USEPAK = 0
DEV = 0

PREFIX = $(DESTDIR)/usr
BINDIR = $(PREFIX)/games/
DATADIR = $(PREFIX)/share/games/blobAndConquer/
DOCDIR = $(PREFIX)/share/doc/$(PROG)/
ICONDIR = $(PREFIX)/share/icons/
MENUDIR = $(PREFIX)/share/applications/
LOCALEDIR = $(PREFIX)/share/locale/

CXX=i586-mingw32msvc-g++
SDLC=/home/steve/Windows/bin/sdl-config

CXXFLAGS = $(CFLAGS)
CXXFLAGS += -Wformat=2 -Wformat-security -Wstrict-aliasing=2
CXXFLAGS += -Wmissing-format-attribute -Wmissing-noreturn
CXXFLAGS += -Wdisabled-optimization
CXXFLAGS += `$(SDLC) --cflags` -DVERSION=$(VERSION) -DRELEASE=$(RELEASE) -DUSEPAK=$(USEPAK) -DDEV=$(DEV)
CXXFLAGS += -DPAKNAME=\"$(PAKNAME)\" -DPAKLOCATION=\"$(DATADIR)\" -DGAMEPLAYMANUAL=\"$(DOCDIR)/index.html\" -Wall
CXXFLAGS += -DLOCALEDIR=\"$(LOCALEDIR)\"
LIBS = `$(SDLC) --libs` -lintl -lSDL_mixer -lSDL_image -lSDL_ttf -lz -lopengl32 -lglu32

# Yes, it means compiling is a little slower... but it's less hassle
SEARCHPATH += src/
SEARCHPATH += src/bosses
SEARCHPATH += src/combat
SEARCHPATH += src/cplusplus
SEARCHPATH += src/effects
SEARCHPATH += src/entities
SEARCHPATH += src/hud
SEARCHPATH += src/io
SEARCHPATH += src/misc
SEARCHPATH += src/missions
SEARCHPATH += src/puzzles
SEARCHPATH += src/world
vpath %.cpp $(SEARCHPATH)
vpath %.h $(SEARCHPATH)

OBJS += CAudio.o
OBJS += CBaseWidget.o CBlobDef.o CBoundingBox.o CBoundingBoxManager.o CBoss.o CBossDef.o CBSP.o CBullet.o CButton.o
OBJS += CCamera.o CCheckBox.o CCollision.o CComboBox.o CCrumb.o CCrumbBox.o CCutsceneCamera.o CCutsceneCommand.o
OBJS += CData.o CDecal.o CDecoration.o CDoor.o
OBJS += CEmitter.o CEnemyDef.o CEntity.o CEntityDef.o CEntityManager.o CEngine.o
OBJS += CFace.o CFeature.o CFileData.o CFrustum.o
OBJS += CGame.o CGeometry.o CGLColor.o CGraphics.o CGrid.o
OBJS += CHashtable.o 
OBJS += CInputWidget.o CItem.o CItemDef.o
OBJS += CLabel.o CLinkable.o CList.o CListView.o CListViewItem.o
OBJS += CMap.o CMath.o CMD2.o CMDLModel.o CMission.o CModelManager.o CMouse.o
OBJS += CObjective.o
OBJS += CPak.o CPanel.o CParticle.o CParticleManager.o CPlane.o CPoint.o CProperties.o
OBJS += CQ3Target.o
OBJS += CRandomNameGen.o CReference.o
OBJS += CSaveGameHeader.o CSimpleModel.o CSlider.o CSprite.o CString.o CStructure.o CSwitch.o
OBJS += CTexture.o CTextureManager.o CTextureSpec.o CTextureSpecManager.o CTrace.o CTrap.o CTriangle.o CTrigger.o
OBJS += CUIManager.o CUnit.o
OBJS += CVector.o CVectori.o
OBJS += CWeapon.o CWeaponDef.o

OBJS += ambush.o
OBJS += battle.o bioMechBlobs.o bioTanks.o blobs.o bosses.o bsp.o bullets.o
OBJS += camera.o combat.o controlPanel.o cryptBoss.o cutscene.o
OBJS += darkBioMechs.o decals.o decoration.o dialogs.o doors.o
OBJS += emitters.o enemy.o eyeDroids.o eyeDroidCommander.o explosions.o
OBJS += features.o finalBoss.o
OBJS += game.o
OBJS += init.o items.o
OBJS += laserGrid.o lift.o load.o
OBJS += mastermind.o md2.o misc.o mission.o modelLoader.o
OBJS += opengl.o options.o
OBJS += particles.o player.o propertiesLoader.o
OBJS += resources.o
OBJS += save.o sentryGuns.o shadows.o specialist.o spiderBlobs.o spiderBlobCommander.o status.o strtok_r.o structures.o switches.o
OBJS += title.o traps.o triggers.o
OBJS += units.o
OBJS += weapons.o weather.o widgets.o world.o

GAMEOBJS = $(OBJS) main.o
PAKOBJS = CLinkable.o CFileData.o pak.o

LOCALE_MO = $(patsubst %.po,%.mo,$(wildcard locale/*.po))

# top-level rule to create the program.
all: $(PROG) pak

%.o: %.cpp %.h data/gameDefs/defines.h defs.h headers.h
	$(CXX) $(CXXFLAGS) -c $<

# linking the program.
$(PROG): $(GAMEOBJS)
	$(CXX) $(GAMEOBJS) $(LIBS) -o $(PROG)
	
pak: $(PAKOBJS)
	$(CXX) $(LIBS) $(PAKOBJS) -o pak
	
%.mo: %.po
	msgfmt -c -o $@ $<
	
buildpak:
	./pak $(PAKDIRS) $(PAKNAME)

# cleaning everything that can be automatically recreated with "make".
clean:
	$(RM) $(OBJS) $(PAK).o main.o $(PROG)
