summaryrefslogtreecommitdiff
path: root/config/Imake.rules
blob: 2716eaf81af056e28eb68444cfe226338161eeac (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
/* 
 * The following macros are supported
 * ----------------------------------
 * create_dir(dir)			- Create a directory hierarchy
 * AnsiCC()				- Specify desire for ANSI compiling
 * ProfiledObjectRule()			- Build profiled objects/libraries
 * SpecialObject(obj,depends,options)	- Build a special object
 *
 * cmd_table(tbl)			- build a command table module (tbl.ct)
 * error_table(tbl)			- build an error table module (tbl.et)
 *
 * SimpleProgram(prog,objs,libs,dest)	- Build/install a program    (simple)
 * build_program(prog,objs,ldflags,libs)- Build a program            (complex)
 * install_program(prog,instflags,dest)	- Install a program          (complex)
 * install_script(prog,instflags,dest)	- Install a script	     (complex)
 *
 * SimpleLibrary(base,objs,destdir)	- Build/install a library    (simple)
 * build_library(base,objs)		- Build a library
 * install_library(base,dir)		- Install a library
 *
 * SimpleLint(base,srcs)		- Build/install a lint library
 *
 * install_man(src,name)		- Install man page
 * install_man_links(name,links)	- Install man page links
 *
 * install_file(src,dest)		- Install file
 *
 * foreach_subdirs(name,subdirs)	- Make 'name' in subdirs
 * do_subdirs_imakefile(subdirs)	- Make Makefile in subdirs (Athena)
 * do_subdirs_xmakefile(subdirs)	- Make Makefile in subdirs (X-style)
 * do_subdirs(subdirs)			- Make common instances in subdirs
 */

#define concat2(a,b) a/**/b
#define concat3(a,b,c) a/**/b/**/c

#define create_dir(dir)							@@\
install_dirs:: $(DESTDIR)dir						@@\
$(DESTDIR)dir::								@@\
	$(MKDIRHIER) $(DESTDIR)dir

#define build_program(prog,objs,ldflags,libs)				@@\
all::	prog								@@\
prog::	objs								@@\
	$(LD) ldflags $(LDFLAGS) -o prog objs $(LDPATH) libs $(LDLIBS)	@@\
clean::									@@\
	$(RM) prog							@@\

#ifndef static_program
#define static_program(prog,objs,ldflags,libs)				@@\
build_program(prog,objs,ldflags,libs)
#endif

#define install_program(prog,instflags,dest)				@@\
install::								@@\
	$(INSTALL) InstPgmFlags instflags prog $(DESTDIR)dest

#define install_script(prog,instflags,dest)				@@\
install::								@@\
	$(INSTALL) InstScriptFlags instflags prog $(DESTDIR)dest

#define install_file(src,dest)						@@\
install::								@@\
	$(INSTALL) -m 0444 src $(DESTDIR)dest

#define SimpleProgram(prog,objs,libs,dest)				@@\
build_program(prog,objs,,libs)						@@\
install_program(prog,,dest)

#define SpecialObject(obj,depends,options)				@@\
obj: depends								@@\
	$(RM) $@							@@\
	$(CC) -c $(CFLAGS) options $*.c

#define install_man(src,name)						@@\
install.man::								@@\
	base=`expr name \: '\(.*\)\.'`; \				@@\
	ext=`expr name \: '.*\.\(.*\)'`; \				@@\
	sdir=$(DESTDIR)$(ATHMANDIR)/man`expr name \: '.*\.\(.\)'`; \	@@\
	$(INSTALL) -m 0444 src $${sdir}/`basename name`

#define install_man_links(name,links)					@@\
name.so:								@@\
	$(RM) name.so							@@\
	sdir=man`expr name \: '.*\.\(.\)'`; \				@@\
	echo ".so $${sdir}/name" > name.so				@@\
clean::									@@\
	$(RM) name.so							@@\
install.man:: name.so							@@\
	for i in links; do \						@@\
		sdir=$(DESTDIR)$(ATHMANDIR)/man`expr $$i \: '.*\.\(.\)'`;\ @@\
		$(INSTALL) -m 0444 name.so $${sdir}/$$i;\		@@\
	done

#ifdef NOPROF
#define ProfiledObjectRule()
#else
#define ProfiledObjectRule()						@@\
.c.o:									@@\
	$(RM) $@ profiled/$@						@@\
	$(CC) ProfCcFlags -c $(CFLAGS) $*.c				@@\
	mv $*.o profiled/$*.o						@@\
	$(CC) -c $(CFLAGS) $*.c						@@\
all:: profiled all-prof							@@\
install:: inst-prof							@@\
profiled:								@@\
	-mkdir $@
#endif

#define AnsiCC()							@@\
CC=AnsiCcCmd								@@\
LD=AnsiLdCmd

#define error_table(tbl)						@@\
depend:: concat2(tbl,.c) concat2(tbl,.h)				@@\
concat2(tbl,.o): concat2(tbl,.c)					@@\
concat2(tbl,.c) concat2(tbl,.h): concat2(tbl,.et)			@@\
	$(RM) concat2(tbl,.c) concat2(tbl,.h)				@@\
	$(ETCMD) concat2(tbl,.et)					@@\
clean::									@@\
	$(RM) concat2(tbl,.c) concat2(tbl,.h)

#define cmd_table(tbl)							@@\
depend:: concat2(tbl,.c)						@@\
concat2(tbl,.o): concat2(tbl,.c)					@@\
concat2(tbl,.c): concat2(tbl,.ct)					@@\
	$(RM) concat2(tbl,.c) concat2(tbl,.h)				@@\
	$(SSCMD) concat2(tbl,.ct)					@@\
clean::									@@\
	$(RM) concat2(tbl,.c)

#define build_library(base,objs)					@@\
all::	concat3(lib,base,.a)						@@\
concat3(lib,base,.a)::	objs						@@\
	ar cru concat3(lib,base,.a) objs				@@\
	$(RANLIB) concat3(lib,base,.a)					@@\
all-prof:: concat3(lib,base,_p.a)					@@\
concat3(lib,base,_p.a):	objs						@@\
	cd profiled; ar cru concat3(../lib,base,_p.a) objs		@@\
	$(RANLIB) concat3(lib,base,_p.a)

#define install_library(base,dir)					@@\
install::								@@\
	$(RM) concat3($(DESTDIR)dir/lib,base,.a)			@@\
	$(INSTALL) -m 0644 concat3(lib,base,.a) $(DESTDIR)dir		@@\
	$(RANLIB) concat3($(DESTDIR)dir/lib,base,.a)			@@\
inst-prof::								@@\
	$(RM) concat3($(DESTDIR)dir/lib,base,_p.a)			@@\
	$(INSTALL) -m 0644 concat3(lib,base,_p.a) $(DESTDIR)dir		@@\
	$(RANLIB) concat3($(DESTDIR)dir/lib,base,_p.a)

#define SimpleLibrary(base,objs,dir)					@@\
build_library(base,objs)						@@\
install_library(base,dir)


#ifdef NOLINT
#define SimpleLint(base,srcs)
#else
#define SimpleLint(base,srcs)						@@\
all::	concat3(llib-l,base,.ln)					@@\
concat3(llib-l,base,.ln):: srcs						@@\
	LintCmd $(LINTCFLAG)base LintFlags $(LINTFLAGS) srcs		@@\
install::								@@\
	$(INSTALL) concat3(llib-l,base,.ln) $(DESTDIR)/usr/lib/lint/	@@\
clean::									@@\
	$(RM) concat3(llib-l,base,.ln)
#endif

#define makefile_target()						@@\
Makefile:: $(ICONFIGFILES)						@@\
	-@if [ -f Makefile ]; then \                                    @@\
        	echo "  $(RM) Makefile.bak; mv Makefile Makefile.bak"; \ @@\
		$(RM) Makefile.bak; mv Makefile Makefile.bak; \		@@\
        else exit 0; fi                                                 @@\
	$(IMAKE) $(IPROJ) $(IFLAGS) -DNEWTOP=$(TOP) -DNEWCWD=$(CWD) @@\
									@@\
XMakefile::								@@\
	-@if [ -f Makefile ]; then \                                    @@\
        	echo "  $(RM) Makefile.bak; mv Makefile Makefile.bak"; \ @@\
		$(RM) Makefile.bak; mv Makefile Makefile.bak; \		@@\
        else exit 0; fi                                                 @@\
	$(IMAKE) $(XIFLAGS)


#define foreach_subdirs_flags(name,subdirs,flgs)			@@\
name:: FRC								@@\
	@for d in subdirs; \						@@\
	do \								@@\
		(cd $$d; echo "### Making" name "in $(CWD)/$$d"; \	@@\
			make $(MFLAGS) flgs DESTDIR=$(DESTDIR) name; \	@@\
			echo "### Done with $(CWD)/$$d"); \		@@\
	done

#define do_subdirs_flags(subdirs,flgs)					@@\
	foreach_subdirs_flags(all, subdirs, flgs)			@@\
	foreach_subdirs_flags(install, subdirs, flgs)			@@\
	foreach_subdirs_flags(clean, subdirs, flgs)			@@\
	foreach_subdirs_flags(depend, subdirs, flgs)			@@\
subdirs:: FRC								@@\
	@(cd $@; echo "### Making" all "in $(CWD)/$@"; \		@@\
		make $(MFLAGS) flgs DESTDIR=$(DESTDIR) all ; \		@@\
		echo "### Done with $(CWD)/$@")

#define foreach_subdirs(name,subdirs)					@@\
	foreach_subdirs_flags(name,subdirs,)

#define do_subdirs(subdirs)						@@\
	do_subdirs_flags(subdirs,)

#define do_subdirs_imakefile(subdirs)					@@\
	foreach_subdirs(install.man, subdirs)				@@\
Makefiles:: Makefile							@@\
	@echo "### Making Makefiles in $(CWD)"				@@\
	@-for d in subdirs; \						@@\
	do \								@@\
		case "$$d" in \						@@\
                ./?*/?*/?*/?*)	newtop=../../../.. ;; \			@@\
                ./?*/?*/?*)	newtop=../../.. ;; \			@@\
                ./?*/?*)	newtop=../.. ;; \			@@\
                ./?*)		newtop=.. ;; \				@@\
                */?*/?*/?*)	newtop=../../../.. ;; \			@@\
                */?*/?*)	newtop=../../.. ;; \			@@\
                */?*)		newtop=../.. ;; \			@@\
                *)		newtop=.. ;; \				@@\
                esac; \							@@\
		( cd $$d; \						@@\
		  echo "### Making Makefile in $(CWD)/$$d"; \		@@\
		  if [ -f Makefile ]; then \				@@\
			$(RM) Makefile.bak; \				@@\
		 	mv Makefile Makefile.bak; fi; \			@@\
		  make -f $${newtop}/Makefile TOP=$${newtop}/$(TOP) \	@@\
			CWD=$(CWD)/$$d Makefile; \			@@\
		  make $(MFLAGS) Makefiles; \				@@\
		  echo "### Done with $(CWD)/$$d" ) ; \			@@\
	done

