# One of: osx86, osxppc, gp2x, win32, win32cross
# Or leave blank for generic LSB Unix-like
ARCH =

# If SDL is installed with some exceptional path or prefix
SDLPREFIX = 

CC = gcc
CFLAGS = -O2 -fomit-frame-pointer -Wall -ffast-math -std=c99 \
 -fno-strict-aliasing `$(SDLPREFIX)sdl-config --cflags` -DBLKSIZE=4096 \
 -DDOUBLEPIX
LDFLAGS = `$(SDLPREFIX)sdl-config --libs` -lpng -lz -lm
RANLIB = ranlib
AR = ar

TARGET = once_upon
OBJ = main.o halftone.o render.o noise.o png_wrap.o partikle.o putpix.o \
      heart.o overlay.o feissi.o rects.o cool_mzx/cool_mzx.a

# Define MSB on little endian systems.
# If the colors are wrong you can attempt to force -DFUKKIDRGBA
# To use 640x480 instead of native 320x240: -DDOUBLEPIX
# A bit less accurate but faster blend: -DQUICKBLEND
# For faster halftone: -DQUICKTONE
# To remove the framerate cap on particles (for slow gear): -DNOCAP
# If you want to locate the data files somewhere else, define DATADIR
# Sound buffer size can be controlled through BLKSIZE
# Hicolor support through -DHICOLOR, doesn't work with DOUBLEPIX

# Intel Mac OS X
ifeq ($(ARCH),osx86)
 CFLAGS += -I/opt/local/include -DMACOSX
 LDFLAGS += -L/opt/local/lib
# Static:
# LDFLAGS = `$(SDLPREFIX)sdl-config --static-libs` /opt/local/lib/libpng.a \
# /opt/local/lib/libz.a
endif

# PPC Mac OS X
ifeq ($(ARCH),osxppc)
 CFLAGS += -I/opt/local/include -DMSB
 LDFLAGS += -L/opt/local/lib
# Static:
# LDFLAGS = `$(SDLPREFIX)sdl-config --static-libs` /opt/local/lib/libpng.a \
# /opt/local/lib/libz.a
endif

# Windows MingW (possibly CygWin)
ifeq ($(ARCH),win32)
 CFLAGS += -DWIN32
 TARGET = once_upon.exe
endif

# Cross-compiler MingW on Linux
ifeq ($(ARCH),win32cross)
 SDLPREFIX = i586-mingw32msvc-
 CFLAGS += -DWIN32
 CC = i586-mingw32msvc-gcc
 AR = i586-mingw32msvc-ar
 RANLIB = i586-mingw32msvc-ranlib
 TARGET = once_upon.exe
endif

# Only for GP2X: video output with scaler: -DVIDEO
# and -DF200 for lower initial volume

ifeq ($(ARCH),gp2x)
 SDLPREFIX = /opt/open2x/gcc-4.1.1-glibc-2.3.6/bin
 CC = arm-open2x-linux-gcc
 RANLIB = touch
 CFLAGS = -O2 -Wall -ffast-math `$(SDLPREFIX)/sdl-config --cflags` \
  -DBLKSIZE=256 -DGP2X -I/opt/open2x/gcc-4.1.1-glibc-2.3.6/include \
  -msoft-float -fomit-frame-pointer -fno-strict-aliasing -pipe \
  -DHICOLOR -DNOCAP -DQUICKBLEND -DVIDEO
 LDFLAGS = -static -L/opt/open2x/gcc-4.1.1-glibc-2.3.6/lib \
  `$(SDLPREFIX)/sdl-config --libs` -lpng -lz -lm
 OBJ += gp2x.o
 STRIP = arm-open2x-linux-strip
endif

export

$(TARGET): $(OBJ)
	$(CC) $(OBJ) -o $@ $(LDFLAGS)

$(TARGET).gpe: $(TARGET)
	$(STRIP) $<
	mv $< $@

cool_mzx/cool_mzx.a:
	cd cool_mzx && make

clean:
	-rm $(TARGET) *.o *~ *.gpe
	cd cool_mzx && make clean
