# This makefile is deprecated and no longer used by active developers.
# Please consider switching to the supported Xcode system.
# A guide to setting up a macOS build environment can found here:
# https://github.com/pjbroad/el-build-methods/tree/master/macOS/Xcode

.PHONY: clean release docs

# tune these for your setup & compile options
OPTIONS=-DOSX -DELC -DNO_MUSIC -DATI_9200_FIX -DBUG_FIX_3D_OBJECTS_MIN_MAX -DUSE_FRAMEBUFFER -DNEW_FRUSTUM -DAUTO_UPDATE -DNEW_TEX -DCOUNTERS -DNEW_E3D_FORMAT -DALUT_WAV
#-DX86_64
#-DTIMER_CHECK
#-DWRITE_XML
#-DNOTEPAD        # enable in-game notepad
#-DCUSTOM_LOOK    # allows you to customize your look. (EXPERIMENTAL)
#-DUID            # use unique ID sent from server for custom looks. (INCOMPLETE)
#-DNETWORK_THREAD # use separate thread for network reading (recommended)
#-DANTI_ALIAS     # allows to enable/disable anti-aliasing in el.ini
#-DMEMORY_DEBUG   # gather information about memory allocation and freeing
#-DPNG_SCREENSHOT # make screenshots in W3C's PNG format in game
#-DATI_9200_FIX   # flickering fix for ATI 92xx
#-DNEW_WEATHER    # new weather effects
#-DOPTIONS_I18N   # make option labels & descriptions translatable
#-DUSE_FRAMEBUFFER	# use framebuffer for reflection
#-DNEW_TEX        # use new texture coordinates for enhanced actors
#-DNEW_FRUSTUM    # use new frustum culling (AABB trees)
#-DBUG_FIX_3D_OBJECTS_MIN_MAX # Just a smal work around for the new frustum with the buggy 3d objects. This is not nessecary if you have correct 3d objects.
#-DDRAW_BBOX	  # draws the bounding boxes for 2d and 3d objects
#-DUSE_LISPSM	  # uses light space optimized shadow maps (EXPERIMENTAL)
#-DAUTO_UPDATE	  # enable minor automatic file updating
#-DAFK_FIX	# fixes afk messages to count only PM's, and store and count local messages if the option is selected
#-DFONTS_FIX		# dynamically loads all fonts with the filename in the format font*.bmp, and makes them accessable in the options

PLATFORM=-mpowerpc -malign-natural #-arch ppc64 -arch i386 -mpowerpc
XDIR=-L/usr/X11R6/lib
FRAMEWORKS=-framework OpenAL -framework OpenGL -framework GLUT -framework SDL -framework SDL_net
CWARN= #-Wall
#-Wdeclaration-after-statement -Wall -Werror
CXXWARN= #-Wall
#-Wall -Werror

# basic compiling and linking - rarely changed
CFLAGS=$(PLATFORM) $(CWARN) -O -pipe $(OPTIONS) -I/usr/include -I/usr/include/libxml2 -I/opt/local/include/ -I/Library/Frameworks/SDL.framework/Headers -D_REENTRANT -I/Library/Frameworks/SDL_net.framework/Versions/A/Headers/ -I/System/Library/Frameworks/OpenGL.framework/Headers/
_CFLAGS=$(PLATFORM) -O3 -fomit-frame-pointer -ffast-math -pipe $(OPTIONS) $(shell sdl-config --cflags) -I/usr/include/libxml2 -I/usr/local/include
CXXFLAGS=$(PLATFORM) $(CXXWARN) -O -ggdb -pipe $(OPTIONS)
_CXXFLAGS=$(PLATFORM) -O3 -fomit-frame-pointer -ffast-math -pipe $(OPTIONS)

LDFLAGS=-Wl SDLmain.o $(FRAMEWORKS) -lobjc -flat_namespace -L/usr/lib -lxml2 -lz -lpthread -liconv $(XDIR) -L/opt/local/lib -lcal3d -lm -lstdc++ -lc -Wno-long-double -headerpad_max_install_names
_LDFLAGS=$(XDIR) -Wl -flat_namespace -framework OpenAL -framework OpenGL -lpthread -lz
STATICLIBS=libs/libSDL_net.a libs/libSDL.a libs/libvorbisfile.a libs/libvorbis.a libs/libogg.a libs/libxml2.a libs/libcal3d.a libs/libpng.a

