]>
Commit | Line | Data |
---|---|---|
2e387221 | 1 | /**/# $Source$ |
2 | /**/# $Author$ | |
3 | /**/# $Header$ | |
4 | /**/# | |
5 | ||
b9be51ef | 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 | |
83791534 | 10 | #define concat5(v,w,x,y,z) v##w##x##y##z |
b9be51ef | 11 | #define requote(x) #x |
12 | #else | |
df897414 | 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 | |
83791534 | 16 | #define concat5(v,w,x,y,z)v/**/w/**/x/**/y/**/z |
b9be51ef | 17 | #define requote(x) "x" |
18 | #endif | |
19 | ||
df897414 | 20 | #ifdef PROFILED_LIBS |
b9be51ef | 21 | /* |
22 | * Rule for building objects in libraries. | |
23 | */ | |
24 | ||
bb64d499 | 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 */ | |
b9be51ef | 37 | #define library_obj_rule() @@\ |
38 | .c.o: @@\ | |
df897414 | 39 | $(CC) PROF_FLAG -c $(CFLAGS) $*.c @@\ |
b9be51ef | 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 | |
bb64d499 | 44 | #endif /* mips */ |
b9be51ef | 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) @@\ | |
df897414 | 52 | $(CC) PROF_FLAG -c $(CFLAGS) concat(cfile,.c) @@\ |
b9be51ef | 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 @@\ | |
d1e9e56b | 73 | $(RM) $@.bak @@\ |
74 | -$(MV) $@ $@.bak @@\ | |
b9be51ef | 75 | $(ARCHIVE) $@ objs @@\ |
76 | $(RANLIB) $@ @@\ | |
77 | @@\ | |
78 | concat3(lib,libname,_p.a): objs @@\ | |
d1e9e56b | 79 | $(RM) $@.bak @@\ |
80 | -$(MV) $@ $@.bak @@\ | |
b9be51ef | 81 | cd profiled; $(ARCHIVE) ../$@ objs @@\ |
82 | $(RANLIB) $@ @@\ | |
83 | @@\ | |
2e387221 | 84 | lint:: concat3(llib-l,libname,.ln) @@\ |
b9be51ef | 85 | @@\ |
86 | concat3(llib-l,libname,.ln): srcs @@\ | |
322efbe6 | 87 | $(LINT) concat($(LINTLIBFLAG),libname) $(LINTFLAGS) srcs lintlibs @@\ |
b9be51ef | 88 | @@\ |
89 | clean:: @@\ | |
90 | $(RM) concat3(lib,libname,.a) concat3(lib,libname,_p.a) @@\ | |
91 | $(RM) concat3(llib-l,libname,.ln) @@\ | |
92 | $(RM) objs @@\ | |
df897414 | 93 | $(RM) profiled/?*.o @@\ |
b9be51ef | 94 | @@\ |
95 | install:: @@\ | |
f111b4b2 | 96 | $(INSTALLRAW) -c -m 644 concat3(lib,libname,.a) concat4($(DESTDIR)$(LIBDIR)/,lib,libname,.a) @@\ |
f9d599c8 | 97 | $(RANLIB) -t concat4($(DESTDIR)$(LIBDIR)/,lib,libname,.a) @@\ |
93fe6c95 | 98 | $(CHMOD) 444 concat4($(DESTDIR)$(LIBDIR)/,lib,libname,.a) @@\ |
f111b4b2 | 99 | $(INSTALLRAW) -c -m 644 concat3(lib,libname,_p.a) concat4($(DESTDIR)$(LIBDIR)/,lib,libname,_p.a) @@\ |
f9d599c8 | 100 | $(RANLIB) -t concat4($(DESTDIR)$(LIBDIR)/,lib,libname,_p.a) @@\ |
93fe6c95 | 101 | $(CHMOD) 444 concat4($(DESTDIR)$(LIBDIR)/,lib,libname,_p.a) @@\ |
f9d599c8 | 102 | $(INSTALLFILE) concat3(llib-l,libname,.ln) concat4($(DESTDIR)$(LINTLIBDIR)/,llib-l,libname,.ln) @@\ |
b9be51ef | 103 | |
df897414 | 104 | #else /* !PROFILED_LIBS */ |
105 | /* | |
106 | * Rule for building objects in libraries. | |
107 | */ | |
108 | ||
d56d6311 | 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 | |
df897414 | 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 | |
d56d6311 | 120 | #endif |
df897414 | 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 @@\ | |
d1e9e56b | 140 | $(RM) $@.bak @@\ |
141 | -$(MV) $@ $@.bak @@\ | |
df897414 | 142 | $(ARCHIVE) $@ objs @@\ |
143 | $(RANLIB) $@ @@\ | |
144 | @@\ | |
145 | lint:: concat3(llib-l,libname,.ln) @@\ | |
146 | @@\ | |
147 | concat3(llib-l,libname,.ln): srcs @@\ | |
322efbe6 | 148 | $(LINT) concat($(LINTLIBFLAG),libname) $(LINTFLAGS) srcs lintlibs @@\ |
df897414 | 149 | @@\ |
150 | clean:: @@\ | |
151 | $(RM) concat3(lib,libname,.a) @@\ | |
152 | $(RM) concat3(llib-l,libname,.ln) @@\ | |
153 | $(RM) objs @@\ | |
154 | @@\ | |
155 | install:: @@\ | |
f111b4b2 | 156 | $(INSTALLRAW) -c -m 644 concat3(lib,libname,.a) concat4($(DESTDIR)$(LIBDIR)/,lib,libname,.a) @@\ |
df897414 | 157 | $(RANLIB) -t concat4($(DESTDIR)$(LIBDIR)/,lib,libname,.a) @@\ |
93fe6c95 | 158 | $(CHMOD) 444 concat4($(DESTDIR)$(LIBDIR)/,lib,libname,.a) @@\ |
c87509c1 | 159 | $(INSTALLFILE) concat3(llib-l,libname,.ln) concat4($(DESTDIR)$(LINTLIBDIR)/,llib-l,libname,.ln) @@\ |
df897414 | 160 | |
161 | #endif /* PROFILED_LIBS */ | |
162 | ||
b9be51ef | 163 | /* |
164 | * Rule for building utilities (binaries which don't get installed) | |
165 | */ | |
b9be51ef | 166 | #define genutil(pgm,objs,localdeps,syslibs) @@\ |
167 | all:: pgm @@\ | |
168 | @@\ | |
169 | pgm: objs localdeps @@\ | |
83791534 | 170 | $(CC) $(CFLAGS) -o $@ objs syslibs @@\ |
b9be51ef | 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 @@\ | |
7caabe5f | 185 | ./pgm file @@\ |
b9be51ef | 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 | ||
7caabe5f | 210 | /* |
211 | * Rule for compileing files with "et" | |
212 | */ | |
213 | ||
df897414 | 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) @@\ | |
7caabe5f | 221 | clean:: @@\ |
bb64d499 | 222 | $(RM) concat(tbl,.o) concat(tbl,.h) @@\ |
223 | depend:: concat(tbl,.h) | |
df897414 | 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:: @@\ | |
bb64d499 | 232 | $(RM) concat(tbl,.o) concat(tbl,.h) |
7caabe5f | 233 | |
234 | #define comp_et_depend(src) @@\ | |
bb64d499 | 235 | comp_et_prof(src) @@\ |
7caabe5f | 236 | @@\ |
df897414 | 237 | depend:: concat(src,.h) |
7caabe5f | 238 | |
7b74aba1 | 239 | #define mk_cmds(tbl) @@\ |
240 | concat(tbl,.o): concat(tbl,.ct) @@\ | |
241 | $(MAKE_COMMANDS) concat(tbl,.ct) @@\ | |
242 | clean:: @@\ | |
bb64d499 | 243 | $(RM) concat(tbl,.o) |
7b74aba1 | 244 | |
b9be51ef | 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 | ||
2e387221 | 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) @@\ | |
7caabe5f | 288 | obj: interim src localdeps @@\ |
2e387221 | 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) @@\ | |
7caabe5f | 296 | obj: src localdeps interim @@\ |
2e387221 | 297 | $(CCRO) $(CFLAGS) flags -c src @@\ |
298 | $(MV) interim obj @@\ | |
299 | @@\ | |
300 | clean:: @@\ | |
301 | $(RM) obj @@\ | |
302 | ||
b9be51ef | 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 | @@\ | |
7caabe5f | 310 | pgm: localdeps objs @@\ |
311 | $(CC) $(CFLAGS) -o $@ objs syslibs @@\ | |
b9be51ef | 312 | @@\ |
313 | install:: @@\ | |
2e387221 | 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 @@\ | |
f9d599c8 | 327 | $(CC) $(CFLAGS) -o $@ objs syslibs @@\ |
2e387221 | 328 | @@\ |
329 | install:: @@\ | |
330 | $(INSTALLSUID) pgm ${DESTDIR}installdir/pgm @@\ | |
b9be51ef | 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 @@\ | |
f9d599c8 | 343 | $(CC) $(CFLAGS) -o $@ objs syslibs @@\ |
b9be51ef | 344 | @@\ |
345 | install:: @@\ | |
2e387221 | 346 | $(INSTALLRAW) instopts pgm ${DESTDIR}installdir/pgm @@\ |
b9be51ef | 347 | @@\ |
348 | clean:: @@\ | |
349 | $(RM) pgm objs @@\ | |
350 | ||
83791534 | 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:: @@\ | |
c87509c1 | 363 | -if [ ! -f concat5(${DESTDIR},installdir,/,pgm,.ucb) -a -f concat4(${DESTDIR},installdir,/,pgm) ]; then \ @@\ |
83791534 | 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 | ||
b9be51ef | 371 | /* |
2e387221 | 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). | |
b9be51ef | 374 | */ |
375 | ||
376 | #define manpage(section,page) @@\ | |
377 | all:: @@\ | |
378 | install:: page @@\ | |
28580807 | 379 | $(INSTALLFILE) page concat4(${DESTDIR}${MANDIR}/man,section,/,`basename page`) @@\ |
b9be51ef | 380 | |
381 | /* | |
2e387221 | 382 | * Rule for building makefile dependencies. |
b9be51ef | 383 | */ |
384 | ||
385 | #define depend_target() @@\ | |
386 | depend:: $(SRCS) @@\ | |
2e387221 | 387 | @echo "### Now computing dependencies" @@\ |
322efbe6 | 388 | @$(DEPEND) -s "# DO NOT DELETE" -- $(CFLAGS) -- $(SRCS) @@\ |
b9be51ef | 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`; \ @@\ | |
7caabe5f | 408 | $(MAKE) $(MFLAGS) DESTDIR=$(DESTDIR) name ; \ @@\ |
b9be51ef | 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}: @@\ | |
719b9402 | 420 | $(RM) $@ @@\ |
b9be51ef | 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 |