]>
Commit | Line | Data |
---|---|---|
b9be51ef | 1 | #ifdef __STDC__ |
2 | #define concat(x,y) x##y | |
3 | #define concat3(x,y,z) x##y##z | |
4 | #define concat4(w,x,y,z) w##x##y##z | |
5 | #define requote(x) #x | |
6 | #else | |
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 requote(x) "x" | |
11 | #endif | |
12 | ||
13 | /* | |
14 | * Rule for building objects in libraries. | |
15 | */ | |
16 | ||
17 | #define library_obj_rule() @@\ | |
18 | .c.o: @@\ | |
19 | $(CC) -p -c $(CFLAGS) $*.c @@\ | |
20 | -$(LD) -X -r -o profiled/$*.o $*.o @@\ | |
21 | $(CC) -c $(CFLAGS) $*.c @@\ | |
22 | -$(LD) -x -r -o a.out $*.o @@\ | |
23 | $(MV) a.out $*.o | |
24 | ||
25 | /* | |
26 | * cc -R breaks profiling with -p on 4.3BSD on the VAX | |
27 | * (and probably elsewhere), so we don't do it for the profiled version. | |
28 | */ | |
29 | ||
30 | #define library_ro_object(cfile) @@\ | |
31 | concat(cfile,.o): concat(cfile,.c) @@\ | |
32 | $(CC) -p -c $(CFLAGS) concat(cfile,.c) @@\ | |
33 | -$(LD) -X -r -o profiled/$*.o $*.o @@\ | |
34 | $(CCRO) -c $(CFLAGS) concat(cfile,.c) @@\ | |
35 | -$(LD) -x -r -o a.out $*.o @@\ | |
36 | $(MV) a.out $*.o | |
37 | ||
38 | #define library_asm_object(ofile,sfile) @@\ | |
39 | ofile: sfile @@\ | |
40 | $(CP) sfile x.c @@\ | |
41 | $(CPP) -DPROF x.c | $(AS) - @@\ | |
42 | -$(LD) -X -r -o profiled/$*.o a.out @@\ | |
43 | $(CPP) x.c | $(AS) - @@\ | |
44 | -$(LD) -x -r -o $*.o a.out @@\ | |
45 | $(RM) a.out x.c | |
46 | ||
47 | #define install_library_target(libname,objs,srcs,lintlibs) @@\ | |
48 | @@\ | |
49 | all:: concat3(lib,libname,.a) concat3(lib,libname,_p.a) @@\ | |
50 | all:: concat3(llib-l,libname,.ln) @@\ | |
51 | @@\ | |
52 | concat3(lib,libname,.a): objs @@\ | |
53 | $(ARCHIVE) $@ objs @@\ | |
54 | $(RANLIB) $@ @@\ | |
55 | @@\ | |
56 | concat3(lib,libname,_p.a): objs @@\ | |
57 | cd profiled; $(ARCHIVE) ../$@ objs @@\ | |
58 | $(RANLIB) $@ @@\ | |
59 | @@\ | |
60 | lint: concat3(llib-l,libname,.ln) @@\ | |
61 | @@\ | |
62 | concat3(llib-l,libname,.ln): srcs @@\ | |
63 | $(LINT) concat(-C,libname) $(CFLAGS) srcs lintlibs @@\ | |
64 | @@\ | |
65 | clean:: @@\ | |
66 | $(RM) concat3(lib,libname,.a) concat3(lib,libname,_p.a) @@\ | |
67 | $(RM) concat3(llib-l,libname,.ln) @@\ | |
68 | $(RM) objs @@\ | |
69 | $(RM) profiled/*.o @@\ | |
70 | @@\ | |
71 | install:: @@\ | |
72 | $(INSTALLFILE) concat3(lib,libname,.a) $(DESTDIR)/$(LIBDIR) @@\ | |
73 | $(RANLIB) concat4($(DESTDIR)/$(LIBDIR),lib,libname,.a) @@\ | |
74 | $(INSTALLFILE) concat3(lib,libname,_p.a) $(DESTDIR)/$(LIBDIR) @@\ | |
75 | $(RANLIB) concat4($(DESTDIR)/$(LIBDIR),lib,libname,_p.a) @@\ | |
76 | $(INSTALLFILE) concat3(llib-l,libname,.ln) $(DESTDIR)/$(LIBDIR)/lint | |
77 | ||
78 | /* | |
79 | * Rule for building utilities (binaries which don't get installed) | |
80 | */ | |
81 | ||
82 | #define genutil(pgm,objs,localdeps,syslibs) @@\ | |
83 | all:: pgm @@\ | |
84 | @@\ | |
85 | pgm: objs localdeps @@\ | |
86 | $(CC) $(CFLAGS) -o $@ objs localdeps syslibs @@\ | |
87 | @@\ | |
88 | clean:: @@\ | |
89 | $(RM) pgm objs @@\ | |
90 | ||
91 | /* | |
92 | * Rule for building "generator" programs. | |
93 | */ | |
94 | ||
95 | #define generate(file,pgm,libs) @@\ | |
96 | @@\ | |
97 | pgm: concat(pgm,.c) libs @@\ | |
98 | $(HCC) $(HCFLAGS) -o $@ $@.c libs @@\ | |
99 | @@\ | |
100 | file: pgm @@\ | |
101 | ./pgm > file @@\ | |
102 | @@\ | |
103 | clean:: @@\ | |
104 | $(RM) file pgm concat(pgm,.o) | |
105 | ||
106 | #define generate_depend(file,pgm,libs) @@\ | |
107 | generate(file,pgm,libs) @@\ | |
108 | @@\ | |
109 | depend:: file | |
110 | ||
111 | ||
112 | /* | |
113 | * Rule for building test programs (something which is not installed) | |
114 | */ | |
115 | ||
116 | #define test(pgm,locallibs,syslibs) @@\ | |
117 | @@\ | |
118 | all:: pgm @@\ | |
119 | @@\ | |
120 | pgm: concat(pgm,.c) locallibs @@\ | |
121 | $(CC) $(CFLAGS) -o $@ $@.c locallibs syslibs @@\ | |
122 | @@\ | |
123 | clean:: @@\ | |
124 | $(RM) pgm concat(pgm,.o) @@\ | |
125 | ||
126 | /* | |
127 | * Rule for building some random object module | |
128 | */ | |
129 | ||
130 | #define host_simple_object(obj,src) @@\ | |
131 | obj: src @@\ | |
132 | $(HCC) $(HCFLAGS) -c src @@\ | |
133 | @@\ | |
134 | clean:: @@\ | |
135 | $(RM) obj @@\ | |
136 | ||
137 | #define ro_object(obj,src) @@\ | |
138 | obj: src @@\ | |
139 | $(CCRO) $(CFLAGS) -c src @@\ | |
140 | @@\ | |
141 | clean:: @@\ | |
142 | $(RM) obj @@\ | |
143 | ||
144 | /* | |
145 | * Rule for building a program which is to be installed: | |
146 | */ | |
147 | ||
148 | #define program(pgm,objs,localdeps,syslibs,installdir) @@\ | |
149 | all:: pgm @@\ | |
150 | @@\ | |
151 | pgm: objs localdeps @@\ | |
152 | $(CC) $(CFLAGS) -o $@ objs localdeps syslibs @@\ | |
153 | @@\ | |
154 | install:: @@\ | |
155 | $(INSTALLPROG) pgm ${DESTDIR}installdir @@\ | |
156 | @@\ | |
157 | clean:: @@\ | |
158 | $(RM) pgm objs @@\ | |
159 | ||
160 | /* | |
161 | * Rule for building a specially installed program | |
162 | */ | |
163 | ||
164 | #define program_spinst(pgm,objs,localdeps,syslibs,installdir,instopts) @@\ | |
165 | all:: pgm @@\ | |
166 | @@\ | |
167 | pgm: objs localdeps @@\ | |
168 | $(CC) $(CFLAGS) -o $@ objs localdeps syslibs @@\ | |
169 | @@\ | |
170 | install:: @@\ | |
171 | $(INSTALLPROG) instopts pgm ${DESTDIR}installdir @@\ | |
172 | @@\ | |
173 | clean:: @@\ | |
174 | $(RM) pgm objs @@\ | |
175 | ||
176 | /* | |
177 | * Rule for installing man pages. | |
178 | */ | |
179 | ||
180 | #define manpage(section,page) @@\ | |
181 | all:: @@\ | |
182 | install:: page @@\ | |
183 | $(INSTALLFILE) page concat3(${DESTDIR}${MANDIR}/man,section,/`basename page`) @@\ | |
184 | ||
185 | /* | |
186 | * Rule for building makefile dependancies. | |
187 | */ | |
188 | ||
189 | #define depend_target() @@\ | |
190 | depend:: $(SRCS) @@\ | |
191 | @echo "### Now computing dependancies" @@\ | |
192 | @$(DEPEND) -s "# DO NOT DELETE" $(CFLAGS) $(SRCS) @@\ | |
193 | ||
194 | #define clean_target() @@\ | |
195 | clean:: @@\ | |
196 | $(RM) *~ \#* *.bak $(TAGSFILE) | |
197 | ||
198 | #define tags_target() @@\ | |
199 | tags:: @@\ | |
200 | $(TAGGER) *.c *.h | |
201 | ||
202 | #define makefile_target() @@\ | |
203 | Makefile:: @@\ | |
204 | -$(RM) Makefile.bak; $(MV) Makefile Makefile.bak @@\ | |
205 | $(IMAKE) -DNEW_TOP=$(NEWTOP) -s Makefile @@\ | |
206 | ||
207 | #define foreach_subdirs(name,subdirs) @@\ | |
208 | name:: @@\ | |
209 | @for d in subdirs; \ @@\ | |
210 | do \ @@\ | |
211 | (cd $$d; echo "### Making" name "in" `pwd`; \ @@\ | |
212 | $(MAKE) $(MFLAGS) name ; \ @@\ | |
213 | echo "### Done with" `pwd`); \ @@\ | |
214 | done | |
215 | ||
216 | #define print_target() @@\ | |
217 | print:: ${CODE} @@\ | |
218 | ${LPR} ${CODE} | |
219 | ||
220 | #define src_target() @@\ | |
221 | src:: ${CODE} @@\ | |
222 | @@\ | |
223 | ${CODE}: @@\ | |
224 | -$(LN) ${SRCDIR}/$@ $@ | |
225 | ||
226 | #define do_subdirs_no_imakefile(subdirs) @@\ | |
227 | foreach_subdirs(all, subdirs) @@\ | |
228 | foreach_subdirs(install, subdirs) @@\ | |
229 | foreach_subdirs(clean, subdirs) @@\ | |
230 | foreach_subdirs(depend, subdirs) @@\ | |
231 | foreach_subdirs(tags, subdirs) @@\ | |
232 | foreach_subdirs(print, subdirs) @@\ | |
233 | foreach_subdirs(src, subdirs) @@\ | |
234 | ||
235 | #define do_subdirs(subdirs) @@\ | |
236 | do_subdirs_no_imakefile(subdirs) @@\ | |
237 | @@\ | |
238 | Makefiles:: @@\ | |
239 | @echo "### Making Makefiles in" `pwd` @@\ | |
240 | @for d in subdirs; \ @@\ | |
241 | do \ @@\ | |
242 | (cd $$d; echo "### Making Makefile in" `pwd`; \ @@\ | |
243 | $(MAKE) $(MFLAGS) SRCTOP=$(SRCTOP) \ @@\ | |
244 | NEWTOP=../$(BUILDTOP) \ @@\ | |
245 | BUILDTOP=../$(BUILDTOP) \ @@\ | |
246 | -f ../Makefile \ @@\ | |
247 | Makefile; \ @@\ | |
248 | $(MAKE) $(MFLAGS) SRCTOP=$(SRCTOP) \ @@\ | |
249 | NEWTOP=../$(BUILDTOP) \ @@\ | |
250 | Makefiles; \ @@\ | |
251 | echo "### Done with" `pwd`); \ @@\ | |
252 | done | |
253 | ||
254 | ||
255 |