6 // Bootstrap for themes.
8 // By default, concatenates all the resources and a table of contents
9 // into an object file with objcopy.
11 // Run nm <object> to get the symbols created by bootstrap.
13 // The user must make extern variable declarations like
14 // extern unsigned char _binary_myobject_data_start[];
15 // and link the object to get at the symbols.
17 // Pass the symbol like
18 // _binary_destname_o_start
19 // to BC_Theme::set_data to set an image table for a theme.
22 // Because of the need for runtime compilation of source files for OpenGL,
23 // it now supports loading a single resource and omitting the table of contents.
28 // Usage: bootstrap <dest object> <resource> * n
33 void append_contents(char *path,
41 for(i = strlen(path) - 1;
42 i > 0 && path[i] && path[i] != '/';
46 if(path[i] == '/') i++;
48 for(j = 0; path[i] != 0; i++, j++)
53 strcpy(buffer + *buffer_size, string);
55 *buffer_size += strlen(string) + 1;
57 *(int*)(buffer + *buffer_size) = data_offset;
58 *buffer_size += sizeof(int);
61 int main(int argc, char *argv[])
66 char *contents_buffer;
67 int contents_size = 0;
74 char system_command[1024];
81 fprintf(stderr, "Usage: bootstrap [-b] <dest object> <resource> * n\n");
82 fprintf(stderr, "-b - omit table of contents just store resource.\n");
83 fprintf(stderr, "-s - omit table of contents but append 0 to resource.\n");
87 if(!strcmp(argv[current_arg], "-b"))
93 if(!strcmp(argv[current_arg], "-s"))
99 // Make object filename
100 strcpy(temp_path, argv[current_arg]);
101 strcpy(out_path, argv[current_arg++]);
102 ptr = strchr(temp_path, '.');
109 fprintf(stderr, "Dest path must end in .o\n");
113 if(!(dest = fopen(temp_path, "w")))
115 fprintf(stderr, "Couldn't open dest file %s. %s\n",
121 if(!(data_buffer = malloc(0x1000000)))
123 fprintf(stderr, "Not enough memory to allocate data buffer.\n");
127 if(!(contents_buffer = malloc(0x100000)))
129 fprintf(stderr, "Not enough memory to allocate contents buffer.\n");
133 // Leave space for offset to data
134 contents_size = sizeof(int);
136 // Read through all the resources, concatenate to dest file,
137 // and record the contents.
138 while(current_arg < argc)
140 char *path = argv[current_arg++];
141 if(!(src = fopen(path, "r")))
143 fprintf(stderr, "%s while opening %s\n", strerror(errno), path);
148 fseek(src, 0, SEEK_END);
150 fseek(src, 0, SEEK_SET);
152 data_offset = data_size;
154 if(!binary_mode && !string_mode)
156 // Write size of image in data buffer
157 *(data_buffer + data_size) = (size & 0xff000000) >> 24;
159 *(data_buffer + data_size) = (size & 0xff0000) >> 16;
161 *(data_buffer + data_size) = (size & 0xff00) >> 8;
163 *(data_buffer + data_size) = size & 0xff;
167 int temp = fread(data_buffer + data_size, 1, size, src);
170 if(string_mode) data_buffer[data_size++] = 0;
173 if(!binary_mode && !string_mode)
176 append_contents(path,
184 if(!binary_mode && !string_mode)
186 // Finish off size of contents
187 *(int*)(contents_buffer) = contents_size;
189 fwrite(contents_buffer, 1, contents_size, dest);
193 fwrite(data_buffer, 1, data_size, dest);
196 // Run system command on it
197 sprintf(system_command, "%s %s %s", BOOTSTRAP, temp_path, out_path);
198 int temp = system(system_command);