### ==========================================================================
###  $Id: Makefile.user,v 1.9 2003/02/14 05:48:49 stephmo Exp $
###  FILE: Makefile.user - support for building programs run under brickOS
###  brickOS - the independent LEGO Mindstorms OS
### --------------------------------------------------------------------------
###       (this file is included by the  demo/ and demo/c++  Makefiles)


#  User application libraries. Comment out if linking
#  them statically to kernel in Makefile.kernel.
LIBS = -lc -lmint -lfloat -lc++

#  Linker command files dynamic executables.
DYNAMIC_LDS = $(KERNEL).lds
DLDFLAGS    = -T $(DYNAMIC_LDS) -relax -L$(BRICKOS_ROOT)/lib

#  Base addresses to determine relocation info.
BASE1 = 0xb000
BASE2 = 0xb210

# Add config.h to include path
CINC += -I$(BRICKOS_ROOT)/boot

#  Allow setting LNP Host Address on command line
ifdef LNP_HOSTADDR
CDEFINES = -DCONF_LNP_HOSTADDR=$(LNP_HOSTADDR)
endif

############ new dynamic executables stuff

#  How to build executables dynamically linked to the kernel 
#  Set DYNAMIC_TEXT, DOBJECTS, DYNAMIC_LDS appropriately.
%.dcoff: %.o $(DOBJECTS) $(DYNAMIC_LDS)
	$(LD) $(DLDFLAGS) $*.o $(DOBJECTS) $(LIBS) -o $@ -Ttext $(BASE1) --oformat coff-h8300

#  How to make barebones dymanic executable map files
%.dmap: %.dcoff
	$(NM) $< | sort > $@
	
#  How to disassemble coff kernel
%.dis: %.dcoff
	$(OBJDUMP) $(ODFLAGS) $*.dcoff > $@
	
#  How to merge map files with symbols
%.dis2: %.dmap %.dis
	$(MERGEMAP) $*.dmap $*.dis > $@
        
#  How to make coff files of dynamic executables (twice, for makelx)
%.dc1: %.o $(DOBJECTS) $(DYNAMIC_LDS)
	$(LD) $(DLDFLAGS) $*.o $(DOBJECTS) $(LIBS) -o $@ --oformat coff-h8300 -Ttext $(BASE1)

%.dc2: %.o $(DOBJECTS) $(DYNAMIC_LDS)	
	$(LD) $(DLDFLAGS) $*.o $(DOBJECTS) $(LIBS) -o $@ --oformat coff-h8300 -Ttext $(BASE2)

#  How to make srec files from coff files (twice, for makelx)
%.ds2: %.dc2
	$(OBJCOPY) -I coff-h8300 -O symbolsrec $< $@

%.ds1: %.dc1
	$(OBJCOPY) -I coff-h8300 -O symbolsrec $< $@

%.lx: %.ds1 %.ds2
	$(MAKELX) $*.ds1 $*.ds2 $@


### --------------------------------------------------------------------------
###                          End of FILE: Makefile.user
### ==========================================================================
