mirror of https://gitlab.com/ita1024/waf.git
extras: add file_to_object tool
This commit is contained in:
parent
3e378c45bf
commit
a4d0442e45
|
@ -13,45 +13,22 @@ from waflib.TaskGen import feature, before_method
|
||||||
|
|
||||||
def options(opt):
|
def options(opt):
|
||||||
opt.load('compiler_c')
|
opt.load('compiler_c')
|
||||||
|
opt.load('file_to_object')
|
||||||
|
|
||||||
def configure(cfg):
|
def configure(cfg):
|
||||||
cfg.load('compiler_c')
|
cfg.load('compiler_c')
|
||||||
cfg.find_program('ld')
|
cfg.load('file_to_object')
|
||||||
|
|
||||||
class resource_ldr(Task.Task):
|
|
||||||
def run(tsk):
|
|
||||||
dst = tsk.outputs[0]
|
|
||||||
src = tsk.inputs[0]
|
|
||||||
cmd = tsk.env.LD + [
|
|
||||||
'-r',
|
|
||||||
'-b', 'binary',
|
|
||||||
'-o', dst.abspath(),
|
|
||||||
src.name,
|
|
||||||
]
|
|
||||||
tsk.exec_command(cmd, cwd=src.parent.abspath())
|
|
||||||
|
|
||||||
@feature('resource_embed')
|
|
||||||
@before_method('process_source')
|
|
||||||
def ld_binary(self):
|
|
||||||
src = self.path.find_resource(self.source)
|
|
||||||
dst = src.change_ext('.o')
|
|
||||||
tsk = self.create_task('resource_ldr', src, dst)
|
|
||||||
try:
|
|
||||||
self.compiled_tasks.append(tsk)
|
|
||||||
except AttributeError:
|
|
||||||
self.compiled_tasks = [tsk]
|
|
||||||
self.source = []
|
|
||||||
|
|
||||||
def build(bld):
|
def build(bld):
|
||||||
bld(
|
bld(
|
||||||
name='example',
|
name='example',
|
||||||
source='main.c',
|
source='main.c',
|
||||||
features='resource_embed',
|
features='file_to_object',
|
||||||
)
|
)
|
||||||
bld(
|
bld(
|
||||||
target = 'app',
|
target = 'app',
|
||||||
features = 'c cprogram',
|
features = 'c cprogram',
|
||||||
source = 'main.c',
|
source = 'main.c',
|
||||||
use='example',
|
use='example',
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,60 @@
|
||||||
|
#!/usr/bin/python
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
# Tool to embed file into objects
|
||||||
|
|
||||||
|
__author__ = __maintainer__ = "Jérôme Carretero <cJ-waf@zougloub.eu>"
|
||||||
|
__copyright__ = "Jérôme Carretero, 2014"
|
||||||
|
|
||||||
|
"""
|
||||||
|
|
||||||
|
This tool allows to embed file contents in object files (.o).
|
||||||
|
It is not exactly portable, and the file contents are reachable
|
||||||
|
using various non-portable fashions.
|
||||||
|
The goal here is to provide a functional interface to the embedding
|
||||||
|
of file data in objects.
|
||||||
|
See the ``playground/embedded_resources`` example for an example.
|
||||||
|
|
||||||
|
Usage::
|
||||||
|
|
||||||
|
bld(
|
||||||
|
name='pipeline',
|
||||||
|
# ^ Reference this in use="..." for things using the generated code
|
||||||
|
features='file_to_object',
|
||||||
|
source='some.file',
|
||||||
|
# ^ Name of the file to embed in binary section.
|
||||||
|
)
|
||||||
|
|
||||||
|
Known issues:
|
||||||
|
|
||||||
|
- Currently only handles elf files with GNU ld.
|
||||||
|
|
||||||
|
- Destination is named like source, with extension renamed to .o
|
||||||
|
eg. some.file -> some.o
|
||||||
|
|
||||||
|
"""
|
||||||
|
|
||||||
|
from waflib import Task, Utils, TaskGen
|
||||||
|
|
||||||
|
class file_to_object(Task.Task):
|
||||||
|
run_str = '${LD} -r -b binary -o ${TGT[0].abspath()} ${SRC[0].name}'
|
||||||
|
color = 'CYAN'
|
||||||
|
|
||||||
|
@TaskGen.feature('file_to_object')
|
||||||
|
@TaskGen.before_method('process_source')
|
||||||
|
def tg_file_to_object(self):
|
||||||
|
bld = self.bld
|
||||||
|
src = self.to_nodes(self.source)
|
||||||
|
assert len(src) == 1
|
||||||
|
src = src[0]
|
||||||
|
tgt = src.change_ext('.o')
|
||||||
|
task = self.create_task('file_to_object',
|
||||||
|
src, tgt, cwd=src.parent.abspath())
|
||||||
|
try:
|
||||||
|
self.compiled_tasks.append(task)
|
||||||
|
except AttributeError:
|
||||||
|
self.compiled_tasks = [task]
|
||||||
|
self.source = []
|
||||||
|
|
||||||
|
def configure(conf):
|
||||||
|
conf.load('gcc')
|
||||||
|
conf.env.LD = [ conf.env.CC[0].replace('gcc', 'ld') ]
|
Loading…
Reference in New Issue