1omkdepend
2=========
3
4This code is taken from the X11R6 makedepend sources. All I have done is:
5
6 * Add GNUWIN32 file name translation.
7 * Remove all predefined symbols, include directories and other
8 platform-specific behaviour. Its behaviour should be the same on all
9 platforms. All symbols and include directories must be explicitly given on
10 the command line with -D and -I flags.
11 * Fix processing of numbers in #if expressions.
12 * Fix processing of -D flag.
13 * Fix C++ comment handling.
14 * Improve #error warnings.
15 * Change the output so that processing "xxx.c" or "xxx.cc" produces "xxx.d".
16
17I disclaim all responsibility for the unclean nature of the code herein.
18
19TJR 17/7/97.
20
21
22For reference, here is a complete diff from the X11R6 source:
23
24% diff /packages/old/X11R6/src/xc/config/makedepend .
25Only in /packages/old/X11R6/src/xc/config/makedepend: Imakefile
26Only in /packages/old/X11R6/src/xc/config/makedepend: cpp.ed
27Only in /packages/old/X11R6/src/xc/config/makedepend: mkdepend.man
28Only in .: README
29Only in .: dir.mk
30Only in .: gnuwin32.c
31Only in .: gnuwin32.h
32
33
34 *************** def.h ***************
35
36diff /packages/old/X11R6/src/xc/config/makedepend/def.h ./def.h
3729,33d28
38< #include <X11/Xosdefs.h>
39< #ifdef WIN32
40< #include <X11/Xw32defs.h>
41< #endif
42< #include <X11/Xfuncproto.h>
43
44
45 *************** ifparser.c ***************
46
47diff /packages/old/X11R6/src/xc/config/makedepend/ifparser.c ./ifparser.c
48102d101
49< #ifdef WIN32
50104,108d102
51< #else
52< *valp = atoi (cp);
53< /* EMPTY */
54< for (cp++; isdigit(*cp); cp++) ;
55< #endif
56
57
58 *************** include.c ***************
59
60diff /packages/old/X11R6/src/xc/config/makedepend/include.c ./include.c
61103a104,106
62> #ifdef WIN32
63> sprintf(path, "%s\\%s", *pp, include);
64> #else
65104a108
66> #endif
67
68
69 *************** main.c ***************
70
71diff /packages/old/X11R6/src/xc/config/makedepend/main.c ./main.c
7228a29
73> #include "gnuwin32.h"
7477,79c78
75< #define MAKEDEPEND
76< #include "imakemdep.h" /* from config sources */
77< #undef MAKEDEPEND
78---
79> struct symtab predefs[] = { {NULL, NULL} };
8089,90c88
81< char *objsuffix = OBJSUFFIX;
82< char *startat = "# DO NOT DELETE";
83---
84> char *objsuffix = ".o";
85138a137,139
86> #ifdef WIN32
87> GetMounts();
88> #endif
89202a204,206
90> #ifdef WIN32
91> argv[0] = TranslateFileNameU2D(argv[0],0);
92> #endif
93211a216,217
94> {
95> int offset = 2;
96214a221
97> offset = 0;
98216c223
99< for (p=argv[0] + 2; *p ; p++)
100---
101> for (p=argv[0] + offset; *p ; p++)
102221c228
103< define(argv[0] + 2, &maininclist);
104---
105> define(argv[0] + offset, &maininclist);
106222a230
107> }
108230a239,241
109> #ifdef WIN32
110> *(incp-1) = TranslateFileNameU2D(*(incp-1),0);
111> #endif
112275,294d285
113< case 's':
114< if (endmarker) break;
115< startat = argv[0]+2;
116< if (*startat == '\0') {
117< startat = *(++argv);
118< argc--;
119< }
120< if (*startat != '#')
121< fatalerr("-s flag's value should start %s\n",
122< "with '#'.");
123< break;
124< case 'f':
125< if (endmarker) break;
126< makefile = argv[0]+2;
127< if (*makefile == '\0') {
128< makefile = *(++argv);
129< argc--;
130< }
131< break;
132<
133312,324d302
134< #ifdef PREINCDIR
135< if (incp >= includedirs + MAXDIRS)
136< fatalerr("Too many -I flags.\n");
137< *incp++ = PREINCDIR;
138< #endif
139< if (incp >= includedirs + MAXDIRS)
140< fatalerr("Too many -I flags.\n");
141< *incp++ = INCLUDEDIR;
142< #ifdef POSTINCDIR
143< if (incp >= includedirs + MAXDIRS)
144< fatalerr("Too many -I flags.\n");
145< *incp++ = POSTINCDIR;
146< #endif
147331,332d308
148< redirect(startat, makefile);
149<
150401a378,385
151> char *base = base_name(*fp);
152> char *depfile = (char *)malloc(strlen(base) + 3);
153> sprintf(depfile,"%s.d",base);
154> if (!freopen(depfile, "wb", stdout))
155> fatalerr("cannot open \"%s\"\n", depfile);
156> free(depfile);
157> free(base);
158> printed = FALSE;
159405c389
160< find_includes(filecontent, ip, ip, 0, FALSE);
161---
162> find_includes(filecontent, ip, ip, 0, TRUE);
163408a393,394
164> if (printed)
165> printf("\n");
166410,411d395
167< if (printed)
168< printf("\n");
169503d486
170< #ifdef WIN32
171507a491
172> p--; /* go back to before newline */
173511d494
174< #endif
175550c533,535
176< file = copy(file);
177---
178> for(p=file+strlen(file); p>file && *p != '/' && *p != '\\'; p--) ;
179> if (p>file) p++;
180> file = copy(p);
181558,639d542
182< #if defined(USG) && !defined(CRAY) && !defined(SVR4)
183< int rename (from, to)
184< char *from, *to;
185< {
186< (void) unlink (to);
187< if (link (from, to) == 0) {
188< unlink (from);
189< return 0;
190< } else {
191< return -1;
192< }
193< }
194< #endif /* USGISH */
195<
196< redirect(line, makefile)
197< char *line,
198< *makefile;
199< {
200< struct stat st;
201< FILE *fdin, *fdout;
202< char backup[ BUFSIZ ],
203< buf[ BUFSIZ ];
204< boolean found = FALSE;
205< int len;
206<
207< /*
208< * if makefile is "-" then let it pour onto stdout.
209< */
210< if (makefile && *makefile == '-' && *(makefile+1) == '\0')
211< return;
212<
213< /*
214< * use a default makefile is not specified.
215< */
216< if (!makefile) {
217< if (stat("Makefile", &st) == 0)
218< makefile = "Makefile";
219< else if (stat("makefile", &st) == 0)
220< makefile = "makefile";
221< else
222< fatalerr("[mM]akefile is not present\n");
223< }
224< else
225< stat(makefile, &st);
226< if ((fdin = fopen(makefile, "r")) == NULL)
227< fatalerr("cannot open \"%s\"\n", makefile);
228< sprintf(backup, "%s.bak", makefile);
229< unlink(backup);
230< #ifdef WIN32
231< fclose(fdin);
232< #endif
233< if (rename(makefile, backup) < 0)
234< fatalerr("cannot rename %s to %s\n", makefile, backup);
235< #ifdef WIN32
236< if ((fdin = fopen(backup, "r")) == NULL)
237< fatalerr("cannot open \"%s\"\n", backup);
238< #endif
239< if ((fdout = freopen(makefile, "w", stdout)) == NULL)
240< fatalerr("cannot open \"%s\"\n", backup);
241< len = strlen(line);
242< while (!found && fgets(buf, BUFSIZ, fdin)) {
243< if (*buf == '#' && strncmp(line, buf, len) == 0)
244< found = TRUE;
245< fputs(buf, fdout);
246< }
247< if (!found) {
248< if (verbose)
249< warning("Adding new delimiting line \"%s\" and dependencies...\n",
250< line);
251< puts(line); /* same as fputs(fdout); but with newline */
252< } else if (append) {
253< while (fgets(buf, BUFSIZ, fdin)) {
254< fputs(buf, fdout);
255< }
256< }
257< fflush(fdout);
258< #if defined(USGISH) || defined(_SEQUENT_)
259< chmod(makefile, st.st_mode);
260< #else
261< fchmod(fileno(fdout), st.st_mode);
262< #endif /* USGISH */
263< }
264
265
266 *************** parse.c ***************
267
268diff /packages/old/X11R6/src/xc/config/makedepend/parse.c ./parse.c
269131c131,132
270< warning("%s: %d: %s\n", file_red->i_file,
271---
272> warning("(from %s) %s: %d: %s\n",
273> file_red->i_file, file->i_file,
274
275
276 *************** pr.c ***************
277
278diff /packages/old/X11R6/src/xc/config/makedepend/pr.c ./pr.c
27998d97
280< static int current_len;
281100a100,104
282> #ifdef WIN32
283> char *transfile = TranslateFileNameD2U(ip->i_file,0);
284> #else
285> char *transfile = ip->i_file;
286> #endif
287103,104c107
288< len = strlen(ip->i_file)+1;
289< if (current_len + len > width || file != lastfile) {
290---
291> if (file != lastfile) {
292106,108c109,110
293< sprintf(buf, "\n%s%s%s: %s", objprefix, base, objsuffix,
294< ip->i_file);
295< len = current_len = strlen(buf);
296---
297> sprintf(buf, "%s%s%s %s.d: %s", objprefix, base, objsuffix,
298> base, transfile);
299111,113c113
300< buf[0] = ' ';
301< strcpy(buf+1, ip->i_file);
302< current_len += len;
303---
304> sprintf(buf, " \\\n %s", transfile);
305115c115
306< fwrite(buf, len, 1, stdout);
307---
308> fwrite(buf, strlen(buf), 1, stdout);
309124c124
310< printf("\n# %s includes:", ip->i_file);
311---
312> printf("\n# %s includes:", transfile);
313126a127,129
314> #ifdef WIN32
315> free(transfile);
316> #endif
317