
C++FLAGS	= -O2 -fomit-frame-pointer -m68000 -Wall
CFLAGS		= -O2 -Wall
CPPFLAGS	= 
ARFLAGS		= -rsv
ECHO		= smakyecho

C++			= gcc
CC			= gcc
AR			= gcc_ar

C++SRCS	= $(wildcard *.cxx)
ASMSRCS	= $(wildcard *.s)
OBJS	= $(subst .cxx,.o,$(C++SRCS)) # $(subst .s,.o,$(ASMSRCS))
SMOBJ	= ntrel.o gesmem.o lib.o fos.o res.o gra.o
#MT_OBJS	= mtest.o gesmem.o ntrel.o

%.o : %.cxx
	@echo gcc is compiling $<
	@$(C++) -c $(C++FLAGS) $(CPPFLAGS) $< -o $@

%.asm : %.cxx
	@echo gcc is compiling $< for assembler source only
	@$(C++) -S $(C++FLAGS) $(CPPFLAGS) $< -o $@


all : #bin:sma_smaky.code

deps:
	#@$(ECHO) Making dependencies for the C++ sources
	@$(CC) -M $(CPPFLAGS) $(C++SRCS) > make-c++.deps

sma_smaky.code : $(OBJS) microcrt:microcrt.o microlib:microlib.a
	@echo gcc is linking $@
	@ld -ro -d -s -o $@ -Lmicrolib microcrt:microcrt.o $(OBJS) -lmu -lc

400_smaky.code : $(OBJS) microcrt:400_microcrt.o microlib:microlib.a 400_c++.o
	@echo gcc is linking $@
	@gld -r -d -s -o $@ -Lmicrolib microcrt:400_microcrt.o $(OBJS) 400_c++.o -lmu -lc
	@strip $@

#bin:sma_smaky.code : sma_smaky.code 400_smaky.code
	@rm #bin:sma_smaky.code
	@#:cp 400_smaky.code #bin:sma_smaky.code

mtest.code : $(MT_OBJS)
	@echo gcc is linking $@
	#@gcc -o $@ $(MT_OBJS) -lgxx
	@ld -ro -d -s -o $@ #:gnulib:crt0.o $(MT_OBJS) -lgxx -lc

smlib :
	$(ar) $(ARFLAGS) libsm.a $(SMLIBOBJ)

clean:
	#@$(ECHO) Cleaning up the object files
	@-rm -f make-c++.deps $(OBJS) $(wildcard *.a)
	@cd microcrt
	@$(MAKE) clean
	@cd #src:code:smaky:
	@cd microlib
	@$(MAKE) clean
	@cd #src:code:smaky:

microlib:microlib.a :
	@cd microlib
	@$(MAKE) all
	@cd #src:code:smaky:

microcrt:microcrt.o : 
	@cd microcrt
	@$(MAKE) all
	@cd #src:code:smaky:


.PHONY : all deps clean

#  Include the dependency file if it does exist. If not, the result will
#  be unpredictable. This is just a trick to be able to `make deps'.

ifeq ("$(wildcard make-c++.deps)", "make-c++.deps ")
include make-c++.deps
endif

