TARGET = aplay-ex

SRCS := src/aplay.c

OBJS += $(subst .c,.o,$(SRCS))
HEDS += $(subst .c,.h,$(SRCS))
DEPS += $(subst .o,.d,$(OBJS))

ifndef YOCTOSDK_ROOT
YOCTOSDK_ROOT := /opt/poky/1.6.1
endif

ifndef EC_CXX
EC_CXX := $(YOCTOSDK_ROOT)/sysroots/i686-pokysdk-linux/usr/bin/arm-poky-linux-gnueabi/arm-poky-linux-gnueabi-g++
CXX := $(EC_CXX)
endif

#ifndef EC_CC
EC_CC := $(YOCTOSDK_ROOT)/sysroots/i686-pokysdk-linux/usr/bin/arm-poky-linux-gnueabi/arm-poky-linux-gnueabi-gcc
CC := $(EC_CC)
#endif

ifndef EC_SYSTEM_SDK
EC_SYSTEM_SDK := $(YOCTOSDK_ROOT)/sysroots/cortexa15hf-vfp-neon-poky-linux-gnueabi
endif

INCLUDEDIRS += -I$(PWD)/src/include
#INCLUDEDIRS += -I$(EC_SYSTEM_SDK)/usr/include
#INCLUDEDIRS += -I$(EC_BUILD_DIR)/include
#LIBDIRS += -L$(EC_SYSTEM_SDK)/usr/lib
#LIBDIRS += -L$(EC_TARGET_DIR)/lib

#LIBS :=
#LIBS += -pthread

EC_LDFLAGS += -lasound

RM := rm -rf

$(TARGET): $(OBJS)
	$(CC) $(LIBDIRS) -o $(TARGET) $(EC_LDFLAGS) $(OBJS) $(LIBS)
	@echo '***************************************'
	@echo 'Succeed to build target: $@'
	@echo '***************************************'

-include $(DEPS)

%.o: %.c
	$(CC) $(INCLUDEDIRS) -Wall -MMD -MP -MF$(@:%.o=%.d) -c -o $@ $<

all: $(TARGET)

install:
	make
	cp $(TARGET) $(EC_TARGET_DIR)/bin
	@echo '***************************************'
	@echo 'Succeed to install target: $(TARGET)'
	@echo '***************************************'

clean:
	-$(RM) $(OBJS) $(DEPS) $(TARGET)
