# Generated automatically from Makefile.in by configure.
#### Start of system configuration section. ####


srcdir =        .

ifeq ($(srcdir),.)
srcdir = ../..
endif

VPATH :=        $(srcdir)

# Common prefix for machine-independent installed files.
prefix =        /usr/local

# Common prefix for machine-dependent installed files.
exec_prefix =   ${prefix}

bindir =        $(exec_prefix)/bin
libdir =        $(exec_prefix)/Sys/libs

INSTALL =       /usr/bin/install -c
INSTALL_DATA =  ${INSTALL} -m 644

CC =            gcc

CFLAGS =        -O2
LDFLAGS =       

RANLIB =        ranlib
AR =            ar

NATIVE_CC =     gcc

NATIVE_CFLAGS = -O2
NATIVE_LDFLAGS= 

DO_CATENATE =   no

#### End system configuration section ####

# I *love* GNU make!
define catenate
/bin/echo -n creating $@...
/bin/echo "$(^:%=#include \"%\"\n)" >$@
/bin/echo done
endef

ifeq ($(BASE), morphos)
FLAVOR_CFLAGS = -mcpu=$(FPU)
FIXED_A4 = -ffixed-r13
OTHER_CFLAGS =
else
FLAVOR_CFLAGS = -m$(CPU) -m$(FPU)
OTHER_CFLAGS =  -fomit-frame-pointer
FIXED_A4 = -ffixed-a4
endif

ifeq ($(OS),pos)
ALL_CFLAGS =    $(CFLAGS) $(FLAVOR_CFLAGS) $(INCS) $(OTHER_CFLAGS) $(POS_CFLAGS) $(DEFS)
else
ALL_CFLAGS =    $(CFLAGS) $(FLAVOR_CFLAGS) $(INCS) $(OTHER_CFLAGS) $(DEFS)
endif

ifeq ($(OS),morphos)
NATIVE_FLAGS = $(NATIVE_CFLAGS) $(filter -DDEBUG_VERSION -DNOTRAP, $(ALL_CFLAGS)) -DNATIVE_MORPHOS -DCPU_$(FPU)
else
ifeq ($(FPU),soft-float)
NATIVE_FLAGS = $(NATIVE_CFLAGS) $(filter -DDEBUG_VERSION -DNOTRAP, $(ALL_CFLAGS)) -DCPU_$(CPU)
else
NATIVE_FLAGS = $(NATIVE_CFLAGS) $(filter -DDEBUG_VERSION -DNOTRAP, $(ALL_CFLAGS)) -DCPU_$(CPU) -DFPU_$(FPU)
endif
endif

INCS =          -I$(srcdir) -I$(srcdir)/../library -I$(srcdir)/../include -I.
DEFS =          -D__DBINTERFACE_PRIVATE
LIB =           libixnet.a
SHELL =         sh

# Strip the executable (-s), don't look for standard libraries (-nostdlib)
# don't link in crt0.o (-nostartfiles)
# link in some libc.a files (-L../../glue/no-baserel -lglue)
# need some stuff in libgeneral.a

ifeq ($(CPU),powerpc)
LINKFLAGS =     -nostdlib -nostartfiles -L/gg/ppc-morphos/lib/libnix/ -L../../../glue/morphos -L../../../db/morphos
else
LINKFLAGS =     -nostdlib -nostartfiles -L../../../glue/no-baserel -L../../../db/no-baserel
endif


.c.o:
		$(CC) $(ALL_CFLAGS) -c $< -o $@

ifeq ($(OS),pos)
all:
else
ifeq ($(OS),morphos)
all: ixnet.library
else
all: ixnet.library ixnet.debug
endif
endif

SRC_A4 =        set_errno.c siglaunch.c
SRC_MISC =      create_header.c parse_version.c start.c gates.c

SRC =           $(filter-out $(SRC_A4) $(SRC_MISC),$(notdir $(wildcard $(srcdir)/*.c)))

ifeq ($(OS),morphos)
OBJ_N =         start.o gates.o
else
OBJ_N =         start.o
endif

IXLIBS =        $(LIB)

ifeq ($(OS),morphos)
LIBS =          -lglue -lsyscall
else
LIBS =          -lglue
endif

ifeq ($(DO_CATENATE), yes)

$(LIB) :        a4.o az.o
		rm -f $@
		$(AR) rv $@ $^
		$(RANLIB) $@

a4.o:           a4.c
		$(CC) $(ALL_CFLAGS) $(FIXED_A4) -c $< -o $@

a4.c:           $(SRC_A4)
		@$(catenate)

az.c:           $(SRC)
		@$(catenate)

else

OBJS= $(SRC:.c=.o)
OBJS_A4= $(SRC_A4:.c=.o)

$(LIB):         $(OBJS_A4) $(OBJS)
		rm -f $@
		$(AR) rv $@ $^
		$(RANLIB) $@

$(OBJS_A4): %.o: %.c
		$(CC) $(ALL_CFLAGS) $(FIXED_A4) -c $< -o $@

endif

ixnet.library:  $(OBJ_N) $(IXLIBS)
		$(CC) $(LINKFLAGS) $(OBJ_N) $(IXLIBS) $(LIBS) -o $@

ixnet.debug:    $(OBJ_N) $(IXLIBS)
		$(CC) -g $(LINKFLAGS) $(OBJ_N) $(IXLIBS) $(LIBS) -o $@

clean:
		rm -rf 680?0 notrap powerpc
		rm -f create_header parse_version

clobber:        clean
		rm -f Makefile

ifeq ($(CPU),powerpc)

start.o:        $(srcdir)/start.c version.h $(srcdir)/../include/sys/ixnet_syscall.def ix_internals.h

else

start.o:        $(srcdir)/start.S version.h $(srcdir)/../include/sys/ixnet_syscall.def ix_internals.h
		$(CC) $(ALL_CFLAGS) -traditional -c $< -o $@

endif

ix_internals.h: create_header.o
		echo -e -n >$@ "/* This header has been generated by the create_header tool.\n   DO NOT EDIT! */\n\n"

		FOO=`ppc-morphos-objdump -D create_header.o | grep -A 1 MY_IXNETBASE_SIZEOF | tail -n 1 | sed "s/.*\.long //"`; echo -e -n >>$@ "#define IXNETBASE_SIZEOF (IXNETBASE_C_PRIVATE + $$FOO)\n"

create_header.o: create_header.c $(srcdir)/../include/user.h ixnet.h
		$(CC) $(ALL_CFLAGS) -c $< -o $@

parse_version:  parse_version.o
		$(NATIVE_CC) $(NATIVE_LDFLAGS) $< -o $@

parse_version.o:  parse_version.c
		$(NATIVE_CC) $(NATIVE_FLAGS) -c $< -o $@

version.h:      parse_version $(srcdir)/../version.in
		./parse_version $(srcdir) >$@

