CPPFLAGS += -DGM_OS_VXWORKS=1 -DVXWORKS=1 -DMT_ppc_vxWorks -DINSIST -fsigned-char
MATH_LIBRARY =
 
DRIVER_CPPFLAGS = $(KERN_CPPFLAGS) -DGM_KERNEL \
         -I$(top_srcdir)/zlib \
	 -I$(srcdir) -I$(top_srcdir)/drivers \
	 -I$(top_builddir)/include -I$(top_srcdir)/include \
	 -I$(top_srcdir)/drivers/vxworks/gm \
	 -I$(top_srcdir)/drivers/vxworks/gm_end \
	 -DGM_CPU_$(target_cpu)=1
DRIVER_CFLAGS = $(NOFPREGS) $(KERN_CFLAGS) $(DRIVER_CPPFLAGS)

EXTRA_USER_LDFLAGS = -r -nostdlib

#override the standard gm Makefile variables to not include -lgm on vxworks
TEST_LDFLAGS = -Llibgm -Lbinary/lib $(LDFLAGS) $(EXTRA_USER_LDFLAGS) $(LIBS)
MAPPER_LDFLAGS =  -Llibgm -Lbinary/lib $(LDFLAGS) $(EXTRA_USER_LDFLAGS) $(LIBS)

MAPPER_CXXLDFLAGS = 

#$(MAPPER): $(MAPPER_OBJS) binary/lib/libgm.a
#	$(CXX) -o $(MAPPER) $(MAPPER_OBJS) $(MAPPER_LDFLAGS)

# Explicit rule to use C++ to build the mapper.
mt/tools/mapper.o: $(srcdir)/mt/tools/vx_mapper.c
	$(CXX) -c $(MAPPER_CXXFLAGS) $< -o $@


#############
# Building
#############

release: binary/sbin/gm binary/GM_INSTALL binary/README binary/README-vxworks

#Note: must use += to not replace the generic gm driver code
DRIVER_SRCS += drivers/vxworks/gm/gm_arch.c  drivers/vxworks/gm_end/ge.c

DRIVER_OBJECTS = $(DRIVER_SRCS:.c=_k.o) $(GM_MCP_OBJS)

$(DRIVER_OBJECTS): vxworks-builddirs

vxworks-builddirs:
	if [ ! -d drivers ]; then mkdir drivers; fi
	if [ ! -d drivers/vxworks ]; then mkdir drivers/vxworks; fi
	if [ ! -d drivers/vxworks/gm ]; then mkdir drivers/vxworks/gm; fi
	if [ ! -d drivers/vxworks/gm_end ]; then mkdir drivers/vxworks/gm_end; fi
	echo timestamp > vxworks-builddirs

DRIVER_LIBS = 					\
	libgm/libgm_k.a				\
	zlib/libz.a

binary/sbin/gm: $(DRIVER_OBJECTS) $(DRIVER_LIBS) installdirs
	ld -dc -whole-archive -r -o $@ $(DRIVER_OBJECTS) $(DRIVER_LIBS)
#	$(STRIP) --strip-debug binary/sbin/gm

binary/GM_INSTALL: drivers/vxworks/gm_install installdirs
	$(INSTALL_PROGRAM) $(srcdir)/drivers/vxworks/gm_install binary/GM_INSTALL

binary/README: README installdirs
	$(INSTALL_PROGRAM) $(srcdir)/README binary/README

binary/README-vxworks: README-vxworks installdirs
	$(INSTALL_PROGRAM) $(srcdir)/README-vxworks binary/README-vxworks

#############
# Executables
#############

binary/lib/libgm.a: libgm/libgm_k.a installdirs
	-rm -f binary/lib/libgm.a
	$(INSTALL_PROGRAM) libgm/libgm_k.a binary/lib/libgm.a

mostlyclean: drivers/vxworks/mostlyclean
drivers/vxworks/mostlyclean: force
	-rm -f drivers/vxworks/gm/*.o
	-rm -f drivers/vxworks/gm_end/*.o

driver_tags: force
	cd $(srcdir) && etags --append drivers/vxworks/gm/*.[ch]






