SYSTEM= $(shell uname)

CROSS=	1

ifdef CROSS

CPPFLAGS+=	-DCROSS

ifeq ($(SYSTEM),Linux)

TARGET=
FLOPPY=/dev/fd0

else

TARGET=i386-linux-

ifeq ($(SYSTEM),FreeBSD)
FLOPPY=/dev/rfd0.1440
endif

endif

endif

ifdef NDEBUG
CPPFLAGS+=      -DNDEBUG
endif

ifdef DEBUG
CPPFLAGS+=	-DDEBUG
endif

ifdef OPT
CPPFLAGS+=	-O$(OPT)
endif

ifdef ASM
CPPFLAGS+=      -S
endif

ifdef PRE
CPPFLAGS+=      -E
endif

CFLAGS=	-g -Wall -Wstrict-prototypes -Wmissing-prototypes \
  -Wmissing-declarations $(CPPFLAGS)

CC=	$(TARGET)gcc
AS=	$(TARGET)as
LD=	$(TARGET)ld
AR=	$(TARGET)ar
RANLIB=	$(TARGET)ranlib
SIZE=	$(TARGET)size
RM=	rm -f

# a cross-assembler groking Intel syntax and MASM-style macros
KAS=	$(DOSWRAP) $(DOSAS)
KLD=	$(DOSWRAP) $(DOSLD)
DOSWRAP=dos
DOSAS=	386asm
DOSLD=	386link

#DOSAS=	masm
#DOSLD=	link

%.d:	%.c
	@echo building dependencies for $<
	@$(SHELL) -ec \
		'$(CC) -M $(CPPFLAGS) $< | sed '\''s,$*.o,& $@,g'\'' > $@'

%.d:	%.cc
	@echo building dependencies for $<
	@$(SHELL) -ec \
		'$(CC) -M $(CPPFLAGS) $< | sed '\''s,$*.o,& $@,g'\'' > $@'

%.o:	%.c
	$(CC) -c $(CFLAGS) $<

%.o:	%.S
	$(CC) -c $(CFLAGS) $<

%:	%.o 
	$(LD) -o $@ crt0.o $< 

