tek@penzance.cs.ucla.edu (02/14/90)
Since makedepend comes in the MIT X distribution, I decided to post here ... Ever want to build variants of a program and put the object files in separate subidrectories? The following changes should help you use makedepend in such situations. (Assuming, of course, your version of make can handle object files outside of the current directory.) The one problem is that makedepend thinks the object files always belong in the current directory. The new "-p" switch allows you to prefix the object file names in the dependencies, so you can specify a different directory. Also makedepend doesn't allow you to accumulate more than one set of dependencies. (It deletes all the dependencies each time.) The new "-a" switch specifies dependencies should be appended to the end of the file. (It would be better, if it could selectively replace dependencies, but that is much harder to do.) An example Makefile (for SUNOS): SRCS= a.c b.c OBJS= $(SRCS:.c=.o) VAR1FLAGS= -DVAR1 VAR1DIR= var1 VAR1OBJS= $(OBJS:%=$(VAR1DIR)/%) VAR2FLAGS= -DVAR2 VAR2DIR= var2 VAR2OBJS= $(OBJS:%=$(VAR2DIR)/%) var1 := CFLAGS= $(VAR1FLAGS) var2 := CFLAGS= $(VAR2FLAGS) var1: $(VAR1OBJS) cc -o $@ $(VAR1OBJS) var2: $(VAR2OBJS) cc -o $@ $(VAR2OBJS) $(VAR1DIR)/%.o $(VAR2DIR)/%.o: %.c $(COMPILE.c) -o $@ $< depend:: makedepend -p $(VAR1DIR)/ -- $(VAR1FLAGS) -- $(SRCS) depend:: makedepend -a -p $(VAR2DIR)/ -- $(VAR2FLAGS) -- $(SRCS) # DO NOT DELETE Patches to implement the "-a" and "-p" switches follow. They affect files: mit/util/makedepend/main.c mit/util/makedepend/mkdepend.man mit/util/makedepend/pr.c use "patch -p0 < patchfile" from the X source root *** mit/util/makedepend/main.c- Sat Dec 16 18:03:45 1989 --- mit/util/makedepend/main.c Tue Feb 13 12:35:50 1990 *************** *** 45,53 **** --- 45,55 ---- char *filelist[ MAXFILES ]; char *includedirs[ MAXDIRS ]; char *notdotdot[ MAXDIRS ]; + char *objprefix = ""; char *objfile = ".o"; char *startat = "# DO NOT DELETE THIS LINE -- make depend depends on it."; int width = 78; + boolean append = FALSE; boolean printed = FALSE; boolean verbose = FALSE; boolean show_where_not = FALSE; *************** *** 134,139 **** --- 136,144 ---- argc--; } break; + case 'a': + append = TRUE; + break; /* do not use if endmarker processing */ case 'w': if (endmarker) break; *************** *** 153,158 **** --- 158,171 ---- } else objfile = argv[0]+2; break; + case 'p': + if (endmarker) break; + objprefix = argv[0]+2; + if (*objprefix == '\0') { + objprefix = *(++argv); + argc--; + } + break; case 'v': if (endmarker) break; verbose = TRUE; *************** *** 422,427 **** --- 435,445 ---- fatal("cannot rename %s to %s\n", makefile, backup); if ((fdout = freopen(makefile, "w", stdout)) == NULL) fatal("cannot open \"%s\"\n", backup); + if (append) + while (fgets(buf, BUFSIZ, fdin)) + fputs(buf, fdout); + else { + len = strlen(line); while (fgets(buf, BUFSIZ, fdin) && !found) { if (*buf == '#' && strncmp(line, buf, len) == 0) *************** *** 433,438 **** --- 451,458 ---- warning("Adding new delimiting line \"%s\" and dependencies...\n", line); puts(line); /* same as fputs(fdout); but with newline */ + } + } fflush(fdout); #ifdef USG *** mit/util/makedepend/mkdepend.man- Thu Dec 21 11:05:07 1989 --- mit/util/makedepend/mkdepend.man Tue Feb 13 12:53:44 1990 *************** *** 11,20 **** --- 11,24 ---- ] [ .B \-Iincludedir ] [ + .B \-a + ] [ .B \-fmakefile ] [ .B \-oobjsuffix ] [ + .B \-pprefix + ] [ .B \-sstring ] [ .B \-wwidth *************** *** 144,149 **** --- 148,157 ---- .B makedepend only searches /usr/include. .TP 5 + .B \-a + Append the dependencies to the end of the file instead of replacing + them. + .TP 5 .B \-fmakefile Filename. This allows you to specify an alternate makefile in which *************** *** 161,166 **** --- 169,179 ---- with .I -o:obj and so forth. + .TP 5 + .B \-pprefix + Object file prefix. + The prefix is prepended to the name of the object file. This is + usually used to designate a different directory for the object file. .TP 5 .B \-sstring Starting string delimiter. *** mit/util/makedepend/pr.c- Tue Dec 12 09:44:29 1989 --- mit/util/makedepend/pr.c Tue Feb 13 12:27:55 1990 *************** *** 5,10 **** --- 5,11 ---- extern struct inclist inclist[ MAXFILES ], *inclistp; + extern char *objprefix; extern char *objfile; extern int width; extern boolean printed; *************** *** 72,78 **** len = strlen(ip->i_file)+1; if (current_len + len > width || file != lastfile) { lastfile = file; ! sprintf(buf, "\n%s%s: %s", base, objfile, ip->i_file); len = current_len = strlen(buf); } else { --- 73,80 ---- len = strlen(ip->i_file)+1; if (current_len + len > width || file != lastfile) { lastfile = file; ! sprintf(buf, "\n%s%s%s: %s", objprefix, base, objfile, ! ip->i_file); len = current_len = strlen(buf); } else { Ted Kim UCLA Computer Science Department Internet: tek@penzance.cs.ucla.edu 3804C Boelter Hall UUCP: ...!{uunet|ucbvax}!cs.ucla.edu!tek Los Angeles, CA 90024 Phone: (213) 206-8696