32x: drc: more wip, some games work, debug stats
[picodrive.git] / platform / uiq2 / launcher / nicemake.c
CommitLineData
cc68a136 1#include <stdio.h>\r
2#include <stdlib.h>\r
3#include <string.h>\r
4\r
5\r
6void targetname(char *dest, char *src)\r
7{\r
8 char *p, *p1;\r
9\r
10 if(strlen(src) < 5 || src[0] == '\t') return;\r
11\r
12 // goto string end\r
13 for(p=src; *p && *p != ' ' && *p != '\r'; p++);\r
14 // goto start\r
15 for(p1=p; p1 > src && *p1 != '\\'; p1--); p1++;\r
16 if(p-p1 > 0) {\r
17 strncpy(dest, p1, p-p1);\r
18 dest[p-p1] = 0;\r
19 }\r
20}\r
21\r
22\r
23int main(int argc, char *argv[])\r
24{\r
25 FILE *f = 0, *fo = 0;\r
26 unsigned char buff[512], buff2[128], outname[512];\r
27 buff2[0] = 0;\r
28\r
29 if(argc != 2) {\r
30 printf("usage: %s <makefile>\n\n", argv[0]);\r
31 return 1;\r
32 }\r
33 \r
34 f = fopen(argv[1], "r");\r
35 if(!f) {\r
36 printf("%s: couldn't open %s\n", argv[0], argv[1]);\r
37 return 2;\r
38 }\r
39\r
40 strcpy(outname, argv[1]);\r
41 strcat(outname, ".out");\r
42 fo = fopen(outname, "w");\r
43 if(!fo) {\r
44 fclose(f);\r
45 printf("%s: couldn't open %s for writing\n", argv[0], outname);\r
46 return 3;\r
47 }\r
48\r
49\r
50 while(!feof(f)) {\r
51 fgets(buff, 512, f);\r
52 if(!strncmp(buff, "\t$(GCCUREL)", 11) && !strchr(buff, '>')) {\r
53 fprintf(fo, "\t@echo %s: gcc\n\t@$(GCCUREL)", buff2);\r
54 fputs(buff+11, fo);\r
55 } else if(!strncmp(buff, "\tperl -S ecopyfile.pl", 21) && !strchr(buff, '>')) {\r
56 fprintf(fo, "\t@echo %s: perl -S ecopyfile.pl\n\t@perl", buff2);\r
57 fputs(buff+5, fo);\r
58 } else if(!strncmp(buff, "\tperl -S epocrc.pl", 18) && !strchr(buff, '>')) {\r
59 fprintf(fo, "\t@echo %s: perl -S epocrc.pl\n\t@perl", buff2);\r
60 fputs(buff+5, fo);\r
61 } else if(!strncmp(buff, "\tperl -S epocaif.pl", 19) && !strchr(buff, '>')) {\r
62 fprintf(fo, "\t@echo %s: perl -S epocaif.pl\n\t@perl", buff2);\r
63 fputs(buff+5, fo);\r
64 } else if(!strncmp(buff, "\tperl -S emkdir.pl", 18) && !strchr(buff, '>')) {\r
65 fprintf(fo, "\t@echo %s: perl -S emkdir.pl\n\t@perl", buff2);\r
66 fputs(buff+5, fo);\r
67 } else if(!strncmp(buff, "\tperl -S makedef.pl", 18) && !strchr(buff, '>')) {\r
68 fprintf(fo, "\t@echo %s: perl -S makedef.pl\n\t@perl", buff2);\r
69 fputs(buff+5, fo);\r
70 } else if(!strncmp(buff, "\tld ", 4) && !strchr(buff, '>')) {\r
71 fprintf(fo, "\t@echo %s: ld\n\t@ld ", buff2);\r
72 fputs(buff+4, fo);\r
73 } else if(!strncmp(buff, "\tar ", 4) && !strchr(buff, '>')) {\r
74 fprintf(fo, "\t@echo %s: ar\n\t@ar ", buff2);\r
75 fputs(buff+4, fo);\r
76 } else if(!strncmp(buff, "\tif exist ", 10) && !strchr(buff, '>')) {\r
77 fprintf(fo, "\t@echo %s: if exist (del?)\n\t@if exist ", buff2);\r
78 fputs(buff+10, fo);\r
79 } else if(!strncmp(buff, "\tdlltool ", 9) && !strchr(buff, '>')) {\r
80 fprintf(fo, "\t@echo %s: dlltool\n\t@dlltool ", buff2);\r
81 fputs(buff+9, fo);\r
82 } else if(!strncmp(buff, "\tpetran ", 8) && !strchr(buff, '>')) {\r
83 fprintf(fo, "\t@echo %s: petran\n\t@petran ", buff2);\r
84 fputs(buff+8, fo);\r
85 } else {\r
86 // try to get new targetname\r
87 targetname(buff2, buff);\r
88 fputs(buff, fo);\r
89 }\r
90 }\r
91\r
92\r
93 // done!\r
94 fclose(f);\r
95 fclose(fo);\r
96\r
97 remove(argv[1]);\r
98 rename(outname, argv[1]);\r
99\r
100 return 0;\r
101}\r