aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/src/others/irrlicht-1.8.1/tools/FileToHeader
diff options
context:
space:
mode:
Diffstat (limited to 'src/others/irrlicht-1.8.1/tools/FileToHeader')
-rw-r--r--src/others/irrlicht-1.8.1/tools/FileToHeader/FileToHeader.cbp48
-rw-r--r--src/others/irrlicht-1.8.1/tools/FileToHeader/Makefile35
-rw-r--r--src/others/irrlicht-1.8.1/tools/FileToHeader/main.cpp175
3 files changed, 258 insertions, 0 deletions
diff --git a/src/others/irrlicht-1.8.1/tools/FileToHeader/FileToHeader.cbp b/src/others/irrlicht-1.8.1/tools/FileToHeader/FileToHeader.cbp
new file mode 100644
index 0000000..e6c1a2d
--- /dev/null
+++ b/src/others/irrlicht-1.8.1/tools/FileToHeader/FileToHeader.cbp
@@ -0,0 +1,48 @@
1<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
2<CodeBlocks_project_file>
3 <FileVersion major="1" minor="6" />
4 <Project>
5 <Option title="FileToHeader" />
6 <Option pch_mode="0" />
7 <Option compiler="gcc" />
8 <Build>
9 <Target title="Linux">
10 <Option platforms="Unix;" />
11 <Option output="..\..\bin\Linux\FileToHeader" prefix_auto="0" extension_auto="0" />
12 <Option type="1" />
13 <Option compiler="gcc" />
14 <Compiler>
15 <Add option="-g" />
16 <Add option="-D_IRR_STATIC_LIB_" />
17 </Compiler>
18 <Linker>
19 <Add directory="..\..\lib\Linux" />
20 </Linker>
21 </Target>
22 <Target title="Windows">
23 <Option platforms="Windows;" />
24 <Option output="..\..\bin\Win32-gcc\FileToHeader" prefix_auto="0" extension_auto="1" />
25 <Option type="1" />
26 <Option compiler="gcc" />
27 <Compiler>
28 <Add option="-g" />
29 </Compiler>
30 <Linker>
31 <Add directory="..\..\lib\Win32-gcc" />
32 </Linker>
33 </Target>
34 </Build>
35 <VirtualTargets>
36 <Add alias="All" targets="Windows;Linux;" />
37 </VirtualTargets>
38 <Compiler>
39 <Add option="-g" />
40 </Compiler>
41 <Unit filename="main.cpp" />
42 <Extensions>
43 <code_completion />
44 <debugger />
45 <envvars />
46 </Extensions>
47 </Project>
48</CodeBlocks_project_file>
diff --git a/src/others/irrlicht-1.8.1/tools/FileToHeader/Makefile b/src/others/irrlicht-1.8.1/tools/FileToHeader/Makefile
new file mode 100644
index 0000000..e9cd818
--- /dev/null
+++ b/src/others/irrlicht-1.8.1/tools/FileToHeader/Makefile
@@ -0,0 +1,35 @@
1# Makefile for FileToHeader
2Target = FileToHeader
3Sources = main.cpp
4
5# general compiler settings
6CPPFLAGS = -I../../include
7CXXFLAGS = -O3 -ffast-math -Wall
8#CXXFLAGS = -g -Wall
9
10#default target is Linux
11all: all_linux
12
13ifeq ($(HOSTTYPE), x86_64)
14LIBSELECT=64
15endif
16
17# target specific settings
18all_linux clean_linux: SYSTEM=Linux
19all_win32: LDFLAGS = -L../../lib/Win32-gcc
20all_win32 clean_win32: SYSTEM=Win32-gcc
21all_win32 clean_win32: SUF=.exe
22# name of the binary - only valid for targets which set SYSTEM
23DESTPATH = ../../bin/$(SYSTEM)/$(Target)$(SUF)
24
25all_linux all_win32:
26 $(warning Building...)
27 $(CXX) $(CPPFLAGS) $(CXXFLAGS) $(Sources) -o $(DESTPATH) $(LDFLAGS)
28
29clean: clean_linux clean_win32
30 $(warning Cleaning...)
31
32clean_linux clean_win32:
33 @$(RM) $(DESTPATH)
34
35.PHONY: all all_win32 clean clean_linux clean_win32
diff --git a/src/others/irrlicht-1.8.1/tools/FileToHeader/main.cpp b/src/others/irrlicht-1.8.1/tools/FileToHeader/main.cpp
new file mode 100644
index 0000000..b3cc7a7
--- /dev/null
+++ b/src/others/irrlicht-1.8.1/tools/FileToHeader/main.cpp
@@ -0,0 +1,175 @@
1// Copyright (C) 2012 Gaz Davidson
2// This file is part of the "Irrlicht Engine".
3// For conditions of distribution and use, see copyright notice in irrlicht.h
4
5/***
6 This tool creates a .h file from a given input file by encoding it into a C string,
7 allowing you to build your resources directly into your binaries, just like Irrlicht's
8 built-in font.
9
10 To distribute your app as a single executable file of minimal size:
11
12 1. Put all your resources into a single directory and add it to Irrlicht's filesystem
13 as a folder through IFileSystem::addArchive. Develop and test your app as usual.
14 2. Open IrrCompileConfig.h and comment out all the options that your app does not use.
15 This will reduce the size of the Irrlicht library considerably.
16 * You should remove the D3D video drivers, because they rely on external DLLs.
17 * You should keep either the TAR or ZIP archive loader, used in step 6.
18 * If you remove the JPEG loader, you don't have to say you use JPEG code in your
19 documentation.
20 3. Recompile Irrlicht as a static library, editing the IRR_STATIC_LIB line in
21 IrrCompileConfig.h.
22 The next time you compile your application it will take a while longer, but
23 Irrlicht will be built into your binary.
24 4. TAR or ZIP your resource directory using your favourite archiving tool (ie 7zip).
25 * If you chose ZIP but compiled without zlib, don't compress this archive or it
26 won't open.
27 5. Run this tool to convert your resource file into a .h file, like so:
28 FileToHeader res.zip > EmbeddedResources.h
29 6. Add the .h file to your project, create the embedded read file then mount as a
30 ZIP or TAR archive instead of the folder, like so:
31 io::IReadFile *f = io::createEmbeddedFile(device->getFileSystem(), "res.zip");
32 device->getFileSystem()->addFileArchive(f);
33 archive->drop();
34 7. Recompile your app.
35 * If you use Microsoft's compiler, make sure your CRT (common run-time) is
36 the static library version, otherwise you'll have a dependency on the CRT DLLs.
37 Your binary should now be completely portable; you can distribute just the exe file.
38 8. Optional: Use UPX (upx.sf.net) to compress your binary.
39*/
40
41#include <iostream>
42#include <fstream>
43#include <sstream>
44
45using namespace std;
46
47int main(int argc, char* argv[])
48{
49 if (argc < 2)
50 {
51 // print usage
52 cerr << "You must to specify at least one input file" << endl;
53 cerr << "usage: " << argv[0] << "<file1> [file2...]" << endl;
54 cerr << "outputs a header file to stdout, so for example use";
55 return 1;
56 }
57
58 int i = 1;
59
60 // write file header
61 cout << "// File made by FileToHeader, part of the Irrlicht Engine" << endl
62 << endl
63 << "#ifndef _EMBEDDED_FILES_H_INCLUDED_" << endl
64 << "#define _EMBEDDED_FILES_H_INCLUDED_" << endl
65 << endl
66 << "#include \"irrTypes.h\"" << endl
67 << "#include \"IReadFile.h\"" << endl
68 << "#include \"IFileSystem.h\"" << endl
69 << endl
70 << "namespace irr" << endl
71 << "{" << endl
72 << "namespace io" << endl
73 << "{" << endl
74 << endl
75 << " const c8* EmbeddedFileData[] = " << endl
76 << " {" << endl;
77
78 // store sizes and file names
79 stringstream sizes;
80 stringstream names;
81 sizes << "const u32 EmbeddedFileSizes[] = {";
82 names << "const c8* EmbeddedFileNames[] = {";
83 int fileCount = 0;
84
85 // char to hex digit table, probably doesn't help for speed due to fstream. better than using sprintf though
86 char hextable[16] = {'0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f'};
87
88 while (i < argc)
89 {
90 // open and seek to end of file
91 ifstream input;
92 input.open(argv[i], ios::in | ios::binary | ios::ate);
93
94 if (input.is_open())
95 {
96 int size = input.tellg();
97 input.seekg(0, ios::beg);
98 // read the file into RAM
99 char *entireFile = new char[size];
100 input.read(entireFile, size);
101
102 if (fileCount)
103 {
104 sizes << ", ";
105 names << ", ";
106 cout << "," << endl;
107 }
108
109 // save file size and name
110 sizes << size;
111 names << '"' << argv[i] << '"';
112
113 // write the file data
114 cout << " \"";
115 for (int count=0; count < size; ++count)
116 {
117 if (count && (count % 16) == 0)
118 cout << "\"" << endl << " \"";
119
120 cout << "\\x" << hextable[(entireFile[count] >> 4) & 0xF] << hextable[entireFile[count] & 0x0F];
121 }
122 cout << "\"";
123
124 delete [] entireFile;
125 //
126 input.close();
127
128 fileCount++;
129 }
130 else
131 {
132 cerr << "Failed to open file: " << argv[i] << endl;
133 }
134
135 ++i;
136 }
137
138 // close binary file list and write file metadata
139 cout << endl
140 << " , 0};" << endl
141 << endl
142 << " const u32 EmbeddedFileCount = " << fileCount << ";" << endl
143 << " " << sizes.str() << "};" << endl
144 << " " << names.str() << "};" << endl
145 << endl;
146
147 // write functions to create embedded IReadFiles
148 cout << " IReadFile* createEmbeddedFile(IFileSystem *fs, u32 index)" << endl
149 << " {" << endl
150 << " if (EmbeddedFileCount < index)" << endl
151 << " return 0;" << endl
152 << endl
153 << " return fs->createMemoryReadFile((void*)EmbeddedFileData[index], " << endl
154 << " EmbeddedFileSizes[index], EmbeddedFileNames[index]);" << endl
155 << " }" << endl
156 << endl
157 << " IReadFile* createEmbeddedFile(IFileSystem *fs, path filename)" << endl
158 << " {" << endl
159 << " for (u32 i=0; i < EmbeddedFileCount; ++i)" << endl
160 << " if (filename == EmbeddedFileNames[i])" << endl
161 << " return createEmbeddedFile(fs, i);" << endl
162 << endl
163 << " return 0;" << endl
164 << " }" << endl
165 << endl;
166
167 // write footer
168 cout << "} // namespace io" << endl
169 << "} // namespace irr" << endl
170 << endl
171 << "#endif // _EMBEDDED_FILES_H_INCLUDED_" << endl;
172
173 return 0;
174}
175