#
# Top level Makefile for TOS-Gcc library
#

# GCC configuration info...

# Leave the next line undefined for native compilation setup.
CROSSDIR := /local/x68

# Define MINTFLAG when compiling mntlib
# 
# MINTFLAG := -mint

ifdef MINTFLAG
MINTOPT := -mint
else
MINTOPT :=
endif

ifdef CROSSDIR

# Set up to do cross-compiling...

CROSSLIB := $(CROSSDIR)/lib
CROSSBIN := $(CROSSDIR)/bin

AR	:= $(CROSSBIN)/car
AS 	:= cgcc $(MINTOPT)
CC	:= cgcc $(MINTOPT)
LIB     := $(CROSSLIB)
VPATH   := ../co

else

# Set up to run native...

AR	:= gcc-ar
AS	:= gcc $(MINTOPT)
CC	:= gcc $(MINTOPT)
LIB	:= d:\gnu\lib

endif

# Additional options for compiling C code

XFLAGS := -I../co

# Dynamic selection of options for each target library...

ifneq (,$(findstring debug,$(TARGET)))
OPTIM= -O -g -Wstrict-prototypes
FRAME=
DEBUG=
g=g
else
OPTIM= -O2 -fstrength-reduce
FRAME= -fomit-frame-pointer
DEBUG= -DNDEBUG
g=
endif

ifneq (,$(findstring long-int,$(TARGET)))
SHORT=
DSHORT=
ST=
else
SHORT= -mshort
DSHORT= -DSHORTLIB
ST=16
endif

ifneq (,$(findstring 68020,$(TARGET)))
CC := $(CC) -m68020 -m68881
endif

ifneq (,$(findstring baserel,$(TARGET)))
CC := $(CC) -mbaserel
b=b
else
b=
endif

# common subset of options; no int size or omit-frame-pointer:
COPTS= $(DEBUG) $(OPTIM) $(XFLAGS)

# Base options CC; includes int size but not omit-frame-pointer
CFFLAGS = $(SHORT) $(COPTS)

# normal CFLAGS including int size and omit-frame-pointer
CFLAGS= $(CFFLAGS) $(FRAME)

# cflags for stuff that needs to be compiled with 32 bit ints
CLFLAGS= $(COPTS) $(FRAME) $(DSHORT)

# flags to $(CC) when it runs the assembler only
ASFLAGS= -c

# flags to $(CC) when running preprocessor and assembler
PPFLAGS= $(SHORT) -P

# library targets
ifdef MINTFLAG

CLIB= $bmint$g$(ST).olb
CLIB020=$bmint$g$(ST)020.olb
IIOLIB= $bmiio$g$(ST).olb
CRT0=$bmcrt0.o
GCRT0=$bmgcrt0.o

else

CLIB= $bgnu$g$(ST).olb
CLIB020=$bgnu$g$(ST)020.olb
IIOLIB= $biio$g$(ST).olb
CRT0=$bcrt0.o
GCRT0=$bgcrt0.o

endif

STARTO= $(CRT0) $(GCRT0)

# the stuff to make
ALL= $(CLIB) $(IIOLIB) $(STARTO)
ALL020 = $(CLIB020) $(STARTO)

#all: lshort llong lgshort lglong
top: lshort llong

lshort:
	$(MAKE) clean
	$(MAKE) install

llong:
	$(MAKE) clean
	$(MAKE) install TARGET=long-int

lgshort:
	$(MAKE) clean
	$(MAKE) install TARGET=debug

lglong:
	$(MAKE) clean
	$(MAKE) install TARGET="long-int debug"

l020short:
	$(MAKE) clean
	$(MAKE) install020 TARGET=68020

l020long:
	$(MAKE) clean
	$(MAKE) install020 TARGET="68020 long-int"

lb020short:
	$(MAKE) clean
	$(MAKE) install020 TARGET="68020 baserel"

lb020long:
	$(MAKE) clean
	$(MAKE) install020 TARGET="68020 long-int baserel"

lbshort:
	$(MAKE) clean
	$(MAKE) install TARGET="baserel"

lblong:
	$(MAKE) clean
	$(MAKE) install TARGET="long-int baserel"

realclean:
	rm -f *.o *.olb
	rm -f core report

# Get the rules to build everything...

include mincl
