diff options
author | Guillaume Cottenceau <gc@mandriva.com> | 2001-05-14 14:19:32 +0000 |
---|---|---|
committer | Guillaume Cottenceau <gc@mandriva.com> | 2001-05-14 14:19:32 +0000 |
commit | 167217bec15c9c7aa70ba2a3dc9c689b3cd91872 (patch) | |
tree | 7c0c62debf8f9f145643102fb52b81afce743594 /mdk-stage1/dietlibc/diet.c | |
parent | 9097327dc1c667fc51b8e05cc7c0626fac96665d (diff) | |
download | drakx-167217bec15c9c7aa70ba2a3dc9c689b3cd91872.tar drakx-167217bec15c9c7aa70ba2a3dc9c689b3cd91872.tar.gz drakx-167217bec15c9c7aa70ba2a3dc9c689b3cd91872.tar.bz2 drakx-167217bec15c9c7aa70ba2a3dc9c689b3cd91872.tar.xz drakx-167217bec15c9c7aa70ba2a3dc9c689b3cd91872.zip |
import new version of dietlibc
Diffstat (limited to 'mdk-stage1/dietlibc/diet.c')
-rw-r--r-- | mdk-stage1/dietlibc/diet.c | 112 |
1 files changed, 112 insertions, 0 deletions
diff --git a/mdk-stage1/dietlibc/diet.c b/mdk-stage1/dietlibc/diet.c new file mode 100644 index 000000000..1de6befc8 --- /dev/null +++ b/mdk-stage1/dietlibc/diet.c @@ -0,0 +1,112 @@ +#include <string.h> +#include <unistd.h> +#include <stdio.h> +#include <stdlib.h> + +/* goal: + * when invoked as + * "diet gcc -c t.c" + * exec + * "gcc -I/path/to/dietlibc/include -c t.c" + * + * when invoked as + * "diet sparc-linux-gcc -o t t.o" + * exec + * "sparc-linux-gcc -nostdlib -static -o t t.o /path/to/dietlibc/bin-sparc/start.o /path/to/dietlibc/bin-sparc/dietlibc.a" +*/ + +void error(const char *message) { + write(2,message,strlen(message)); + exit(1); +} + +int main(int argc,char *argv[]) { + int link=0; + int compile=0; + char diethome[]=DIETHOME; + char platform[1000]=DIETHOME "/bin-"; + char *nostdlib="-nostdlib"; + char *libgcc="-lgcc"; + char dashL[1000]="-L"; + int i; + + if (argc<2) { + error("usage: diet [gcc command line]\n" + "e.g. diet gcc -c t.c\n" + "or diet sparc-linux-gcc -o foo foo.c bar.o\n"); + } + { + char *tmp=strchr(argv[1],0)-2; + char *tmp2; + char *cc=argv[1]; + if (tmp<cc) goto donttouch; + if ((tmp2=strchr(cc,'-'))) { /* cross compiling? */ + int len=strlen(platform); + if (tmp2-cc>90) error("platform name too long!\n"); + memmove(platform+len,argv[1],tmp2-cc); + platform[tmp2-cc+len]=0; +/* printf("found platform %s\n",platform); */ + } else { +#ifdef __sparc__ + strcat(platform,"sparc"); +#endif +#ifdef __ppc__ + strcat(platform,"ppc"); +#endif +#ifdef __i386__ + strcat(platform,"i386"); +#endif +#ifdef __alpha__ + strcat(platform,"alpha"); +#endif +#ifdef __arm__ + strcat(platform,"arm"); +#endif +#ifdef __mips__ + strcat(platform,"mips"); +#endif + } + strcat(dashL,platform); + if (!strcmp(tmp,"cc")) { + char **newargv; + char **dest; + char *a,*b,*c; +/* we need to add -I... if the command line contains -c, -S or -E */ + for (i=2; i<argc; ++i) + if (!strcmp(argv[i],"-c") || !strcmp(argv[i],"-S") || !strcmp(argv[i],"-E")) + compile=1; +/* we need to add -nostdlib if we are not compiling*/ + link=!compile; +#if 0 + for (i=2; i<argc; ++i) + if (!strcmp(argv[i],"-o")) + if (!compile) link=1; +#endif + newargv=alloca(sizeof(char*)*(argc+6)); + a=alloca(strlen(diethome)+20); + b=alloca(strlen(platform)+20); + c=alloca(strlen(platform)+20); + + strcpy(a,"-I"); strcat(a,diethome); strcat(a,"/include"); + strcpy(b,platform); strcat(b,"/start.o"); + strcpy(c,platform); strcat(c,"/dietlibc.a"); + + dest=newargv; + *dest++=argv[1]; + if (link) { *dest++=nostdlib; *dest++=dashL; } + if (compile || link) *dest++=a; + for (i=2; i<argc; ++i) + *dest++=argv[i]; + if (link) { *dest++=b; *dest++=c; *dest++=libgcc; } + *dest=0; + execvp(newargv[0],newargv); + goto error; + } else if (!strcmp(tmp,"ld")) { + } + } +donttouch: + execvp(argv[1],argv+1); +error: + error("execvp failed!\n"); + return 1; +} |