#
# Makefile for MiNT
#

SHELL = /bin/sh
SUBDIRS = 

srcdir = ..
top_srcdir = ..
subdir = $(compile_dir)

default: all

include $(top_srcdir)/CONFIGVARS
include $(top_srcdir)/RULES
include $(top_srcdir)/PHONY

all-here: build

# default overwrites
DEFINITIONS = $(KERNELDEFAULTDEFS) $(KERNELDEFS)
WARN =	-Wall \
	-Wmissing-prototypes \
	-Winline
LDFLAGS = -nostdlib
LDFLAGS += -Wl,-Map -Wl,map.txt
# XXX should be come from arch/
LDFLAGS += -Wl,--entry -Wl,_main
LIBS = $(LIBKERN) -lgcc

ifeq ($(KMEMDEBUG),yes)
LDFLAGS += \
	-Wl,--wrap -Wl,_kcore \
	-Wl,--wrap -Wl,_kmalloc \
	-Wl,--wrap -Wl,_kfree \
	-Wl,--wrap -Wl,_umalloc \
	-Wl,--wrap -Wl,_ufree
endif

NOCFLAGS-gmon.c = -pg
NOCFLAGS-mcount.c = -pg
NOCFLAGS-profil.c = -pg
NOCFLAGS-update.c = -pg

cflags = $(kernel_cflags)
nocflags = $(kernel_nocflags)

# default definitions
GENFILES = $(BUILDINFO) $(MINT)
BUILD = info
BUILDINFO = $(BUILD).o
OBJS = $(COBJS:.c=.o)

VPATH = ..

#
# main target
#
build: $(MINT)

$(MINT): $(OBJS) $(BUILDINFO) $(LIBKERNTARGET)
	$(CC) $(CFLAGS) $(LDFLAGS) -o $@ \
		$(shell for file in `cat $(srcdir)/arch/$(compile_dir)/startup` ; \
			do echo $(srcdir)/arch/$(compile_dir)/$$file ; done) \
		$(OBJS) $(BUILDINFO) \
		$(shell for file in `cat $(srcdir)/arch/$(compile_dir)/objs` ; \
			do echo $(srcdir)/arch/$(compile_dir)/$$file ; done) \
		$(LIBS)

$(BUILDINFO): compiler buildheader buildserial
	$(CC) $(CFLAGS) -o $@ -c $(srcdir)/$(BUILD).c

compiler:
	cd $(srcdir)/buildinfo; \
	CC="$(CC)" \
	OPTS="$(GENERAL) $(MODEL) $(OPTS)" \
	DEFS="$(DEFINITIONS)" \
	sh cdef.sh

buildheader:
	cd $(srcdir)/buildinfo; ./mkbuild

buildserial: $(srcdir)/buildinfo/version.h
	cd $(srcdir)/buildinfo; echo 1 >$@

# default dependencies
# must be included last
include $(top_srcdir)/DEPENDENCIES
