]>
Commit | Line | Data |
---|---|---|
1 | /**/# $Source$ | |
2 | /**/# $Author$ | |
3 | /**/# $Header$ | |
4 | /**/# | |
5 | ||
6 | #ifdef __STDC__ | |
7 | #define concat(x,y) x##y | |
8 | #define concat3(x,y,z) x##y##z | |
9 | #define concat4(w,x,y,z) w##x##y##z | |
10 | #define concat5(v,w,x,y,z) v##w##x##y##z | |
11 | #define requote(x) #x | |
12 | #else | |
13 | #define concat(x,y)x/**/y | |
14 | #define concat3(x,y,z)x/**/y/**/z | |
15 | #define concat4(w,x,y,z)w/**/x/**/y/**/z | |
16 | #define concat5(v,w,x,y,z)v/**/w/**/x/**/y/**/z | |
17 | #define requote(x) "x" | |
18 | #endif | |
19 | ||
20 | #ifdef PROFILED_LIBS | |
21 | /* | |
22 | * Rule for building objects in libraries. | |
23 | */ | |
24 | ||
25 | #ifdef mips | |
26 | /* | |
27 | * The MIPS loader doesn't have the -X flag or its functionality. | |
28 | */ | |
29 | #define library_obj_rule() @@\ | |
30 | .c.o: @@\ | |
31 | $(CC) PROF_FLAG -c $(CFLAGS) $*.c @@\ | |
32 | $(MV) $*.o profiled/$*.o @@\ | |
33 | $(CC) -c $(CFLAGS) $*.c @@\ | |
34 | -$(LD) -x -r -o a.out $*.o @@\ | |
35 | $(MV) a.out $*.o | |
36 | #else /* ! mips */ | |
37 | #define library_obj_rule() @@\ | |
38 | .c.o: @@\ | |
39 | $(CC) PROF_FLAG -c $(CFLAGS) $*.c @@\ | |
40 | -$(LD) -X -r -o profiled/$*.o $*.o @@\ | |
41 | $(CC) -c $(CFLAGS) $*.c @@\ | |
42 | -$(LD) -x -r -o a.out $*.o @@\ | |
43 | $(MV) a.out $*.o | |
44 | #endif /* mips */ | |
45 | /* | |
46 | * cc -R breaks profiling with -p on 4.3BSD on the VAX | |
47 | * (and probably elsewhere), so we don't do it for the profiled version. | |
48 | */ | |
49 | ||
50 | #define library_ro_object(cfile) @@\ | |
51 | concat(cfile,.o): concat(cfile,.c) @@\ | |
52 | $(CC) PROF_FLAG -c $(CFLAGS) concat(cfile,.c) @@\ | |
53 | -$(LD) -X -r -o profiled/$*.o $*.o @@\ | |
54 | $(CCRO) -c $(CFLAGS) concat(cfile,.c) @@\ | |
55 | -$(LD) -x -r -o a.out $*.o @@\ | |
56 | $(MV) a.out $*.o | |
57 | ||
58 | #define library_asm_object(ofile,sfile) @@\ | |
59 | ofile: sfile @@\ | |
60 | $(CP) sfile x.c @@\ | |
61 | $(CPP) -DPROF x.c | $(AS) - @@\ | |
62 | -$(LD) -X -r -o profiled/$*.o a.out @@\ | |
63 | $(CPP) x.c | $(AS) - @@\ | |
64 | -$(LD) -x -r -o $*.o a.out @@\ | |
65 | $(RM) a.out x.c | |
66 | ||
67 | #define install_library_target(libname,objs,srcs,lintlibs) @@\ | |
68 | @@\ | |
69 | all:: concat3(lib,libname,.a) concat3(lib,libname,_p.a) @@\ | |
70 | all:: concat3(llib-l,libname,.ln) @@\ | |
71 | @@\ | |
72 | concat3(lib,libname,.a): objs @@\ | |
73 | $(RM) $@.bak @@\ | |
74 | -$(MV) $@ $@.bak @@\ | |
75 | $(ARCHIVE) $@ objs @@\ | |
76 | $(RANLIB) $@ @@\ | |
77 | @@\ | |
78 | concat3(lib,libname,_p.a): objs @@\ | |
79 | $(RM) $@.bak @@\ | |
80 | -$(MV) $@ $@.bak @@\ | |
81 | cd profiled; $(ARCHIVE) ../$@ objs @@\ | |
82 | $(RANLIB) $@ @@\ | |
83 | @@\ | |
84 | lint:: concat3(llib-l,libname,.ln) @@\ | |
85 | @@\ | |
86 | concat3(llib-l,libname,.ln): srcs @@\ | |
87 | $(LINT) concat($(LINTLIBFLAG),libname) $(LINTFLAGS) srcs lintlibs @@\ | |
88 | @@\ | |
89 | clean:: @@\ | |
90 | $(RM) concat3(lib,libname,.a) concat3(lib,libname,_p.a) @@\ | |
91 | $(RM) concat3(llib-l,libname,.ln) @@\ | |
92 | $(RM) objs @@\ | |
93 | $(RM) profiled/?*.o @@\ | |
94 | @@\ | |
95 | install:: @@\ | |
96 | $(INSTALLRAW) -c -m 644 concat3(lib,libname,.a) concat4($(DESTDIR)$(LIBDIR)/,lib,libname,.a) @@\ | |
97 | $(RANLIB) -t concat4($(DESTDIR)$(LIBDIR)/,lib,libname,.a) @@\ | |
98 | $(CHMOD) 444 concat4($(DESTDIR)$(LIBDIR)/,lib,libname,.a) @@\ | |
99 | $(INSTALLRAW) -c -m 644 concat3(lib,libname,_p.a) concat4($(DESTDIR)$(LIBDIR)/,lib,libname,_p.a) @@\ | |
100 | $(RANLIB) -t concat4($(DESTDIR)$(LIBDIR)/,lib,libname,_p.a) @@\ | |
101 | $(CHMOD) 444 concat4($(DESTDIR)$(LIBDIR)/,lib,libname,_p.a) @@\ | |
102 | $(INSTALLFILE) concat3(llib-l,libname,.ln) concat4($(DESTDIR)$(LINTLIBDIR)/,llib-l,libname,.ln) @@\ | |
103 | ||
104 | #else /* !PROFILED_LIBS */ | |
105 | /* | |
106 | * Rule for building objects in libraries. | |
107 | */ | |
108 | ||
109 | #ifdef DEBUG_LIBS | |
110 | /* When debugging, leave symbols alone (don't do LD) */ | |
111 | #define library_obj_rule() @@\ | |
112 | .c.o: @@\ | |
113 | $(CC) -c $(CFLAGS) $*.c | |
114 | #else | |
115 | #define library_obj_rule() @@\ | |
116 | .c.o: @@\ | |
117 | $(CC) -c $(CFLAGS) $*.c @@\ | |
118 | -$(LD) -x -r -o a.out $*.o @@\ | |
119 | $(MV) a.out $*.o | |
120 | #endif | |
121 | ||
122 | #define library_ro_object(cfile) @@\ | |
123 | concat(cfile,.o): concat(cfile,.c) @@\ | |
124 | $(CCRO) -c $(CFLAGS) concat(cfile,.c) @@\ | |
125 | -$(LD) -x -r -o a.out $*.o @@\ | |
126 | $(MV) a.out $*.o | |
127 | ||
128 | #define library_asm_object(ofile,sfile) @@\ | |
129 | ofile: sfile @@\ | |
130 | $(CPP) x.c | $(AS) - @@\ | |
131 | -$(LD) -x -r -o $*.o a.out @@\ | |
132 | $(RM) a.out x.c | |
133 | ||
134 | #define install_library_target(libname,objs,srcs,lintlibs) @@\ | |
135 | @@\ | |
136 | all:: concat3(lib,libname,.a) @@\ | |
137 | all:: concat3(llib-l,libname,.ln) @@\ | |
138 | @@\ | |
139 | concat3(lib,libname,.a): objs @@\ | |
140 | $(RM) $@.bak @@\ | |
141 | -$(MV) $@ $@.bak @@\ | |
142 | $(ARCHIVE) $@ objs @@\ | |
143 | $(RANLIB) $@ @@\ | |
144 | @@\ | |
145 | lint:: concat3(llib-l,libname,.ln) @@\ | |
146 | @@\ | |
147 | concat3(llib-l,libname,.ln): srcs @@\ | |
148 | $(LINT) concat($(LINTLIBFLAG),libname) $(LINTFLAGS) srcs lintlibs @@\ | |
149 | @@\ | |
150 | clean:: @@\ | |
151 | $(RM) concat3(lib,libname,.a) @@\ | |
152 | $(RM) concat3(llib-l,libname,.ln) @@\ | |
153 | $(RM) objs @@\ | |
154 | @@\ | |
155 | install:: @@\ | |
156 | $(INSTALLRAW) -c -m 644 concat3(lib,libname,.a) concat4($(DESTDIR)$(LIBDIR)/,lib,libname,.a) @@\ | |
157 | $(RANLIB) -t concat4($(DESTDIR)$(LIBDIR)/,lib,libname,.a) @@\ | |
158 | $(CHMOD) 444 concat4($(DESTDIR)$(LIBDIR)/,lib,libname,.a) @@\ | |
159 | $(INSTALLFILE) concat3(llib-l,libname,.ln) concat4($(DESTDIR)$(LINTLIBDIR)/,llib-l,libname,.ln) @@\ | |
160 | ||
161 | #endif /* PROFILED_LIBS */ | |
162 | ||
163 | /* | |
164 | * Rule for building utilities (binaries which don't get installed) | |
165 | */ | |
166 | #define genutil(pgm,objs,localdeps,syslibs) @@\ | |
167 | all:: pgm @@\ | |
168 | @@\ | |
169 | pgm: objs localdeps @@\ | |
170 | $(CC) $(CFLAGS) -o $@ objs syslibs @@\ | |
171 | @@\ | |
172 | clean:: @@\ | |
173 | $(RM) pgm objs @@\ | |
174 | ||
175 | /* | |
176 | * Rule for building "generator" programs. | |
177 | */ | |
178 | ||
179 | #define generate(file,pgm,libs) @@\ | |
180 | @@\ | |
181 | pgm: concat(pgm,.c) libs @@\ | |
182 | $(HCC) $(HCFLAGS) -o $@ $@.c libs @@\ | |
183 | @@\ | |
184 | file: pgm @@\ | |
185 | ./pgm file @@\ | |
186 | @@\ | |
187 | clean:: @@\ | |
188 | $(RM) file pgm concat(pgm,.o) | |
189 | ||
190 | #define generate_depend(file,pgm,libs) @@\ | |
191 | generate(file,pgm,libs) @@\ | |
192 | @@\ | |
193 | depend:: file | |
194 | ||
195 | ||
196 | /* | |
197 | * Rule for building test programs (something which is not installed) | |
198 | */ | |
199 | ||
200 | #define test(pgm,locallibs,syslibs) @@\ | |
201 | @@\ | |
202 | all:: pgm @@\ | |
203 | @@\ | |
204 | pgm: concat(pgm,.c) locallibs @@\ | |
205 | $(CC) $(CFLAGS) -o $@ $@.c locallibs syslibs @@\ | |
206 | @@\ | |
207 | clean:: @@\ | |
208 | $(RM) pgm concat(pgm,.o) @@\ | |
209 | ||
210 | /* | |
211 | * Rule for compileing files with "et" | |
212 | */ | |
213 | ||
214 | #ifdef PROFILED_LIBS | |
215 | #define comp_et_prof(tbl) @@\ | |
216 | concat(tbl,.h) concat(tbl,.o): concat(tbl,.et) @@\ | |
217 | $(COMPILE_ET) concat(tbl,.et) -n @@\ | |
218 | $(CC) -c PROF_FLAG concat(tbl,.et.c) @@\ | |
219 | $(MV) concat(tbl,.et.o) concat3(profiled/,tbl,.o) @@\ | |
220 | $(COMPILE_ET) concat(tbl,.et) @@\ | |
221 | clean:: @@\ | |
222 | $(RM) concat(tbl,.o) concat(tbl,.h) @@\ | |
223 | depend:: concat(tbl,.h) | |
224 | #else /* !PROFILED_LIBS */ | |
225 | #define comp_et_prof(tbl) comp_et(tbl) | |
226 | #endif /* PROFILED_LIBS */ | |
227 | ||
228 | #define comp_et(tbl) @@\ | |
229 | concat(tbl,.h) concat(tbl,.o): concat(tbl,.et) @@\ | |
230 | $(COMPILE_ET) concat(tbl,.et) @@\ | |
231 | clean:: @@\ | |
232 | $(RM) concat(tbl,.o) concat(tbl,.h) | |
233 | ||
234 | #define comp_et_depend(src) @@\ | |
235 | comp_et_prof(src) @@\ | |
236 | @@\ | |
237 | depend:: concat(src,.h) | |
238 | ||
239 | #define mk_cmds(tbl) @@\ | |
240 | concat(tbl,.o): concat(tbl,.ct) @@\ | |
241 | $(MAKE_COMMANDS) concat(tbl,.ct) @@\ | |
242 | clean:: @@\ | |
243 | $(RM) concat(tbl,.o) | |
244 | ||
245 | /* | |
246 | * Rule for building some random object module | |
247 | */ | |
248 | ||
249 | #define host_simple_object(obj,src) @@\ | |
250 | obj: src @@\ | |
251 | $(HCC) $(HCFLAGS) -c src @@\ | |
252 | @@\ | |
253 | clean:: @@\ | |
254 | $(RM) obj @@\ | |
255 | ||
256 | #define ro_object(obj,src) @@\ | |
257 | obj: src @@\ | |
258 | $(CCRO) $(CFLAGS) -c src @@\ | |
259 | @@\ | |
260 | clean:: @@\ | |
261 | $(RM) obj @@\ | |
262 | ||
263 | /* | |
264 | * Rule for building some random object module with compile flags and | |
265 | * other dependendcies | |
266 | */ | |
267 | ||
268 | #define host_flag_object(obj,src,flags,localdeps) @@\ | |
269 | obj: src localdeps @@\ | |
270 | $(HCC) $(HCFLAGS) flags -c src @@\ | |
271 | @@\ | |
272 | clean:: @@\ | |
273 | $(RM) obj @@\ | |
274 | ||
275 | #define ro_flag_object(obj,src,flags,localdeps) @@\ | |
276 | obj: src localdeps @@\ | |
277 | $(CCRO) $(CFLAGS) flags -c src @@\ | |
278 | @@\ | |
279 | clean:: @@\ | |
280 | $(RM) obj @@\ | |
281 | ||
282 | /* | |
283 | * Rule for building some random object module with compile flags, an | |
284 | * intermediate output, and some other dependencies | |
285 | */ | |
286 | ||
287 | #define host_cplx_object(obj,interim,src,flags,localdeps) @@\ | |
288 | obj: interim src localdeps @@\ | |
289 | $(HCC) $(HCFLAGS) flags -c src @@\ | |
290 | $(MV) interim obj @@\ | |
291 | @@\ | |
292 | clean:: @@\ | |
293 | $(RM) obj @@\ | |
294 | ||
295 | #define ro_cplx_object(obj,interim,src,flags,localdeps) @@\ | |
296 | obj: src localdeps interim @@\ | |
297 | $(CCRO) $(CFLAGS) flags -c src @@\ | |
298 | $(MV) interim obj @@\ | |
299 | @@\ | |
300 | clean:: @@\ | |
301 | $(RM) obj @@\ | |
302 | ||
303 | /* | |
304 | * Rule for building a program which is to be installed: | |
305 | */ | |
306 | ||
307 | #define program(pgm,objs,localdeps,syslibs,installdir) @@\ | |
308 | all:: pgm @@\ | |
309 | @@\ | |
310 | pgm: localdeps objs @@\ | |
311 | $(CC) $(CFLAGS) -o $@ objs syslibs @@\ | |
312 | @@\ | |
313 | install:: @@\ | |
314 | $(INSTALLPROG) pgm ${DESTDIR}installdir/pgm @@\ | |
315 | @@\ | |
316 | clean:: @@\ | |
317 | $(RM) pgm objs @@\ | |
318 | ||
319 | /* | |
320 | * Rule for building a program which is to be installed setuid root: | |
321 | */ | |
322 | ||
323 | #define suidprogram(pgm,objs,localdeps,syslibs,installdir) @@\ | |
324 | all:: pgm @@\ | |
325 | @@\ | |
326 | pgm: objs localdeps @@\ | |
327 | $(CC) $(CFLAGS) -o $@ objs syslibs @@\ | |
328 | @@\ | |
329 | install:: @@\ | |
330 | $(INSTALLSUID) pgm ${DESTDIR}installdir/pgm @@\ | |
331 | @@\ | |
332 | clean:: @@\ | |
333 | $(RM) pgm objs @@\ | |
334 | ||
335 | /* | |
336 | * Rule for building a specially installed program | |
337 | */ | |
338 | ||
339 | #define program_spinst(pgm,objs,localdeps,syslibs,installdir,instopts) @@\ | |
340 | all:: pgm @@\ | |
341 | @@\ | |
342 | pgm: objs localdeps @@\ | |
343 | $(CC) $(CFLAGS) -o $@ objs syslibs @@\ | |
344 | @@\ | |
345 | install:: @@\ | |
346 | $(INSTALLRAW) instopts pgm ${DESTDIR}installdir/pgm @@\ | |
347 | @@\ | |
348 | clean:: @@\ | |
349 | $(RM) pgm objs @@\ | |
350 | ||
351 | /* | |
352 | * Special rule for building and installing a Berkeley r-command | |
353 | * We need to preserve the original copies upon installation. | |
354 | */ | |
355 | ||
356 | #define ucbprogram(pgm,objs,localdeps,syslibs,installdir) @@\ | |
357 | all:: pgm @@\ | |
358 | @@\ | |
359 | pgm: objs localdeps @@\ | |
360 | $(CC) $(CFLAGS) -o $@ objs syslibs @@\ | |
361 | @@\ | |
362 | install:: @@\ | |
363 | -if [ ! -f concat5(${DESTDIR},installdir,/,pgm,.ucb) -a -f concat4(${DESTDIR},installdir,/,pgm) ]; then \ @@\ | |
364 | mv concat4(${DESTDIR},installdir,/,pgm) concat5(${DESTDIR},installdir,/,pgm,.ucb); fi; exit 0 @@\ | |
365 | $(INSTALLSUID) pgm concat4(${DESTDIR},installdir,/,pgm) @@\ | |
366 | @@\ | |
367 | clean:: @@\ | |
368 | $(RM) pgm objs @@\ | |
369 | ||
370 | ||
371 | /* | |
372 | * Rule for installing man pages. Section installing into should match | |
373 | * suffix, or the man page won't show up when using man(1). | |
374 | */ | |
375 | ||
376 | #define manpage(section,page) @@\ | |
377 | all:: @@\ | |
378 | install:: page @@\ | |
379 | $(INSTALLFILE) page concat4(${DESTDIR}${MANDIR}/man,section,/,`basename page`) @@\ | |
380 | ||
381 | /* | |
382 | * Rule for building makefile dependencies. | |
383 | */ | |
384 | ||
385 | #define depend_target() @@\ | |
386 | depend:: $(SRCS) @@\ | |
387 | @echo "### Now computing dependencies" @@\ | |
388 | @$(DEPEND) -s "# DO NOT DELETE" -- $(CFLAGS) -- $(SRCS) @@\ | |
389 | ||
390 | #define clean_target() @@\ | |
391 | clean:: @@\ | |
392 | $(RM) *~ \#* *.bak $(TAGSFILE) | |
393 | ||
394 | #define tags_target() @@\ | |
395 | tags:: @@\ | |
396 | $(TAGGER) *.c *.h | |
397 | ||
398 | #define makefile_target() @@\ | |
399 | Makefile:: @@\ | |
400 | -$(RM) Makefile.bak; $(MV) Makefile Makefile.bak @@\ | |
401 | $(IMAKE) -DNEW_TOP=$(NEWTOP) -s Makefile @@\ | |
402 | ||
403 | #define foreach_subdirs(name,subdirs) @@\ | |
404 | name:: @@\ | |
405 | @for d in subdirs; \ @@\ | |
406 | do \ @@\ | |
407 | (cd $$d; echo "### Making" name "in" `pwd`; \ @@\ | |
408 | $(MAKE) $(MFLAGS) DESTDIR=$(DESTDIR) name ; \ @@\ | |
409 | echo "### Done with" `pwd`); \ @@\ | |
410 | done | |
411 | ||
412 | #define print_target() @@\ | |
413 | print:: ${CODE} @@\ | |
414 | ${LPR} ${CODE} | |
415 | ||
416 | #define src_target() @@\ | |
417 | src:: ${CODE} @@\ | |
418 | @@\ | |
419 | ${CODE}: @@\ | |
420 | $(RM) $@ @@\ | |
421 | -$(LN) ${SRCDIR}/$@ $@ | |
422 | ||
423 | #define do_subdirs_no_imakefile(subdirs) @@\ | |
424 | foreach_subdirs(all, subdirs) @@\ | |
425 | foreach_subdirs(install, subdirs) @@\ | |
426 | foreach_subdirs(clean, subdirs) @@\ | |
427 | foreach_subdirs(depend, subdirs) @@\ | |
428 | foreach_subdirs(tags, subdirs) @@\ | |
429 | foreach_subdirs(print, subdirs) @@\ | |
430 | foreach_subdirs(src, subdirs) @@\ | |
431 | ||
432 | #define do_subdirs(subdirs) @@\ | |
433 | do_subdirs_no_imakefile(subdirs) @@\ | |
434 | @@\ | |
435 | Makefiles:: @@\ | |
436 | @echo "### Making Makefiles in" `pwd` @@\ | |
437 | @for d in subdirs; \ @@\ | |
438 | do \ @@\ | |
439 | (cd $$d; echo "### Making Makefile in" `pwd`; \ @@\ | |
440 | $(MAKE) $(MFLAGS) SRCTOP=$(SRCTOP) \ @@\ | |
441 | NEWTOP=../$(BUILDTOP) \ @@\ | |
442 | BUILDTOP=../$(BUILDTOP) \ @@\ | |
443 | -f ../Makefile \ @@\ | |
444 | Makefile; \ @@\ | |
445 | $(MAKE) $(MFLAGS) SRCTOP=$(SRCTOP) \ @@\ | |
446 | NEWTOP=../$(BUILDTOP) \ @@\ | |
447 | Makefiles; \ @@\ | |
448 | echo "### Done with" `pwd`); \ @@\ | |
449 | done | |
450 | ||
451 | ||
452 |