forked from KolibriOS/kolibrios
kolibri-libc:
Move to folder with tcc. Part 1 git-svn-id: svn://kolibrios.org@8793 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
57
programs/develop/ktcc/trunk/libc.obj/linuxtools/src/ExportGen.c
Executable file
57
programs/develop/ktcc/trunk/libc.obj/linuxtools/src/ExportGen.c
Executable file
@@ -0,0 +1,57 @@
|
||||
// export_table_gen
|
||||
// Copyright (C) maxcodehack and turbocat2001, 2021
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
if (argc != 3) {
|
||||
printf("Usage: %s <symbols.txt> <exports.c>\n", argv[0]);
|
||||
return 0;
|
||||
}
|
||||
FILE *input, *output;
|
||||
if ((input = fopen(argv[1], "r")) == NULL)
|
||||
{
|
||||
printf("error: file \"%s\" not found\n", argv[1]);
|
||||
return 1;
|
||||
}
|
||||
char buf[10000];
|
||||
// Head
|
||||
strcpy(buf, \
|
||||
"#include <stdio.h>\n" \
|
||||
"#include <string.h>\n" \
|
||||
"#include <stdlib.h>\n" \
|
||||
"#include <time.h>\n" \
|
||||
"#include <sys/dirent.h>\n" \
|
||||
"#include <sys/ksys.h>\n\n" \
|
||||
"#include <math.h>\n\n" \
|
||||
"#include <setjmp.h>\n\n" \
|
||||
"ksys_coff_etable_t EXPORTS[] = {\n");
|
||||
|
||||
// Generate
|
||||
char symbol[256];
|
||||
while(fscanf(input, "%s", symbol) != EOF) {
|
||||
if(symbol[0]!='!'){
|
||||
char temp[256];
|
||||
sprintf(temp, "{\"%s\", &%s},\n", symbol, symbol);
|
||||
strcat(buf, temp);
|
||||
}
|
||||
}
|
||||
strcat(buf, "NULL,\n};");
|
||||
fclose(input);
|
||||
|
||||
// Output generated
|
||||
output = fopen(argv[2], "w");
|
||||
if (output == NULL)
|
||||
{
|
||||
printf("Unable to write to file: '%s'!\n", argv[2]);
|
||||
return 1;
|
||||
}
|
||||
|
||||
fputs(buf, output);
|
||||
fclose(output);
|
||||
|
||||
printf("Done, check %s!\n", argv[2]);
|
||||
|
||||
return 0;
|
||||
}
|
@@ -0,0 +1,48 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <limits.h>
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
if(argc!=3){
|
||||
printf("Usage: LoadGen <symbols.txt> <loader_dir>\n");
|
||||
return 0;
|
||||
}
|
||||
argv[2][strlen(argv[1])-2]='\0';
|
||||
FILE* symbols_txt = fopen(argv[1], "r");
|
||||
if(!symbols_txt){
|
||||
fprintf(stderr, "File '%s' not found!\n", argv[1]);
|
||||
return -1;
|
||||
}
|
||||
char line[256];
|
||||
while(fgets(line, 256, symbols_txt)) {
|
||||
if(line[0]!='!'){
|
||||
if(line[strlen(line)-1]=='\n'){
|
||||
line[strlen(line)-1]='\0';
|
||||
}
|
||||
char asm_name[PATH_MAX];
|
||||
sprintf(asm_name, "%s/%s.asm", argv[2], line);
|
||||
FILE *out = fopen(asm_name, "wb");
|
||||
if(!out){
|
||||
fprintf(stderr, "Error! File '%s' not created!\n", asm_name);
|
||||
return -1;
|
||||
}else{
|
||||
printf("File '%s' created successfully!\n", asm_name);
|
||||
}
|
||||
|
||||
fprintf(out, "format ELF\n");
|
||||
fprintf(out, "include \"__lib__.inc\"\n");
|
||||
fprintf(out, "fun equ __func@%s\n", line);
|
||||
fprintf(out, "fun_str equ '%s'\n", line);
|
||||
fprintf(out, "section '.text'\n");
|
||||
fprintf(out, "fun_name db fun_str, 0\n");
|
||||
fprintf(out, "section '.data'\n");
|
||||
fprintf(out, "extrn lib_name\n");
|
||||
fprintf(out, "public fun as fun_str\n");
|
||||
fprintf(out, "fun dd fun_name\n");
|
||||
fprintf(out, "lib dd lib_name\n");
|
||||
|
||||
fclose(out);
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,3 @@
|
||||
all:
|
||||
$(CC) ExportGen.c -o ../ExportGen
|
||||
$(CC) LoaderGen.c -o ../LoaderGen
|
Reference in New Issue
Block a user