# Makefile for combined FLAC, FLAC++, derived from zlib's Makefile.mgw,
# which was itself derived from zlib's Makefile.dj2.
# Modified for mingw32 by C. Spieler, 6/16/98.
# Updated for zlib 1.2.x by Christian Spieler and Cosmin Truta, Mar-2003.
# Last updated: 1-Aug-2003.

# Copyright (C) 1995-2003 Jean-loup Gailly.
# For conditions of distribution and use, see copyright notice in zlib.h

ifeq (Windows_NT,$(OS))
  WIN=1
  WINCMD=1
endif
ifeq (msys,$(OSTYPE))
  WIN=1
  WINCMD=0
endif

STATICLIB = libflac.a

#LOC = -DASMV
#LOC = -DDEBUG -g

DEFINES = -D__MINW32__ -DWIN32 -DNDEBUG -D_LIB -DFLAC__CPU_IA32 -DFLAC_HAS_NASM -DFLAC__SSE_OS -DFLAC__USE_3DNOW -DFLAC__NO_DLL -I.

CCDV = @../ccdv
CC = gcc
CXX = g++
CFLAGS = $(LOC) $(DEFINES) -O2 -Wall -fomit-frame-pointer
CXXFLAGS = $(LOC) $(DEFINES) -O2 -Wall

NASM = nasmw
NASMFLAGS = -d OBJ_FORMAT_win32 -f win32

AR = ar
ARFLAGS = rcs

OBJS = cpu_asm.o fixed_asm.o lpc_asm.o \
       bitbuffer.o bitmath.o cpu.o crc.o fixed.o format.o lpc.o memory.o stream_decoder.o stream_decoder_pp.o

all: $(STATICLIB)

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

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

$(STATICLIB): $(OBJS)
	$(CCDV) $(AR) $(ARFLAGS) $@ $(OBJS)


.PHONY: clean

clean:
ifeq (1,$(WINCMD))
	-del /q /f $(STATICLIB) 2>nul
	-del /q /f *.o 2>nul
else
	rm -f $(STATICLIB)
	rm -f *.o
endif

cpu_asm.o: ia32/cpu_asm.nasm
	$(CCDV) $(NASM) -o $@ $(NASMFLAGS) $<
fixed_asm.o: ia32/fixed_asm.nasm
	$(CCDV) $(NASM) -o $@ $(NASMFLAGS) $<
lpc_asm.o: ia32/lpc_asm.nasm
	$(CCDV) $(NASM) -o $@ $(NASMFLAGS) $<
bitbuffer.o: bitbuffer.c
bitmath.o: bitmath.c
cpu.o: cpu.c
crc.o: crc.c
fixed.o: fixed.c
format.o: format.c
lpc.o: lpc.c
memory.o: memory.c
stream_decoder.o: stream_decoder.c
stream_decoder_pp.o: stream_decoder_pp.cpp
