# Makefile to produce test build of ctrmus for Linux
#
# make -f Makefile.linux

ifeq ($(OS),Windows_NT)
    HOST_OS := windows
    ifeq ($(PROCESSOR_ARCHITECTURE),AMD64)
        HOST_ARCH := x86_64
    else
        HOST_ARCH := i686
    endif
else
    UNAME_M := $(shell uname -m)
    ifeq ($(UNAME_M),$(filter $(UNAME_M),x86_64 amd64))
        HOST_ARCH := x86_64
    else ifeq ($(UNAME_M),$(filter $(UNAME_M),i386 i686))
        HOST_ARCH := i686
	else ifeq ($(UNAME_M),$(filter $(UNAME_M),aarch64 arm64))
            HOST_ARCH := arm64
    else
        $(error "Unsupported host architecture.")
    endif
endif

IDIR =./source
CC=gcc
CFLAGS=-I./include/
LIBS=-lsidplay -lmpg123 -lvorbisidec -lopusfile -lopus -logg -lm

ODIR=./build/$(HOST_ARCH)
SDIR=./source

_DEPS = all.h		\
		file.h		\
		flac.h		\
		mp3.h		\
		opus.h		\
		vorbis.h	\
		wav.h

DEPS = $(patsubst %,$(IDIR)/%,$(_DEPS))

_OBJ = file.o		\
		flac.o		\
		mp3.o		\
		opus.o		\
		test.o		\
		vorbis.o	\
		wav.o

OBJ = $(patsubst %,$(ODIR)/%,$(_OBJ))

all: directory test

directory:
	mkdir -p $(ODIR)

$(ODIR)/%.o: $(SDIR)/%.c $(DEPS)
	$(CC) -c -o $@ $< $(CFLAGS)

test: $(OBJ)
	gcc -o $@ $^ $(CFLAGS) $(LIBS)

.PHONY: clean directory

clean:
	rm -f $(ODIR)/*.o *~ core $(INCDIR)/*~
