Hardcodian is a simple bash script that let you compile all your software resources (images, sounds, texts, etc) in a static library that can be linked in your software.
Hardcodian also generates a C++ class that managed the linked resources in a simple way.
Hardcodian works under bash consoles with commands sed and awk.
It also need GCC to make the resources library.
It has been tested under Linux and Windows (Mingw + MSYS) systems.
Hardcodian is based on two files:
hardcodian.sh -> The bash script.
resources.template -> The text template used to make resources.h.
Invoking hardcodian look like this:
*** ./hardcodian.sh myResources/***
Where myResources/ is the folder you want to compile. It can contains other folders and files.
As output you get two files:
libResources.a -> A linkable static library.
resources.h -> A C++ class that managed your embedded resources.
Then you need to include the file resources.h in your C++ code and configure your compiler to link libResources.a
The generated Resources class is based in a singleton pattern, so after include it, you shoud get its reference using getRef() method.
resources.h looks like this:
/*
* resources.h
*
* Created on: 12/12/2012
* Author: ccortiz
*/
#ifndef RESOURCES_H_
#define RESOURCES_H_
#include <map>
#include <iostream>
extern char binary___resources_myRes1_start[];
extern char binary___resources_myRes2_start[];
extern char binary___resources_myRes3_start[];
extern int binary____resources_myRes1_size[];
extern int binary____resources_myRes2_size[];
extern int binary____resources_myRes3_size[];
class Resources{
public:
static Resources* getRef(){
static Resources* instance = new Resources();
return instance;
}
std::map<std::string, std::pair<char*, int> > resourceMap;
private:
Resources(){
resourceMap["/resources/myRes1"] = std::make_pair(binary___resources_myRes1_start, (long)binary____resources_myRes1_size);
resourceMap["/resources/myRes2"] = std::make_pair(binary___resources_myRes2_start, (long)binary____resources_myRes2_size);
resourceMap["/resources/myRes3"] = std::make_pair(binary___resources_myRes3_start, (long)binary____resources_myRes3_size);
}
};
#endif /* RESOURCES_H_ */
Of course. At beginning of harcodian.sh there is an enviroment var called LINKER that you can modify to use your favorite linker.
By default it uses ld, but we have tested other gcc-based toolchains and works well.
What? Aaagg :|
If you test Hardcodian and detect a bug, please send me a mail and I will try to fix it.
Thanks!