# the objects we need
COBJS=2d_objects.o 3d_objects.o	\
	actor_scripts.o actors.o alphamap.o asc.o astrology.o \
	books.o buddy.o bags.o bbox_tree.o \
	cache.o cal.o calc.o chat.o cluster.o colors.o console.o consolewin.o \
	counters.o cursors.o dialogues.o draw_scene.o	\
	elconfig.o elmemory.o elwindows.o encyclopedia.o errors.o events.o	\
	framebuffer.o filter.o frustum.o gamewin.o gl_init.o gamewin.o gl_init.o	\
	hud.o hud_misc_window.o hud_quickbar_window.o hud_statsbar_window.o help.o highlight.o	\
	ignore.o init.o interface.o items.o	\
	keys.o knowledge.o langselwin.o lights.o lispsm.o list.o loginwin.o loading_win.o	\
	main.o manufacture.o map_io.o mapwin.o	\
	md2loader.o md5.o misc.o missiles.o multiplayer.o	\
	new_actors.o new_character.o normals.o notepad.o	\
	openingwin.o	\
	particles.o paste.o pathfinder.o pm_log.o popup.o	\
	questlog.o queue.o reflection.o	rules.o skeletons.o skills.o \
	sector.o session.o serverpopup.o servers.o shader.o shadows.o sky.o sort.o sound.o spells.o stats.o storage.o symbol_table.o tabs.o	\
	terrain.o text.o textures.o tile_map.o timers.o translate.o trade.o	\
	update.o url.o weather.o widgets.o \
	books/fontdef.o books/parser.o books/symbols.o books/typesetter.o \
	text_aliases.o makeargv.o

CXXOBJS=cal3d_wrapper.o eye_candy_wrapper.o font.o \
 eye_candy/eye_candy.o eye_candy/math_cache.o eye_candy/effect_lamp.o \
 eye_candy/effect_candle.o \
 eye_candy/effect_campfire.o eye_candy/effect_fountain.o \
 eye_candy/effect_teleporter.o eye_candy/effect_firefly.o \
 eye_candy/effect_sword.o eye_candy/effect_summon.o \
 eye_candy/effect_selfmagic.o eye_candy/effect_targetmagic.o \
 eye_candy/effect_ongoing.o eye_candy/effect_impact.o \
 eye_candy/effect_smoke.o eye_candy/effect_bag.o eye_candy/effect_cloud.o \
 eye_candy/effect_harvesting.o eye_candy/effect_wind.o \
 eye_candy/effect_breath.o eye_candy/effect_glow.o \
 eye_candy/effect_mines.o eye_candy/effect_missile.o \
 eye_candy/orbital_mover.o eye_candy/kepler_orbit.o


OBJS=$(COBJS) $(CXXOBJS)

EXE=el_osx.exe

CC=gcc
CXX=g++
LINK=gcc

# the compile targets
$(EXE): $(OBJS)
	$(LINK) $(CFLAGS) $(LDFLAGS) -o $(EXE) $(OBJS)

$(COBJS): %.o : %.c
	$(CC) $(CFLAGS) -c -o $@ $<

$(CXXOBJS): %.o : %.cpp
	$(CXX) $(CXXFLAGS) -c -o $@ $<

release:
	$(MAKE) -f Makefile.osx 'CFLAGS=$(_CFLAGS)' 'CXXFLAGS=$(_CXXFLAGS)'

static:
	$(MAKE) -f Makefile.osx 'CFLAGS=$(_CFLAGS)' 'LDFLAGS=$(_LDFLAGS)' 'OBJS=$(OBJS) $(STATICLIBS) -lstdc++'

clean:
	rm -f $(OBJS) $(EXE) .depend

docs:
	cd docs && doxygen Doxyfile

.depend: *.h books/*.h elglext.h
	$(CC) $(CFLAGS) -MM $(patsubst %.o, %.c, $(COBJS)) >.depend
	$(CXX) $(CXXFLAGS) -MM $(patsubst %.o, %.cpp, $(CXXOBJS)) >>.depend

elglext.h: glext.pl glext.h
	perl glext.pl > $@

-include .depend
