#############################################################
# (c) 2021 Aaron Taylor <ataylor at subgeniuskitty dot com> #
# See LICENSE.txt file for copyright and license details. #
#############################################################
################################################################################
################################################################################
# To keep the rules simple, since we are dealing with six different file
# extensions, NED_EMBED is defined with no suffix, leaving the suffix to be
# hardcoded in each step as appropriate and simplying the make target list.
NED_EMBED
:= $(NED_SRC
:.ned_asm
=)
# This header file will contain C declarations for the binary blobs and a
# variable which tracks their size. It should be included in any C source code
# that will link against the object files containing the binary blobs.
DECLARATION_HEADER_FILE
= embedded_ned_program_declarations.h
# Misc program names/paths.
NED_OBJDUMP
= ned1objdump
################################################################################
################################################################################
# Since nedasm and nedobjcopy do not overwrite existing files, include target
# Build an #include guard around the C declarations of the binary blobs.
@mv
$(DECLARATION_HEADER_FILE
) $(DECLARATION_HEADER_FILE
).tempfile
@echo
"/* Autogenerated code. Do not edit. */" >> $(DECLARATION_HEADER_FILE
)
@echo
"#ifndef NEDSIM_AUTOGEN_BLOB_DECLARATIONS" >> $(DECLARATION_HEADER_FILE
)
@echo
"#define NEDSIM_AUTOGEN_BLOB_DECLARATIONS" >> $(DECLARATION_HEADER_FILE
)
@cat
$(DECLARATION_HEADER_FILE
).tempfile
>> $(DECLARATION_HEADER_FILE
)
@
rm $(DECLARATION_HEADER_FILE
).tempfile
@echo
"#endif" >> $(DECLARATION_HEADER_FILE
)
# We assemble the NED source and then dump the executable code section of
# the resulting a.out file as a binary blob.
@
$(NED_ASM
) -i
$*.ned_asm
-o
$*.out
@
$(NED_OBJDUMP
) -i
$*.out
-o
$*.bin
# Using `sed`, prepare an x86 assembly file as a container for each NED
# binary blob. This includes building a C header file with relevant
# declarations for each binary blob.
@sed
's/INSERTNAME/$*/g' container.x86_asm_template
> $*.x86_asm
@echo
"extern const uint8_t $*[];" >> $(DECLARATION_HEADER_FILE
)
@echo
"extern const size_t $*_size;" >> $(DECLARATION_HEADER_FILE
)
# Assemble the container, creating a linkable object file containing the
@
$(GNU_ASM
) -o
$*.o
$*.x86_asm
@
rm -f
$*.bin
$*.x86_asm
$*.out
@
rm -f
*.bin
*.x86_asm
*.out
*.o
$(DECLARATION_HEADER_FILE
)*