2007-12-29 02:05:26 +01:00
|
|
|
############################################################################
|
|
|
|
# arch/z80/src/Makefile
|
|
|
|
#
|
|
|
|
# Copyright (C) 2007, 2008 Gregory Nutt. All rights reserved.
|
|
|
|
# Author: Gregory Nutt <spudmonkey@racsa.co.cr>
|
|
|
|
#
|
|
|
|
# Redistribution and use in source and binary forms, with or without
|
|
|
|
# modification, are permitted provided that the following conditions
|
|
|
|
# are met:
|
|
|
|
#
|
|
|
|
# 1. Redistributions of source code must retain the above copyright
|
|
|
|
# notice, this list of conditions and the following disclaimer.
|
|
|
|
# 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
# notice, this list of conditions and the following disclaimer in
|
|
|
|
# the documentation and/or other materials provided with the
|
|
|
|
# distribution.
|
|
|
|
# 3. Neither the name NuttX nor the names of its contributors may be
|
|
|
|
# used to endorse or promote products derived from this software
|
|
|
|
# without specific prior written permission.
|
|
|
|
#
|
|
|
|
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
|
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
|
|
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
|
|
|
# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
|
|
|
# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
|
|
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
|
|
|
# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
|
|
|
# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
|
|
|
# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
|
|
|
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
|
|
# POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
#
|
|
|
|
############################################################################
|
|
|
|
|
|
|
|
############################################################################
|
|
|
|
# Makefile fragments
|
|
|
|
|
|
|
|
-include $(TOPDIR)/Make.defs
|
|
|
|
-include chip/Make.defs
|
|
|
|
|
|
|
|
############################################################################
|
|
|
|
# Tools
|
|
|
|
|
|
|
|
MKDEP = $(TOPDIR)/tools/mkdeps.sh
|
|
|
|
|
2007-12-29 17:31:25 +01:00
|
|
|
# CFLAGS, CPPFLAGS, ASFLAGS, LDFLAGS are set in $(TOPDIR)/Make.defs
|
2007-12-29 02:05:26 +01:00
|
|
|
|
2007-12-29 17:31:25 +01:00
|
|
|
CFLAGS += -I$(ARCH_SRCDIR)/chip -I$(ARCH_SRCDIR)/common -I$(TOPDIR)/sched
|
|
|
|
CPPFLAGS += -D__ASSEMBLY__
|
2007-12-29 02:05:26 +01:00
|
|
|
|
|
|
|
############################################################################
|
|
|
|
# Files and directories
|
|
|
|
|
|
|
|
# There should be one head source (.asm file)
|
|
|
|
|
|
|
|
HEAD_AOBJ = $(HEAD_ASRC:$(ASMEXT)=$(OBJEXT))
|
|
|
|
|
|
|
|
# Assembly sources and objects
|
|
|
|
|
|
|
|
ASRCS = $(CHIP_ASRCS) $(CMN_ASRCS)
|
2007-12-29 17:31:25 +01:00
|
|
|
AOBJS = $(ASRCS:$(ASMEXT)=$(OBJEXT))
|
2007-12-29 02:05:26 +01:00
|
|
|
|
|
|
|
# C sources and objects
|
|
|
|
|
|
|
|
CSRCS = $(CHIP_CSRCS) $(CMN_CSRCS)
|
|
|
|
COBJS = $(CSRCS:.c=$(OBJEXT))
|
|
|
|
|
|
|
|
# All sources and objcts
|
|
|
|
|
|
|
|
SRCS = $(ASRCS) $(CSRCS)
|
|
|
|
OBJS = $(AOBJS) $(COBJS)
|
|
|
|
|
|
|
|
# Sources that can have dependencies (no .asm files)
|
|
|
|
|
2007-12-29 17:31:25 +01:00
|
|
|
DEPSRCS = $(CSRCS)
|
2007-12-29 02:05:26 +01:00
|
|
|
|
|
|
|
# Directories
|
|
|
|
|
|
|
|
ARCH_SRCDIR = $(TOPDIR)/arch/$(CONFIG_ARCH)/src
|
|
|
|
BOARDDIR = $(TOPDIR)/arch/$(CONFIG_ARCH)/src/board
|
|
|
|
|
|
|
|
VPATH = chip:common
|
|
|
|
|
|
|
|
# Libraries
|
|
|
|
|
|
|
|
LIBGCC = ${shell $(CC) -print-libgcc-file-name}
|
|
|
|
|
2007-12-29 21:18:34 +01:00
|
|
|
# Supports dynamic sizing of HEAP. This adds up the size of each memory area.
|
|
|
|
# This does not account for the alignment of the _CODE area to 0x0100 (hence
|
|
|
|
# the fudge factor 196 is added).
|
2007-12-29 02:05:26 +01:00
|
|
|
|
|
|
|
HEAP_BASE = ${shell \
|
2007-12-29 20:51:39 +01:00
|
|
|
if [ -e pass1.map ]; then \
|
|
|
|
list=`cat pass1.map | grep "SIZE" | sed -e "s/\t//g" | cut -d' ' -f2`; \
|
|
|
|
unset result; \
|
|
|
|
first=yes; \
|
|
|
|
for size in $${list}; do \
|
|
|
|
if [ "$${size}" != "0000" ]; then \
|
|
|
|
if [ -z "$$first" ]; then \
|
|
|
|
result="$${result} + 0x$${size}"; \
|
|
|
|
else \
|
|
|
|
result="(0x$${size}"; \
|
|
|
|
unset first; \
|
|
|
|
fi; \
|
|
|
|
fi; \
|
|
|
|
done; \
|
2007-12-29 21:18:34 +01:00
|
|
|
echo "$${result} + 196)"; \
|
2007-12-29 20:51:39 +01:00
|
|
|
else \
|
|
|
|
echo "(UP_HEAP1_END - 8192)"; \
|
|
|
|
fi; \
|
|
|
|
}
|
2007-12-29 02:05:26 +01:00
|
|
|
|
|
|
|
############################################################################
|
|
|
|
# Targets
|
|
|
|
|
|
|
|
all: $(HEAD_AOBJ) libarch$(LIBEXT)
|
|
|
|
|
2007-12-29 17:31:25 +01:00
|
|
|
$(AOBJS) $(HEAD_AOBJ): %$(OBJEXT): %$(ASMEXT)
|
2007-12-29 02:05:26 +01:00
|
|
|
$(AS) $(ASFLAGS) $@ $<
|
|
|
|
|
2007-12-29 17:31:25 +01:00
|
|
|
$(COBJS): %$(OBJEXT): %.c
|
2007-12-29 02:05:26 +01:00
|
|
|
$(CC) -c $(CFLAGS) $< -o $@
|
|
|
|
|
2007-12-29 17:31:25 +01:00
|
|
|
# This is a kludge to work around some conflicting symbols in libsdcc.liXqueb
|
|
|
|
|
|
|
|
$(SDCCLIBDIR)/myz80.lib: $(SDCCLIBDIR)/$(SDCCLIB)
|
|
|
|
@cat $(SDCCLIBDIR)/$(SDCCLIB) | \
|
2007-12-31 20:05:45 +01:00
|
|
|
grep -v alloc | grep -v free | grep -v printf | \
|
|
|
|
grep -v _str | grep -v _mem | grep -v crt0\.o \
|
2007-12-29 17:31:25 +01:00
|
|
|
> myz80.lib
|
|
|
|
@sudo mv -f myz80.lib $(SDCCLIBDIR)/myz80.lib
|
|
|
|
|
2007-12-29 02:05:26 +01:00
|
|
|
# Create a header file that contains addressing information needed by the code
|
|
|
|
|
2007-12-29 20:51:39 +01:00
|
|
|
up_mem.h:
|
2007-12-29 02:05:26 +01:00
|
|
|
@echo "#ifndef __ARCH_MEM_H" >up_mem.h
|
|
|
|
@echo "#define __ARCH_MEM_H" >>up_mem.h
|
|
|
|
@echo "" >>up_mem.h
|
2007-12-29 17:31:25 +01:00
|
|
|
@echo "#define UP_STACK_END $(CONFIG_DRAM_SIZE)" >> up_mem.h
|
|
|
|
@echo "#define UP_STACK_BASE (UP_STACK_END - $(CONFIG_PROC_STACK_SIZE))" >> up_mem.h
|
|
|
|
@echo "#define UP_HEAP1_END UP_STACK_BASE" >> up_mem.h
|
|
|
|
@echo "#define UP_HEAP1_BASE $(HEAP_BASE)" >> up_mem.h
|
2007-12-29 02:05:26 +01:00
|
|
|
@echo "" >>up_mem.h
|
|
|
|
@echo "#endif /* __ARCH_MEM_H */" >>up_mem.h
|
|
|
|
|
2007-12-29 20:51:39 +01:00
|
|
|
asm_mem.h:
|
2007-12-31 20:05:45 +01:00
|
|
|
@echo " UP_COMPILER_OTHER == 0" > asm_mem.h
|
|
|
|
@echo " UP_COMPILER_SDCC == 1" >> asm_mem.h
|
|
|
|
ifeq ($(CC),sdcc)
|
|
|
|
@echo " UP_COMPILER == 1" >> asm_mem.h
|
|
|
|
else
|
|
|
|
@echo " UP_COMPILER == 0" >> asm_mem.h
|
|
|
|
endif
|
2007-12-29 20:51:39 +01:00
|
|
|
@echo " UP_STACK_END == ($(CONFIG_DRAM_SIZE) - 1)" >> asm_mem.h
|
|
|
|
@echo " UP_STACK_BASE == (UP_STACK_END - $(CONFIG_PROC_STACK_SIZE))" >> asm_mem.h
|
|
|
|
@echo " UP_HEAP1_END == (UP_STACK_END - $(CONFIG_PROC_STACK_SIZE) - 1)" >> asm_mem.h
|
|
|
|
@echo " UP_HEAP1_BASE == $(HEAP_BASE)" >> asm_mem.h
|
|
|
|
|
2007-12-29 02:05:26 +01:00
|
|
|
# Combine all objects in this directory into a library
|
|
|
|
|
2007-12-29 20:51:39 +01:00
|
|
|
libarch$(LIBEXT): up_mem.h asm_mem.h $(OBJS)
|
2007-12-29 02:05:26 +01:00
|
|
|
@( for obj in $(OBJS) ; do \
|
|
|
|
$(AR) $@ $${obj} || \
|
|
|
|
{ echo "$(AR) $@ $${obj} FAILED!" ; exit 1 ; } ; \
|
|
|
|
done ; )
|
|
|
|
|
|
|
|
# This builds the libboard library in the board/ subdirectory
|
|
|
|
|
|
|
|
board/libboard$(LIBEXT):
|
|
|
|
$(MAKE) -C board TOPDIR=$(TOPDIR) libboard$(LIBEXT)
|
|
|
|
|
|
|
|
# This target builds the final executable
|
|
|
|
|
2007-12-29 20:51:39 +01:00
|
|
|
pass1.ihx: up_mem.h asm_mem.h $(SDCCLIBDIR)/myz80.lib $(HEAD_AOBJ) board/libboard$(LIBEXT)
|
2007-12-31 20:05:45 +01:00
|
|
|
@echo "--" >pass1.lnk # Non-interactive
|
|
|
|
@echo "-k $(BOARDDIR)" >>pass1.lnk # Path to board library
|
2007-12-29 17:31:25 +01:00
|
|
|
@echo "-k $(SDCCLIBDIR)" >>pass1.lnk # Path to SDCC z80 library
|
|
|
|
@echo "-l libboard$(LIBEXT)" >>pass1.lnk # Name of board library
|
|
|
|
@for LIB in $(LINKLIBS); do \
|
|
|
|
echo "-l $(TOPDIR)/$$LIB" >> pass1.lnk ;\
|
|
|
|
done
|
|
|
|
@echo "-l myz80.lib" >>pass1.lnk # Name of SDCC z80 library
|
2007-12-29 20:51:39 +01:00
|
|
|
@echo "-b START=0" >>pass1.lnk # Start of START area
|
|
|
|
@echo "-b _CODE=256" >>pass1.lnk # Start of _CODE area
|
2007-12-29 17:31:25 +01:00
|
|
|
@echo "-i" >>pass1.lnk # Intel hex format
|
2007-12-31 20:05:45 +01:00
|
|
|
@echo "-x" >>pass1.lnk # Hexadecimal
|
|
|
|
@echo "-m" >>pass1.lnk # Generate a map file
|
|
|
|
@echo "-j" >>pass1.lnk # Generate a symbol file
|
2007-12-29 17:31:25 +01:00
|
|
|
@echo "pass1.ihx" >>pass1.lnk # Path to head object
|
|
|
|
@echo "$(HEAD_AOBJ)" >>pass1.lnk # Path to head object
|
|
|
|
@echo "-e" >>pass1.lnk # End of script
|
|
|
|
$(LD) -f pass1.lnk
|
2007-12-29 20:51:39 +01:00
|
|
|
@rm -f up_mem.h asm_mem.h
|
|
|
|
@rm -f up_allocateheap$(OBJEXT) $(HEAD_AOBJ) libarch$(LIBEXT)
|
2007-12-29 02:05:26 +01:00
|
|
|
@$(MAKE) TOPDIR=$(TOPDIR) libarch$(LIBEXT)
|
2007-12-29 20:51:39 +01:00
|
|
|
@$(MAKE) TOPDIR=$(TOPDIR) $(HEAD_AOBJ)
|
2007-12-29 02:05:26 +01:00
|
|
|
|
2007-12-29 20:51:39 +01:00
|
|
|
nuttx.ihx: up_mem.h asm_mem.h $(SDCCLIBDIR)/myz80.lib $(HEAD_AOBJ) board/libboard$(LIBEXT)
|
2007-12-31 20:05:45 +01:00
|
|
|
@echo "--" >nuttx.lnk # Non-interactive
|
|
|
|
@echo "-k $(BOARDDIR)" >>nuttx.lnk # Path to board library
|
2007-12-29 17:31:25 +01:00
|
|
|
@echo "-k $(SDCCLIBDIR)" >>nuttx.lnk # Path to SDCC z80 library
|
|
|
|
@echo "-l libboard$(LIBEXT)" >>nuttx.lnk # Name of board library
|
|
|
|
@for LIB in $(LINKLIBS); do \
|
|
|
|
echo "-l $(TOPDIR)/$$LIB" >> nuttx.lnk ;\
|
|
|
|
done
|
|
|
|
@echo "-l myz80.lib" >>nuttx.lnk # Name of SDCC z80 library
|
2007-12-29 20:51:39 +01:00
|
|
|
@echo "-b START=0" >>nuttx.lnk # Start of START area
|
|
|
|
@echo "-b _CODE=256" >>nuttx.lnk # Start of _CODE area
|
2007-12-29 17:31:25 +01:00
|
|
|
@echo "-i" >>nuttx.lnk # Intel hex format
|
2007-12-31 20:05:45 +01:00
|
|
|
@echo "-x" >>nuttx.lnk # Hexadecimal
|
2007-12-29 20:51:39 +01:00
|
|
|
@echo "-m" >>nuttx.lnk # Generate a map file
|
|
|
|
@echo "-j" >>nuttx.lnk # Generate a symbol file
|
2007-12-29 17:31:25 +01:00
|
|
|
@echo "nuttx.ihx" >>nuttx.lnk # Path to head object
|
|
|
|
@echo "$(HEAD_AOBJ)" >>nuttx.lnk # Path to head object
|
|
|
|
@echo "-e" >>nuttx.lnk # End of script
|
|
|
|
$(LD) -f nuttx.lnk
|
2007-12-29 02:05:26 +01:00
|
|
|
|
|
|
|
nuttx$(EXEEXT): pass1.ihx nuttx.ihx
|
|
|
|
@rm -f pass1.*
|
|
|
|
packihx nuttx.ihx > $(TOPDIR)/nuttx$(EXEEXT)
|
|
|
|
@cp -f nuttx.map $(TOPDIR)/.
|
|
|
|
|
|
|
|
# Build dependencies
|
|
|
|
|
2007-12-29 20:51:39 +01:00
|
|
|
.depend: Makefile up_mem.h asm_mem.h chip/Make.defs $(DEPSRCS)
|
2007-12-29 02:05:26 +01:00
|
|
|
@if [ -e board/Makefile ]; then \
|
|
|
|
$(MAKE) -C board TOPDIR=$(TOPDIR) depend ; \
|
|
|
|
fi
|
2007-12-29 20:51:39 +01:00
|
|
|
$(MKDEP) --dep-path chip --dep-path common $(CC) -- $(CFLAGS) -- $(DEPSRCS) >Make.dep
|
2007-12-29 02:05:26 +01:00
|
|
|
@touch $@
|
|
|
|
|
|
|
|
depend: .depend
|
|
|
|
|
|
|
|
clean:
|
|
|
|
@if [ -e board/Makefile ]; then \
|
|
|
|
$(MAKE) -C board TOPDIR=$(TOPDIR) clean ; \
|
|
|
|
fi
|
2007-12-29 20:51:39 +01:00
|
|
|
rm -f libarch$(LIBEXT) up_mem.h asm_mem.h pass1.* nuttx.*
|
|
|
|
rm -f *.asm *.rel *.lst *.rst *.sym *.adb *.lnk *.map *.mem *.ihx *.hex
|
|
|
|
rm -f core *~ .*.swp *.swp
|
2007-12-29 02:05:26 +01:00
|
|
|
if [ ! -z "$(OBJEXT)" ]; then rm -f *$(OBJEXT); fi
|
|
|
|
|
|
|
|
distclean: clean
|
|
|
|
@if [ -e board/Makefile ]; then \
|
|
|
|
$(MAKE) -C board TOPDIR=$(TOPDIR) distclean ; \
|
|
|
|
fi
|
|
|
|
rm -f Make.dep .depend
|
|
|
|
|
|
|
|
-include Make.dep
|