Ticket #239: xapdep2.patch
File xapdep2.patch, 3.0 KB (added by , 15 years ago) |
---|
-
ChangeLog
1 Tue 09 10:58:52 GMT 2010 Charlie Hull <charlie@flax.co.uk> 2 3 * xapdep/xapdep.c: Print object file on every line like Makedepend 4 did, add quotes round dependencies to cope with Windows paths, 5 remove old rename-in-place function 6 1 7 Mon Mar 08 06:26:13 GMT 2010 Olly Betts <olly@survex.com> 2 8 3 9 * xapdep/README: Undouble contents (this file was in the patch twice). -
xapdep/xapdep.c
19 19 */ 20 20 /* Replacement for makedepend, which had several bugs. We read in a file 'deps.d', 21 21 made by the MSVC compiler using the -showIncludes switch, reformat it and add its 22 contents to the end of 'Makefile' - we do a nasty in-place replacement*/22 contents to the end of 'Makefile' */ 23 23 24 24 #pragma warning(disable:4996) 25 25 #include <io.h> … … 39 39 /* lines that don't match the above will have a colon at this position*/ 40 40 #define CHECKPOS 4 41 41 42 /* Ugly rename-in-place hack taken from Makedepend sources */43 int myrename(char *from, char *to)44 {45 int r=1;46 char buf[BUFSIZE];47 FILE *in, *out;48 in=fopen(from, "rb");49 if(in==0)50 return -1;51 out=fopen(to, "wb");52 if(out==0)53 return -1;54 while(!feof(in) && r>0)55 {56 r=fread(buf, 1, sizeof(buf), in);57 if(r>0)58 fwrite(buf, 1, r, out);59 }60 fclose(out);61 fclose(in);62 if(unlink(from) < 0)63 fprintf(stderr, "\nXAPDEP could not delete %s : %s\n", from, strerror(errno));64 65 return 0;66 }67 68 42 int main(int argc, char *argv[]) 69 43 { 70 44 FILE *indep,*inmak,*outmak; 71 45 char buf[BUFSIZE]; 46 char objfile[BUFSIZE]; 72 47 int ch, endch; 73 48 74 49 /* Open the files we'll need, renaming the old Makefile to a backup */ … … 78 53 fprintf(stderr, "\nXAPDEP could not read deps.d\n"); 79 54 return -1; 80 55 } 81 if(myrename(MAKEFILE,BACKUP_MAKEFILE)!=0) 82 return -1; 56 (void)unlink(BACKUP_MAKEFILE); 57 if(rename(MAKEFILE,BACKUP_MAKEFILE)!=0) 58 return -1; 59 83 60 inmak=fopen(BACKUP_MAKEFILE,"rb"); 84 61 outmak=fopen(MAKEFILE,"wb"); 85 62 if((inmak==0)||(outmak==0)) … … 111 88 /* first line should be a .cc file, use this to generate the .obj file */ 112 89 ch=0; 113 90 while((buf[ch]!='.') && (buf[ch]!='\0')) 114 putc(buf[ch++], outmak); 115 fputs(".obj : ", outmak); 91 objfile[ch] = buf[ch++]; 92 objfile[ch]='\0'; 93 strcat(objfile,".obj : "); 116 94 while(!feof(indep)) 117 95 { 118 96 /* get all the dependencies */ … … 132 110 /* skip space */ 133 111 while((ch < endch) && (buf[ch]!='\r') && (buf[ch]==' ')) 134 112 ch++; 113 fputs(objfile, outmak); 114 putc('\"', outmak); 135 115 while((ch < endch) && (buf[ch]!='\r')) 136 116 putc(buf[ch++], outmak); 137 fputs("\ r\n", outmak);117 fputs("\" \r\n", outmak); 138 118 } 139 119 } 140 120 }