| 1 |
/*****************************************************************************\ |
| 2 |
|
| 3 |
Copyright (c) Intel Corporation (2009-2017). |
| 4 |
|
| 5 |
INTEL MAKES NO WARRANTY OF ANY KIND REGARDING THE CODE. THIS CODE IS |
| 6 |
LICENSED ON AN "AS IS" BASIS AND INTEL WILL NOT PROVIDE ANY SUPPORT, |
| 7 |
ASSISTANCE, INSTALLATION, TRAINING OR OTHER SERVICES. INTEL DOES NOT |
| 8 |
PROVIDE ANY UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY |
| 9 |
DISCLAIMS ANY WARRANTY OF MERCHANTABILITY, NONINFRINGEMENT, FITNESS FOR ANY |
| 10 |
PARTICULAR PURPOSE, OR ANY OTHER WARRANTY. Intel disclaims all liability, |
| 11 |
including liability for infringement of any proprietary rights, relating to |
| 12 |
use of the code. No license, express or implied, by estoppel or otherwise, |
| 13 |
to any intellectual property rights is granted herein. |
| 14 |
|
| 15 |
\file linux_resource_linker.cpp |
| 16 |
|
| 17 |
\*****************************************************************************/ |
| 18 |
|
| 19 |
#include <stdio.h> |
| 20 |
#include <string.h> |
| 21 |
|
| 22 |
int main(int argc, char **argv) |
| 23 |
{ |
| 24 |
FILE *input; |
| 25 |
FILE *output; |
| 26 |
|
| 27 |
if (!argv[1] || !strcmp(argv[1], "-h") || !strcmp(argv[1], "--help") || !argv[2] || !argv[3]) |
| 28 |
{ |
| 29 |
printf("Usage: bif_linker [input file] [output file] [symbol base name]\n"); |
| 30 |
return 0; |
| 31 |
} |
| 32 |
|
| 33 |
input = fopen(argv[1], "rb"); |
| 34 |
if (!input) |
| 35 |
{ |
| 36 |
printf("Unable to open input file for reading (%s)\n", argv[1]); |
| 37 |
return 1; |
| 38 |
} |
| 39 |
|
| 40 |
output = fopen(argv[2], "wb"); |
| 41 |
if (!output) |
| 42 |
{ |
| 43 |
printf("Unable to open output file for writing (%s)\n", argv[2]); |
| 44 |
return 1; |
| 45 |
} |
| 46 |
|
| 47 |
fprintf(output, "// This file is auto generated by bo_linker, DO NOT EDIT\n\n"); |
| 48 |
fprintf(output, "unsigned char __attribute__((visibility(\"default\"))) %s[] =\n{\n ", argv[3]); |
| 49 |
|
| 50 |
int count = 0; |
| 51 |
int is_eol; |
| 52 |
unsigned char data; |
| 53 |
while(fread(&data, 1, 1, input)) |
| 54 |
{ |
| 55 |
is_eol = count ? !(count % 20) : 0; |
| 56 |
fprintf(output, "%s0x%.2x, ", is_eol? "\n ":"", data); |
| 57 |
count++; |
| 58 |
} |
| 59 |
fprintf(output, "0x00\n};\n\n"); |
| 60 |
|
| 61 |
fprintf(output, "unsigned int __attribute__((visibility(\"default\"))) %s_size = %d;\n\n", argv[3], count); |
| 62 |
fclose(input); |
| 63 |
fclose(output); |
| 64 |
|
| 65 |
} |