ifdef $(GENDEV)
ROOTDIR = $(GENDEV)
else
ROOTDIR = /opt/toolchains/sega
endif

INSTALLDIR = $(ROOTDIR)/m68k-elf

LIBPATH = -L$(ROOTDIR)/m68k-elf/lib -L$(ROOTDIR)/m68k-elf/lib/gcc/m68k-elf/4.6.2 -L$(ROOTDIR)/m68k-elf/m68k-elf/lib
INCPATH = -I. -I$(ROOTDIR)/m68k-elf/include -I$(ROOTDIR)/m68k-elf/m68k-elf/include

CCFLAGS = -m68000 -O1 -Wall -c -fomit-frame-pointer
ASFLAGS = -m68000 --register-prefix-optional

PREFIX = $(ROOTDIR)/m68k-elf/bin/m68k-elf-
CC = $(PREFIX)gcc
AS = $(PREFIX)as
AR = $(PREFIX)ar

CP = cp
RM = rm -f

TARGET = libpcm
OBJS = pcm.o pcm-io.o

all: $(TARGET).a

$(TARGET).a: $(OBJS)
	$(AR) -rcs $@ $(OBJS)

%.o: %.c
	$(CC) $(CCFLAGS) $(INCPATH) $< -o $@

%.o: %.s
	$(AS) $(ASFLAGS) $(INCPATH) $< -o $@

clean:
	$(RM) *.o *.a

install: all
	$(CP) pcm.h $(INSTALLDIR)/include
	$(CP) libpcm.a $(INSTALLDIR)/lib
