correctly depend on dispatch.h
[riscv-isa-sim.git] / Makefile.in
1 #=========================================================================
2 # Toplevel Makefile for the Modular C++ Build System
3 #=========================================================================
4 # Please read the documenation in 'mcppbs-doc.txt' for more details on
5 # how the Modular C++ Build System works. For most projects, a developer
6 # will not need to make any changes to this makefile. The key targets
7 # are as follows:
8 #
9 # - default : build all libraries and programs
10 # - check : build and run all unit tests
11 # - install : install headers, project library, and some programs
12 # - clean : remove all generated content (except autoconf files)
13 # - dist : make a source tarball
14 # - distcheck : make a source tarball, untar it, check it, clean it
15 # - distclean : remove everything
16 #
17
18 #-------------------------------------------------------------------------
19 # Basic setup
20 #-------------------------------------------------------------------------
21
22 # Remove all default implicit rules since they can cause subtle bugs
23 # and they just make things run slower
24 .SUFFIXES:
25 % : %,v
26 % : RCS/%,v
27 % : RCS/%
28 % : s.%
29 % : SCCS/s.%
30
31 # Default is to build the prereqs of the all target (defined at bottom)
32 default : all
33 .PHONY : default
34
35 project_name := @PACKAGE_TARNAME@
36 src_dir := @srcdir@
37 scripts_dir := $(src_dir)/scripts
38
39 # If the version information is not in the configure script, then we
40 # assume that we are in a working directory. We use the vcs-version.sh
41 # script in the scripts directory to generate an appropriate version
42 # string. Currently the way things are setup we have to run this script
43 # everytime we run make so the script needs to be as fast as possible.
44
45 ifeq (@PACKAGE_VERSION@,?)
46 project_ver:=$(shell $(scripts_dir)/vcs-version.sh $(src_dir))
47 else
48 project_ver:=@PACKAGE_VERSION@
49 endif
50
51 # Installation directories
52
53 prefix := @prefix@
54 enable_stow := @enable_stow@
55
56 ifeq ($(enable_stow),yes)
57 stow_pkg_dir := $(prefix)/pkgs
58 DESTDIR ?= $(stow_pkg_dir)/$(project_name)-$(project_ver)
59 else
60 DESTDIR ?= $(prefix)
61 endif
62
63 install_hdrs_dir := $(DESTDIR)/include/$(project_name)
64 install_libs_dir := $(DESTDIR)/lib/$(project_name)
65 install_exes_dir := $(DESTDIR)/bin
66
67 #-------------------------------------------------------------------------
68 # List of subprojects
69 #-------------------------------------------------------------------------
70
71 sprojs := @subprojects@
72 sprojs_enabled := @subprojects_enabled@
73
74 sprojs_include := -I. $(addprefix -I$(src_dir)/, $(sprojs_enabled))
75 VPATH := $(addprefix $(src_dir)/, $(sprojs_enabled))
76
77 #-------------------------------------------------------------------------
78 # Programs and flags
79 #-------------------------------------------------------------------------
80
81 # C++ compiler
82 # - CPPFLAGS : flags for the preprocessor (eg. -I,-D)
83 # - CXXFLAGS : flags for C++ compiler (eg. -Wall,-g,-O3)
84
85 CC := @CC@
86 CXX := @CXX@
87 CFLAGS += @CFLAGS@
88 CPPFLAGS += @CPPFLAGS@
89 CXXFLAGS += @CXXFLAGS@
90 COMPILE := $(CXX) -MMD -MP $(CPPFLAGS) $(CFLAGS) $(CXXFLAGS) \
91 $(sprojs_include)
92 COMPILE_C := $(CC) -MMD -MP $(CPPFLAGS) $(CFLAGS) \
93 $(sprojs_include)
94 # Linker
95 # - LDFLAGS : Flags for the linker (eg. -L)
96 # - LIBS : Library flags (eg. -l)
97
98 LD := $(CXX)
99 LDFLAGS := @LDFLAGS@
100 LIBS := @LIBS@
101 LINK := $(LD) $(LDFLAGS)
102
103 # Library creation
104
105 AR := @AR@
106 RANLIB := @RANLIB@
107
108 # Host simulator
109
110 RUN := @RUN@
111 RUNFLAGS := @RUNFLAGS@
112
113 # Installation
114
115 MKINSTALLDIRS := $(scripts_dir)/mk-install-dirs.sh
116 INSTALL := @INSTALL@
117 INSTALL_HDR := $(INSTALL) -m 444
118 INSTALL_LIB := $(INSTALL) -m 644
119 INSTALL_EXE := $(INSTALL) -m 555
120 STOW := @stow@
121
122 #-------------------------------------------------------------------------
123 # Include subproject makefile fragments
124 #-------------------------------------------------------------------------
125
126 sprojs_mk = $(addsuffix .mk, $(sprojs_enabled))
127
128 -include $(sprojs_mk)
129
130 dist_junk += $(sprojs_mk)
131
132 #-------------------------------------------------------------------------
133 # Reverse list helper function
134 #-------------------------------------------------------------------------
135 # This function is used by the subproject template to reverse the list
136 # of dependencies. It uses recursion to perform the reversal.
137 #
138 # Arguments:
139 # $(1) : space separated input list
140 # retval : input list in reverse order
141 #
142
143 reverse_list = $(call reverse_list_h,$(1),)
144 define reverse_list_h
145 $(if $(strip $(1)), \
146 $(call reverse_list_h, \
147 $(wordlist 2,$(words $(1)),$(1)), \
148 $(firstword $(1)) $(2)), \
149 $(2))
150 endef
151
152 #-------------------------------------------------------------------------
153 # Template for per subproject rules
154 #-------------------------------------------------------------------------
155 # The template is instantiated for each of the subprojects. It relies on
156 # subprojects defining a certain set of make variables which are all
157 # prefixed with the subproject name. Since subproject names can have
158 # dashes in them (and the make variables are assumed to only use
159 # underscores) the template takes two arguments - one with the regular
160 # subproject name and one with dashes replaced with underscores.
161 #
162 # Arguments:
163 # $(1) : real subproject name (ie with dashes)
164 # $(2) : normalized subproject name (ie dashes replaced with underscores)
165 #
166
167 define subproject_template
168
169 # In some (rare) cases, a subproject might not have any actual object
170 # files. It might only include header files or program sources. To keep
171 # things consistent we still want a library for this subproject, so in
172 # this spectial case we create a dummy source file and thus the build
173 # system will create a library for this subproject with just the
174 # corresponding dummy object file.
175
176 ifeq ($$(strip $$($(2)_srcs) $$($(2)_c_srcs)),)
177 $(2)_srcs += _$(1).cc
178 $(2)_junk += _$(1).cc
179 endif
180
181 _$(1).cc :
182 echo "int _$(2)( int arg ) { return arg; }" > $$@
183
184 # Build the object files for this subproject
185
186 $(2)_objs := $$(patsubst %.cc, %.o, $$($(2)_srcs))
187 $(2)_c_objs := $$(patsubst %.c, %.o, $$($(2)_c_srcs))
188 $(2)_deps := $$(patsubst %.o, %.d, $$($(2)_objs))
189 $(2)_c_deps := $$(patsubst %.o, %.d, $$($(2)_c_objs))
190 $$($(2)_objs) : %.o : %.cc
191 $(COMPILE) -c $$<
192 $$($(2)_c_objs) : %.o : %.c
193 $(COMPILE_C) -c $$<
194
195 $(2)_junk += $$($(2)_objs) $$($(2)_c_objs) $$($(2)_deps) $$($(2)_c_deps)
196
197 # Build a library for this subproject
198
199 lib$(1).a : $$($(2)_objs) $$($(2)_c_objs)
200 $(AR) rcv $$@ $$^
201 $(RANLIB) $$@
202
203 $(2)_junk += lib$(1).a
204
205 # Reverse the dependency list so that a given subproject only depends on
206 # subprojects listed to its right. This is the correct order for linking
207 # the list of subproject libraries.
208
209 $(2)_reverse_deps := $$(call reverse_list,$$($(2)_subproject_deps))
210
211 # Build unit tests
212
213 $(2)_test_objs := $$(patsubst %.cc, %.o, $$($(2)_test_srcs))
214 $(2)_test_deps := $$(patsubst %.o, %.d, $$($(2)_test_objs))
215 $(2)_test_exes := $$(patsubst %.t.cc, %-utst, $$($(2)_test_srcs))
216 $(2)_test_outs := $$(patsubst %, %.out, $$($(2)_test_exes))
217 $(2)_test_libs := $(1) $$($(2)_reverse_deps) utst
218 $(2)_test_libnames := $$(patsubst %, lib%.a, $$($(2)_test_libs))
219 $(2)_test_libarg := -L. $$(patsubst %, -l%, $$($(2)_test_libs))
220
221 $$($(2)_test_objs) : %.o : %.cc
222 $(COMPILE) -c $$<
223
224 $$($(2)_test_exes) : %-utst : %.t.o $$($(2)_test_libnames)
225 $(LINK) -o $$@ $$< $$($(2)_test_libarg) $(LIBS)
226
227 $(2)_deps += $$($(2)_test_deps)
228 $(2)_junk += \
229 $$($(2)_test_objs) $$($(2)_test_deps) \
230 $$($(2)_test_exes) *.junk-dat
231
232 # Run unit tests
233
234 $$($(2)_test_outs) : %.out : %
235 $(RUN) $(RUNFLAGS) ./$$< default | tee $$@
236
237 $(2)_junk += $$($(2)_test_outs)
238
239 # Build programs
240
241 $(2)_prog_objs := $$(patsubst %.cc, %.o, $$($(2)_prog_srcs))
242 $(2)_prog_deps := $$(patsubst %.o, %.d, $$($(2)_prog_objs))
243 $(2)_prog_exes := $$(patsubst %.cc, %, $$($(2)_prog_srcs))
244 $(2)_prog_libs := $(1) $$($(2)_reverse_deps)
245 $(2)_prog_libnames := $$(patsubst %, lib%.a, $$($(2)_prog_libs))
246 $(2)_prog_libarg := -L. $$(patsubst %, -l%, $$($(2)_prog_libs))
247
248 $$($(2)_prog_objs) : %.o : %.cc
249 $(COMPILE) -c $$<
250
251 $$($(2)_prog_exes) : % : %.o $$($(2)_prog_libnames)
252 $(LINK) -o $$@ $$< $$($(2)_prog_libarg) $(LIBS)
253
254 $(2)_deps += $$($(2)_prog_deps)
255 $(2)_junk += $$($(2)_prog_objs) $$($(2)_prog_deps) $$($(2)_prog_exes)
256
257 # Build programs which will be installed
258
259 $(2)_install_prog_objs := $$(patsubst %.cc, %.o, $$($(2)_install_prog_srcs))
260 $(2)_install_prog_deps := $$(patsubst %.o, %.d, $$($(2)_install_prog_objs))
261 $(2)_install_prog_exes := $$(patsubst %.cc, %, $$($(2)_install_prog_srcs))
262
263 $$($(2)_install_prog_objs) : %.o : %.cc
264 $(COMPILE) -c $$<
265
266 $$($(2)_install_prog_exes) : % : %.o $$($(2)_prog_libnames)
267 $(LINK) -o $$@ $$< $$($(2)_prog_libarg) $(LIBS)
268
269 $(2)_deps += $$($(2)_install_prog_deps)
270 $(2)_junk += \
271 $$($(2)_install_prog_objs) $$($(2)_install_prog_deps) \
272 $$($(2)_install_prog_exes)
273
274 # Subproject specific targets
275
276 all-$(1) : lib$(1).a $$($(2)_install_prog_exes)
277
278 check-$(1) : $$($(2)_test_outs)
279 echo; grep -h -e'Unit Tests' -e'FAILED' -e'Segementation' $$^; echo
280
281 clean-$(1) :
282 rm -rf $$($(2)_junk)
283
284 .PHONY : all-$(1) check-$(1) clean-$(1)
285
286 # Update running variables
287
288 libs += lib$(1).a
289 objs += $$($(2)_objs)
290 srcs += $$(addprefix $(src_dir)/$(1)/, $$($(2)_srcs))
291 hdrs += $$(addprefix $(src_dir)/$(1)/, $$($(2)_hdrs))
292 junk += $$($(2)_junk)
293 deps += $$($(2)_deps)
294
295 test_outs += $$($(2)_test_outs)
296
297 install_hdrs += $$(addprefix $(src_dir)/$(1)/, $$($(2)_hdrs))
298 install_libs += lib$(1).a
299 install_exes += $$($(2)_install_prog_exes)
300
301 endef
302
303 # Iterate over the subprojects and call the template for each one
304
305 $(foreach sproj,$(sprojs_enabled), \
306 $(eval $(call subproject_template,$(sproj),$(subst -,_,$(sproj)))))
307
308 #-------------------------------------------------------------------------
309 # Autodependency files
310 #-------------------------------------------------------------------------
311
312 -include $(deps)
313
314 deps : $(deps)
315 .PHONY : deps
316
317 #-------------------------------------------------------------------------
318 # Check
319 #-------------------------------------------------------------------------
320
321 check : $(test_outs)
322 echo; grep -h -e'Unit Tests' -e'FAILED' -e'Segementation' $^; echo
323
324 .PHONY : check
325
326 #-------------------------------------------------------------------------
327 # Installation
328 #-------------------------------------------------------------------------
329
330 install-hdrs : $(install_hdrs)
331 $(MKINSTALLDIRS) $(install_hdrs_dir)
332 for file in $^; \
333 do \
334 $(INSTALL_HDR) $$file $(install_hdrs_dir); \
335 done
336
337 install-libs : $(install_libs)
338 $(MKINSTALLDIRS) $(install_libs_dir)
339 for file in $^; \
340 do \
341 $(INSTALL_LIB) $$file $(install_libs_dir); \
342 done
343
344 install-exes : $(install_exes)
345 $(MKINSTALLDIRS) $(install_exes_dir)
346 for file in $^; \
347 do \
348 $(INSTALL_EXE) $$file $(install_exes_dir); \
349 done
350
351 install : install-hdrs install-libs install-exes
352 ifeq ($(enable_stow),yes)
353 $(MKINSTALLDIRS) $(stow_pkg_dir)
354 cd $(stow_pkg_dir) && \
355 $(STOW) --delete $(project_name)-* && \
356 $(STOW) $(project_name)-$(project_ver)
357 endif
358
359 .PHONY : install install-hdrs install-libs install-exes
360
361 #-------------------------------------------------------------------------
362 # Regenerate configure information
363 #-------------------------------------------------------------------------
364
365 configure_prereq = \
366 $(src_dir)/configure.ac \
367 $(src_dir)/aclocal.m4 \
368 $(join $(addprefix $(src_dir)/, $(sprojs_enabled)), \
369 $(patsubst %, /%.ac, $(sprojs_enabled)))
370
371 $(src_dir)/configure : $(configure_prereq)
372 cd $(src_dir) && autoconf && autoheader
373
374 config.status : $(src_dir)/configure
375 ./config.status --recheck
376
377 sprojs_mk_in = \
378 $(join $(addprefix $(src_dir)/, $(sprojs_enabled)), \
379 $(patsubst %, /%.mk.in, $(sprojs_enabled)))
380
381 Makefile : $(src_dir)/Makefile.in $(sprojs_mk_in) config.status
382 ./config.status
383
384 dist_junk += config.status config.h Makefile config.log
385
386 #-------------------------------------------------------------------------
387 # Distribution
388 #-------------------------------------------------------------------------
389 # The distribution tarball is named project-ver.tar.gz and it includes
390 # both enabled and disabled subprojects.
391
392 dist_files = \
393 $(sprojs) \
394 README \
395 style-guide.txt \
396 mcppbs-uguide.txt \
397 scripts \
398 configure.ac \
399 aclocal.m4 \
400 configure \
401 config.h.in \
402 Makefile.in \
403
404 dist_dir := $(project_name)-$(project_ver)
405 dist_tgz := $(project_name)-$(project_ver).tar.gz
406
407 # Notice that when we make the distribution we rewrite the configure.ac
408 # script with the current version and we rerun autoconf in the new
409 # source directory so that the distribution will have the proper version
410 # information. We also rewrite the "Version : " line in the README.
411
412 dist :
413 rm -rf $(dist_dir)
414 mkdir $(dist_dir)
415 tar -C $(src_dir) -cf - $(dist_files) | tar -C $(dist_dir) -xpf -
416 sed -i.bak 's/^\(# Version :\).*/\1 $(project_ver)/' $(dist_dir)/README
417 sed -i.bak 's/\( proj_version,\).*/\1 [$(project_ver)])/' $(dist_dir)/configure.ac
418 cd $(dist_dir) && \
419 autoconf && autoheader && \
420 rm -rf autom4te.cache configure.ac.bak README.bak
421 tar -czvf $(dist_tgz) $(dist_dir)
422 rm -rf $(dist_dir)
423
424 # You can use the distcheck target to try untarring the distribution and
425 # then running configure, make, make check, and make distclean. A
426 # "directory is not empty" error means distclean is not removing
427 # everything.
428
429 distcheck : dist
430 rm -rf $(dist_dir)
431 tar -xzvf $(dist_tgz)
432 mkdir -p $(dist_dir)/build
433 cd $(dist_dir)/build; ../configure; make; make check; make distclean
434 rm -rf $(dist_dir)
435
436 junk += $(project_name)-*.tar.gz
437
438 .PHONY : dist distcheck
439
440 #-------------------------------------------------------------------------
441 # Default
442 #-------------------------------------------------------------------------
443
444 all : $(install_hdrs) $(install_libs) $(install_exes)
445 .PHONY : all
446
447 #-------------------------------------------------------------------------
448 # Makefile debugging
449 #-------------------------------------------------------------------------
450 # This handy rule will display the contents of any make variable by
451 # using the target debug-<varname>. So for example, make debug-junk will
452 # display the contents of the junk variable.
453
454 debug-% :
455 @echo $* = $($*)
456
457 #-------------------------------------------------------------------------
458 # Clean up junk
459 #-------------------------------------------------------------------------
460
461 clean :
462 rm -rf *~ \#* $(junk)
463
464 distclean :
465 rm -rf *~ \#* $(junk) $(dist_junk)
466
467 .PHONY : clean distclean