Fixed minor typo in Makefile comment.
[screensavers] / hacks / NEDsim / ned_programs / Makefile
CommitLineData
b73247cf
AT
1#############################################################
2# (c) 2021 Aaron Taylor <ataylor at subgeniuskitty dot com> #
3# See LICENSE.txt file for copyright and license details. #
4#############################################################
5
6################################################################################
7# Configuration
8################################################################################
9
10# To keep the rules simple, since we are dealing with six different file
11# extensions, NED_EMBED is defined with no suffix, leaving the suffix to be
ab051153 12# hardcoded in each step as appropriate and simplifying the make target list.
b73247cf
AT
13.SUFFIXES: .ned_asm
14NED_SRC != ls *.ned_asm
15NED_EMBED := $(NED_SRC:.ned_asm=)
16
17# This header file will contain C declarations for the binary blobs and a
18# variable which tracks their size. It should be included in any C source code
19# that will link against the object files containing the binary blobs.
20DECLARATION_HEADER_FILE = embedded_ned_program_declarations.h
21
22# Misc program names/paths.
23GNU_ASM = as
24NED_ASM = ned1asm
25NED_OBJDUMP = ned1objdump
26
27################################################################################
28# Targets
29################################################################################
30
31# Since nedasm and nedobjcopy do not overwrite existing files, include target
32# `clean` as a preq.
33all: clean $(NED_EMBED)
1da913bb 34 # Build an #include guard around the C declarations of the binary blobs.
b73247cf
AT
35 @mv $(DECLARATION_HEADER_FILE) $(DECLARATION_HEADER_FILE).tempfile
36 @echo "/* Autogenerated code. Do not edit. */" >> $(DECLARATION_HEADER_FILE)
37 @echo "#ifndef NEDSIM_AUTOGEN_BLOB_DECLARATIONS" >> $(DECLARATION_HEADER_FILE)
38 @echo "#define NEDSIM_AUTOGEN_BLOB_DECLARATIONS" >> $(DECLARATION_HEADER_FILE)
39 @cat $(DECLARATION_HEADER_FILE).tempfile >> $(DECLARATION_HEADER_FILE)
40 @rm $(DECLARATION_HEADER_FILE).tempfile
41 @echo "#endif" >> $(DECLARATION_HEADER_FILE)
42
43.ned_asm:
44 # We assemble the NED source and then dump the executable code section of
45 # the resulting a.out file as a binary blob.
46 @$(NED_ASM) -i $*.ned_asm -o $*.out
47 @$(NED_OBJDUMP) -i $*.out -o $*.bin
48 # Using `sed`, prepare an x86 assembly file as a container for each NED
49 # binary blob. This includes building a C header file with relevant
50 # declarations for each binary blob.
51 @sed 's/INSERTNAME/$*/g' container.x86_asm_template > $*.x86_asm
52 @echo "extern const uint8_t $*[];" >> $(DECLARATION_HEADER_FILE)
53 @echo "extern const size_t $*_size;" >> $(DECLARATION_HEADER_FILE)
54 # Assemble the container, creating a linkable object file containing the
55 # NED binary blob.
56 @$(GNU_ASM) -o $*.o $*.x86_asm
57 @rm -f $*.bin $*.x86_asm $*.out
58
59clean:
60 @rm -f *.bin *.x86_asm *.out *.o $(DECLARATION_HEADER_FILE)*
61