#define do_subdirs_xmakefile(subdirs)					@@\
	foreach_subdirs(install.man,subdirs)				@@\
Makefiles:: Makefile							@@\
	@echo "### Making Makefiles in $(CWD)"				@@\
	@-for d in subdirs; \						@@\
	do \								@@\
		case "$$d" in \						@@\
                ./?*/?*/?*/?*)	newtop=../../../.. ;; \			@@\
                ./?*/?*/?*)	newtop=../../.. ;; \			@@\
                ./?*/?*)	newtop=../.. ;; \			@@\
                ./?*)		newtop=.. ;; \				@@\
                */?*/?*/?*)	newtop=../../../.. ;; \			@@\
                */?*/?*)	newtop=../../.. ;; \			@@\
                */?*)		newtop=../.. ;; \			@@\
                *)		newtop=.. ;; \				@@\
                esac; \							@@\
		( cd $$d; \						@@\
		  echo "### Making Makefile in $(CWD)/$$d"; \		@@\
		  if [ -f Makefile ]; then \				@@\
			$(RM) Makefile.bak; \				@@\
		 	mv Makefile Makefile.bak; fi; \			@@\
		  make -f $${newtop}/Makefile TOP=$${newtop}/$(TOP) \	@@\
			CWD=$(CWD)/$$d XMakefile; \			@@\
		  make $(MFLAGS) Makefiles; \				@@\
		  echo "### Done with $(CWD)/$$d" ) ; \			@@\
	done

#define create_depend(files)						@@\
depend:: files								@@\
	makedepend $(CFLAGS) files