# Makefile for libRILc.
# Simple implementation of a standard C library (and a few other things).
# Copyright © 1993, 1997, 1998 Rask Ingemann Lambertsen.

# libRILc is freely distributable as described in the file DISTRIBUTION.

srcdir = @srcdir@
top_srcdir = @top_srcdir@
VPATH  = @srcdir@

CC = @CC@
AR = @AR@

PPC_AFLAGS  = -Wa,-mregnames
M68K_AFLAGS =

ALL_CPPFLAGS = -I $(srcdir)/include -I $(srcdir)/internal $(CPPFLAGS)

export M68KFLAGS = -m68020-60 -g
export PPCFLAGS  = -mcpu=604 -mmultiple -mstring -g

export CFLAGS = -O3 -fomit-frame-pointer -Wall $(@CPU@FLAGS)
ALL_CFLAGS = $(CFLAGS) $(ALL_CPPFLAGS)

prefix = @prefix@
exec_prefix = @exec_prefix@

INSTDIR_HEADERS = @includedir@
INSTDIR_LIBRARY = @libdir@

# Try to produce a list of object modules that will be generated from the
# source files. Perhaps it even works?
OBJSSRC := $(wildcard $(srcdir)/internal/*.c $(srcdir)/locale/*.c $(srcdir)/memory/*.c $(srcdir)/misc/*.c $(srcdir)/stdio/*.c $(srcdir)/stdlib/*.c $(srcdir)/stdlib/*-@CPU@.s $(srcdir)/string/*.c $(srcdir)/unix/*.c)
OBJS :=  $(patsubst $(srcdir)/%.s,%.o,$(patsubst $(srcdir)/%.c,%.o,$(OBJSSRC)))

# Prevent implicit rules from f*cking things up.
.c.o :
	@echo "Error: Implicit rule hit trying to generate" $@ "from" $+

.s.o :
	@echo "Error: Implicit rule hit trying to generate" $@ "from" $+

.c.s :
	@echo "Error: Implicit rule hit trying to generate" $@ "from" $+

all : internal locale memory misc stdio stdlib string unix libRILc.a startup

install : libRILc.a startup
	Copy CLONE $< $(INSTDIR_LIBRARY)/libc.a
	Copy CLONE ALL QUIET $(srcdir)/include $(INSTDIR_HEADERS)
	cd startup; make install

clean :
	-Delete libRILc.a QUIET
	cd internal; make clean
	cd locale;   make clean
	cd memory;   make clean
	cd misc;     make clean
	cd stdio;    make clean
	cd stdlib;   make clean
	cd string;   make clean
	cd unix;     make clean
	cd startup;  make clean

internal :
	cd internal; make

locale :
	cd locale;   make

memory :
	cd memory;   make

misc :
	cd misc;     make

stdio :
	cd stdio;    make

stdlib :
	cd stdlib;   make

string :
	cd string;   make

unix :
	cd unix;     make

startup :
	cd startup; make

.PHONY : all install clean internal locale memory misc stdio stdlib string unix startup

libRILc.a : $(OBJS)
	$(AR) rsc $@ $?
