mrc(1) | User Commands | mrc(1) |
mrc - A resource compiler
mrc [-o|--output outputfile]
[--root arg]
[--resource-prefix arg]
[--elf-machine arg]
[--elf-class arg]
[--elf-data arg]
[--elf-abi arg]
[--elf-flags arg]
file1 [file2...]
mrc [-h|--help]
mrc [-v|--version]
mrc [--header] > mrsrc.h
#include "mrsrc.h"
void foo()
{
mrsrc::rsrc data("/alerts/text.txt");
if (data) {
mrsrc::istream is(data);
...
}
}
Many applications come with supplementary data. This data is usually stored on disk as regular files. The disadvantage of this procedure is that an application cannot simply be copied to another location or computer and expected to function properly.
Resources are a way to overcome this problem by including all data inside the executable file. The mrc resource compiler can create object files containing both the data and an index. This data can then be accessed from within an application using C++ classes.
The machine flag is used to specify the value of the e_machine field in the ELF header.
Regular files are added in the root of the resource tree using their proper file name.
If the file name refers to a directory, the directory is traversed recursively and all files are added. If the file name ends with a forward slash (/) files are added to the root. If the file does not end with a slash, the name of the directory will be placed in the root and all contained files will be placed beneath this.
Here's a list of usage cases.
mrc -o x.o img Same as the previous, but note there's no trailing slash, the resource file will contain both images but they are now accessible under the name "/img/my-image-1.png" and "/img/my-image-1.png".
Use the verbose flag (--verbose) to track what ends up where.
The way this works is that mrc first collects all data from the files specified, including the files found in specified directories. An simple index is created to allow hierarchical access to the data. The data is then flattened into three data structures and these are written to the .data section of the object file. The three data blobs are then made available as globals in your application with the names gResourceIndex, gResourceName and gResourceData. You can specify the prefix part of this variable with the -fB--resource-prefix option.
The index entries have the following format:
struct rsrc_imp
{
unsigned int m_next; // index of the next sibling entry
unsigned int m_child; // index of the first child entry
unsigned int m_name; // offset of the name for this entry
unsigned int m_size; // data size for this entry
unsigned int m_data; // offset of the data for this entry
};
The classes in the mrsrc.h file are contained in the namespace mrsrc. The available classes are
This application can only generate ELF formatted object files on machines that have an <elf.h> header file installed.
Only a single resource entry can be generated and there's no way to merge or manipulate resource files yet.
2022-12-03 | version 1.3.6 |