# Copyright (C) Information Equipment co.,LTD
# All rights reserved.
# Code by JaeHyuk Cho <mailto:minzkn@infoeq.com>
# CVSTAG="$Header$"

# bash$ make TARGET_ARCH=i386 all
# bash$ make TARGET_ARCH=mips all
# bash$ make TARGET_ARCH=ppc all
# bash$ make TARGET_ARCH=arm all

TARGET_ARCH                  :=i386
# TARGET_ARCH                  :=mips
# TARGET_ARCH                  :=ppc
# TARGET_ARCH                  :=arm

TARGET_CONFIG                :=#

ifeq ($(findstring mips,$(TARGET_ARCH)),mips)
 CROSS_COMPILE               :=/opt/kenati/bin/lx4189-uclibc-#
else
 ifeq ($(findstring ppc,$(TARGET_ARCH)),ppc)
  CROSS_COMPILE              :=/opt/hardhat/devkit/ppc/405/bin/ppc_405-#
 else
  ifeq ($(findstring arm,$(TARGET_ARCH)),arm)
   CROSS_COMPILE             :=/usr/local/arm-linux/bin/arm-linux-#
   TARGET_CONFIG             += nofpu
  else
   ifeq ($(findstring i386,$(TARGET_ARCH)),i386)
    CROSS_COMPILE            :=#
   else
    CROSS_COMPILE            :=#
   endif
  endif
 endif
endif

CC                           := $(CROSS_COMPILE)gcc
RM                           := rm -f
OBJDUMP                      := $(CROSS_COMPILE)objdump

CFLAGS                       := -O2 -Wall -Werror -fomit-frame-pointer -ansi -pipe
LDFLAGS                      := -s

CFLAGS                       += -D_REENTRANT
ifeq ($(findstring nofpu,$(TARGET_CONFIG)),nofpu)
CFLAGS                       += -msoft-float
else
LDFLAGS                      += -lm
endif
LDFLAGS                      += -lpthread

TARGET                       := pmp3_decode

OBJECT_pmp3_decode           := pmp3_decode.o
ifeq ($(findstring i386,$(TARGET_ARCH)),i386)
CFLAGS                       += -DDEF_I386=586 
OBJECT_pmp3_decode           += getbits.o interface.o layer3.o mp3_ext.o decode_i586.o dct64_i386.o
else
OBJECT_pmp3_decode           += getbits.o interface.o layer3.o mp3_ext.o decode.o dct64.o
endif

OBJECTS                      := $(OBJECT_pmp3_decode)

.PHONY: all clean

all: $(TARGET)
clean: ; $(RM) *.o $(TARGET)

OBJECTS: Makefile mpg123.h mp3_ext.h

pmp3_decode: $(OBJECT_pmp3_decode) ; $(CC) $(LDFLAGS) -o $(@) $(^)

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

# End of Makefile
