Files
FreeRTOS/tools/memory_estimator/makefile_generator.py
Gaurav-Aggarwal-AWS 91068f0862 Add the memory estimator tool (#69)
* Add the memory estimator tool

This tool helps in determining the memory estimates for FreeRTOS
libraries.

Signed-off-by: Gaurav Aggarwal <aggarg@amazon.com>

* Address review feedback

1. Make the tool python3 compatible - The output read from a process is
bytes array and needs to be decoded as 'utf-8' before doing any string
like operations.
2. Make the script runnable from any directory.

Signed-off-by: Gaurav Aggarwal <aggarg@amazon.com>
2020-05-26 12:34:47 -07:00

28 lines
1.1 KiB
Python

def generate_makefile_from_template(source_files, include_dirs, optimization, template_file, output_file):
'''
source_files - A list containing all source files.
include_dirs - A list containing all include directories.
optimization - Compiler optimization (O0, Os etc.).
template_file - Makefile template to use.
output_file - Generated Makefile path.
'''
formatted_source_files = 'SRCS=' + ' \\\n'.join(source_files)
formatted_source_files += '\n'
formatted_include_dirs=''
for include_dir in include_dirs:
formatted_include_dirs += 'INCLUDE_DIRS+=-I ' + include_dir + '\n'
formatted_include_dirs += '\n'
with open(template_file, 'r') as f:
makefile_content = f.read()
makefile_content = makefile_content.replace('SOURCE_FILES', formatted_source_files)
makefile_content = makefile_content.replace('INCLUDE_DIRECTORIES', formatted_include_dirs)
makefile_content = makefile_content.replace('OPTIMIZATION', optimization)
with open(output_file, 'w') as f:
f.write(makefile_content)