Ticket #239: xapdep2.patch

File xapdep2.patch, 3.0 KB (added by Charlie Hull, 14 years ago)

Further patch to fix small issues with xapdep

  • ChangeLog

     
     1Tue  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   
    17Mon Mar 08 06:26:13 GMT 2010  Olly Betts <olly@survex.com>
    28
    39        * xapdep/README: Undouble contents (this file was in the patch twice).
  • xapdep/xapdep.c

     
    1919 */
    2020/* Replacement for makedepend, which had several bugs. We read in a file 'deps.d',
    2121made 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' */
    2323
    2424#pragma warning(disable:4996)
    2525#include <io.h>
     
    3939/*  lines that don't match the above will have a colon at this position*/
    4040#define CHECKPOS 4
    4141
    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 
    6842int main(int argc, char *argv[])
    6943{
    7044        FILE *indep,*inmak,*outmak;
    7145        char buf[BUFSIZE];
     46    char objfile[BUFSIZE];
    7247        int ch, endch;
    7348
    7449    /* Open the files we'll need, renaming the old Makefile to a backup */
     
    7853                fprintf(stderr, "\nXAPDEP could not read deps.d\n");
    7954                return -1;
    8055        }
    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
    8360        inmak=fopen(BACKUP_MAKEFILE,"rb");
    8461        outmak=fopen(MAKEFILE,"wb");
    8562        if((inmak==0)||(outmak==0))
     
    11188                                /* first line should be a .cc file, use this to generate the .obj file */
    11289                                ch=0;
    11390                                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 : ");
    11694                                while(!feof(indep))
    11795                                {
    11896                    /* get all the dependencies */
     
    132110                    /* skip space */
    133111                                        while((ch < endch) && (buf[ch]!='\r') && (buf[ch]==' '))
    134112                                                ch++;
     113                                fputs(objfile, outmak);
     114                    putc('\"', outmak);
    135115                                        while((ch < endch) && (buf[ch]!='\r'))
    136116                                                putc(buf[ch++], outmak);
    137                                         fputs("\r\n", outmak);
     117                                        fputs("\" \r\n", outmak);
    138118                                }
    139119                        }
    140120                }