TE smol edition

Makefile made by dennthecafebabe
This commit is contained in:
suchmememanyskill
2021-01-31 19:59:28 +01:00
parent 853cf4f5cf
commit 3499ad1549
14 changed files with 1078 additions and 6 deletions

16
tools/bin2c/Makefile Normal file
View File

@@ -0,0 +1,16 @@
NATIVE_CC ?= gcc
ifeq (, $(shell which $(NATIVE_CC) 2>/dev/null))
$(error "Native GCC is missing. Please install it first. If it's path is custom, set it with export NATIVE_CC=<path to native gcc toolchain>")
endif
.PHONY: all clean
all: bin2c
@echo > /dev/null
clean:
@rm -f bin2c
bin2c: bin2c.c
@$(NATIVE_CC) -o $@ bin2c.c

77
tools/bin2c/bin2c.c Normal file
View File

@@ -0,0 +1,77 @@
/*
* This is bin2c program, which allows you to convert binary file to
* C language array, for use as embedded resource, for instance you can
* embed graphics or audio file directly into your program.
* This is public domain software, use it on your own risk.
* Contact Serge Fukanchik at fuxx@mail.ru if you have any questions.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <fcntl.h>
#include <ctype.h>
#include <unistd.h>
/* Replace . with _ */
char*
make_ident ( char* name )
{
char* ret;
char* p;
ret = strdup ( name );
for ( p = ret; p[0]; p++ )
{
if ( !isalnum ( p[0] ) ) p[0] = '_';
}
return ret;
}
int
main ( int argc, char* argv[] )
{
unsigned char buf[BUFSIZ];
char* ident;
int fd, i, total, rd, need_comma;
if ( argc < 2 )
{
fprintf ( stderr, "Usage: %s binary_file > output_file\n", argv[0] );
return -1;
}
fd = open ( argv[1], O_RDONLY );
if ( fd == -1 )
{
fprintf ( stderr, "%s: can't open %s for reading\n", argv[0], argv[1] );
return -1;
}
ident = make_ident ( (argc > 2) ? argv[2] : argv[1] );
printf ( "static const unsigned char __attribute__((section (\"._%s\"))) %s[] = {", ident, ident );
for ( total = 0, need_comma = 0; ( rd = read ( fd, buf, BUFSIZ ) ) != 0; )
{
if ( rd == -1 )
{
fprintf ( stderr, "%s: file read error\n", argv[0] );
return -1;
}
for ( i = 0; i < rd; i++ )
{
if ( need_comma ) printf ( ", " );
else need_comma = 1;
if ( ( total % 11 ) == 0 ) printf ( "\n\t" );
printf ( "0x%.2x", buf[i] );
total++;
}
}
printf ( "\n};\n" );
close ( fd );
free ( ident );
return 0;
}