Added PC histogram option.
[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
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@ -DPREFIX=\"$(prefix)\"
88 CPPFLAGS += @CPPFLAGS@
89 CXXFLAGS += @CXXFLAGS@ -DPREFIX=\"$(prefix)\"
90 COMPILE := $(CXX) -fPIC -MMD -MP $(CPPFLAGS) $(CFLAGS) $(CXXFLAGS) \
91 $(sprojs_include)
92 COMPILE_C := $(CC) -fPIC -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 comma := ,
99 LD := $(CXX)
100 LDFLAGS := @LDFLAGS@
101 LIBS := @LIBS@
102 LINK := $(LD) -L. $(LDFLAGS) -Wl,-rpath,$(install_libs_dir) $(patsubst -L%,-Wl$(comma)-rpath$(comma)%,$(filter -L%,$(LDFLAGS)))
103
104 # Library creation
105
106 AR := @AR@
107 RANLIB := @RANLIB@
108
109 # Host simulator
110
111 RUN := @RUN@
112 RUNFLAGS := @RUNFLAGS@
113
114 # Installation
115
116 MKINSTALLDIRS := $(scripts_dir)/mk-install-dirs.sh
117 INSTALL := @INSTALL@
118 INSTALL_HDR := $(INSTALL) -m 444
119 INSTALL_LIB := $(INSTALL) -m 644
120 INSTALL_EXE := $(INSTALL) -m 555
121 STOW := @stow@
122
123 #-------------------------------------------------------------------------
124 # Include subproject makefile fragments
125 #-------------------------------------------------------------------------
126
127 sprojs_mk = $(addsuffix .mk, $(sprojs_enabled))
128
129 -include $(sprojs_mk)
130
131 dist_junk += $(sprojs_mk)
132
133 #-------------------------------------------------------------------------
134 # Reverse list helper function
135 #-------------------------------------------------------------------------
136 # This function is used by the subproject template to reverse the list
137 # of dependencies. It uses recursion to perform the reversal.
138 #
139 # Arguments:
140 # $(1) : space separated input list
141 # retval : input list in reverse order
142 #
143
144 reverse_list = $(call reverse_list_h,$(1),)
145 define reverse_list_h
146 $(if $(strip $(1)), \
147 $(call reverse_list_h, \
148 $(wordlist 2,$(words $(1)),$(1)), \
149 $(firstword $(1)) $(2)), \
150 $(2))
151 endef
152
153 #-------------------------------------------------------------------------
154 # Template for per subproject rules
155 #-------------------------------------------------------------------------
156 # The template is instantiated for each of the subprojects. It relies on
157 # subprojects defining a certain set of make variables which are all
158 # prefixed with the subproject name. Since subproject names can have
159 # dashes in them (and the make variables are assumed to only use
160 # underscores) the template takes two arguments - one with the regular
161 # subproject name and one with dashes replaced with underscores.
162 #
163 # Arguments:
164 # $(1) : real subproject name (ie with dashes)
165 # $(2) : normalized subproject name (ie dashes replaced with underscores)
166 #
167
168 define subproject_template
169
170 # In some (rare) cases, a subproject might not have any actual object
171 # files. It might only include header files or program sources. To keep
172 # things consistent we still want a library for this subproject, so in
173 # this spectial case we create a dummy source file and thus the build
174 # system will create a library for this subproject with just the
175 # corresponding dummy object file.
176
177 ifeq ($$(strip $$($(2)_srcs) $$($(2)_c_srcs)),)
178 $(2)_srcs += _$(1).cc
179 $(2)_junk += _$(1).cc
180 endif
181
182 _$(1).cc :
183 echo "int _$(2)( int arg ) { return arg; }" > $$@
184
185 # Build the object files for this subproject
186
187 $(2)_pch := $$(patsubst %.h, %.h.gch, $$($(2)_precompiled_hdrs))
188 $(2)_objs := $$(patsubst %.cc, %.o, $$($(2)_srcs))
189 $(2)_c_objs := $$(patsubst %.c, %.o, $$($(2)_c_srcs))
190 $(2)_deps := $$(patsubst %.o, %.d, $$($(2)_objs))
191 $(2)_c_deps := $$(patsubst %.o, %.d, $$($(2)_c_objs))
192 $$($(2)_pch) : %.h.gch : %.h
193 $(COMPILE) $$<
194 $$($(2)_objs) : %.o : %.cc $$($(2)_gen_hdrs) $$($(2)_pch)
195 $(COMPILE) -c $$<
196 $$($(2)_c_objs) : %.o : %.c $$($(2)_gen_hdrs)
197 $(COMPILE_C) -c $$<
198
199 $(2)_junk += $$(addprefix $(src_dir)/$(1)/, $$($(2)_pch)) \
200 $$($(2)_objs) $$($(2)_c_objs) $$($(2)_deps) $$($(2)_c_deps) $$($(2)_gen_hdrs)
201
202 # Reverse the dependency list so that a given subproject only depends on
203 # subprojects listed to its right. This is the correct order for linking
204 # the list of subproject libraries.
205
206 $(2)_reverse_deps := $$(call reverse_list,$$($(2)_subproject_deps))
207
208 # Build a library for this subproject
209
210 $(2)_lib_libs := $$($(2)_reverse_deps)
211 $(2)_lib_libnames := $$(patsubst %, lib%.so, $$($(2)_lib_libs))
212 $(2)_lib_libarg := $$(patsubst %, -l%, $$($(2)_lib_libs))
213
214 lib$(1).so : $$($(2)_objs) $$($(2)_c_objs) $$($(2)_lib_libnames)
215 $(LINK) -shared -o $$@ $(if $(filter Darwin,$(shell uname -s)),-install_name $(install_libs_dir)/$$@) $$^ $$($(2)_lib_libarg) $(LIBS)
216
217 $(2)_junk += lib$(1).so
218
219 # Build unit tests
220
221 $(2)_test_objs := $$(patsubst %.cc, %.o, $$($(2)_test_srcs))
222 $(2)_test_deps := $$(patsubst %.o, %.d, $$($(2)_test_objs))
223 $(2)_test_exes := $$(patsubst %.t.cc, %-utst, $$($(2)_test_srcs))
224 $(2)_test_outs := $$(patsubst %, %.out, $$($(2)_test_exes))
225 $(2)_test_libs := $(1) $$($(2)_reverse_deps) utst
226 $(2)_test_libnames := $$(patsubst %, lib%.so, $$($(2)_test_libs))
227 $(2)_test_libarg := $$(patsubst %, -l%, $$($(2)_test_libs))
228
229 $$($(2)_test_objs) : %.o : %.cc
230 $(COMPILE) -c $$<
231
232 $$($(2)_test_exes) : %-utst : %.t.o $$($(2)_test_libnames)
233 $(LINK) -o $$@ $$< $$($(2)_test_libarg) $(LIBS)
234
235 $(2)_deps += $$($(2)_test_deps)
236 $(2)_junk += \
237 $$($(2)_test_objs) $$($(2)_test_deps) \
238 $$($(2)_test_exes) *.junk-dat
239
240 # Run unit tests
241
242 $$($(2)_test_outs) : %.out : %
243 $(RUN) $(RUNFLAGS) ./$$< default | tee $$@
244
245 $(2)_junk += $$($(2)_test_outs)
246
247 # Build programs
248
249 $(2)_prog_objs := $$(patsubst %.cc, %.o, $$($(2)_prog_srcs))
250 $(2)_prog_deps := $$(patsubst %.o, %.d, $$($(2)_prog_objs))
251 $(2)_prog_exes := $$(patsubst %.cc, %, $$($(2)_prog_srcs))
252 $(2)_prog_libs := $(1) $$($(2)_reverse_deps)
253 $(2)_prog_libnames := $$(patsubst %, lib%.so, $$($(2)_prog_libs))
254 $(2)_prog_libarg := $$(patsubst %, -l%, $$($(2)_prog_libs))
255
256 $$($(2)_prog_objs) : %.o : %.cc
257 $(COMPILE) -c $$<
258
259 $$($(2)_prog_exes) : % : %.o $$($(2)_prog_libnames)
260 $(LINK) -o $$@ $$< $$($(2)_prog_libarg) $(LIBS)
261
262 $(2)_deps += $$($(2)_prog_deps)
263 $(2)_junk += $$($(2)_prog_objs) $$($(2)_prog_deps) $$($(2)_prog_exes)
264
265 # Build programs which will be installed
266
267 $(2)_install_prog_objs := $$(patsubst %.cc, %.o, $$($(2)_install_prog_srcs))
268 $(2)_install_prog_deps := $$(patsubst %.o, %.d, $$($(2)_install_prog_objs))
269 $(2)_install_prog_exes := $$(patsubst %.cc, %, $$($(2)_install_prog_srcs))
270
271 $$($(2)_install_prog_objs) : %.o : %.cc $$($(2)_gen_hdrs)
272 $(COMPILE) -c $$<
273
274 $$($(2)_install_prog_exes) : % : %.o $$($(2)_prog_libnames)
275 $(LINK) -o $$@ $$< $$($(2)_prog_libarg) $(LIBS)
276
277 $(2)_deps += $$($(2)_install_prog_deps)
278 $(2)_junk += \
279 $$($(2)_install_prog_objs) $$($(2)_install_prog_deps) \
280 $$($(2)_install_prog_exes)
281
282 # Subproject specific targets
283
284 all-$(1) : lib$(1).so $$($(2)_install_prog_exes)
285
286 check-$(1) : $$($(2)_test_outs)
287 echo; grep -h -e'Unit Tests' -e'FAILED' -e'Segementation' $$^; echo
288
289 clean-$(1) :
290 rm -rf $$($(2)_junk)
291
292 .PHONY : all-$(1) check-$(1) clean-$(1)
293
294 # Update running variables
295
296 libs += lib$(1).so
297 objs += $$($(2)_objs)
298 srcs += $$(addprefix $(src_dir)/$(1)/, $$($(2)_srcs))
299 hdrs += $$(addprefix $(src_dir)/$(1)/, $$($(2)_hdrs)) $$($(2)_gen_hdrs)
300 junk += $$($(2)_junk)
301 deps += $$($(2)_deps)
302
303 test_outs += $$($(2)_test_outs)
304
305 install_hdrs += $$(addprefix $(src_dir)/$(1)/, $$($(2)_hdrs)) $$($(2)_gen_hdrs)
306 install_libs += lib$(1).so
307 install_exes += $$($(2)_install_prog_exes)
308
309 endef
310
311 # Iterate over the subprojects and call the template for each one
312
313 $(foreach sproj,$(sprojs_enabled), \
314 $(eval $(call subproject_template,$(sproj),$(subst -,_,$(sproj)))))
315
316 #-------------------------------------------------------------------------
317 # Autodependency files
318 #-------------------------------------------------------------------------
319
320 -include $(deps)
321
322 deps : $(deps)
323 .PHONY : deps
324
325 #-------------------------------------------------------------------------
326 # Check
327 #-------------------------------------------------------------------------
328
329 check : $(test_outs)
330 echo; grep -h -e'Unit Tests' -e'FAILED' -e'Segementation' $^; echo
331
332 .PHONY : check
333
334 #-------------------------------------------------------------------------
335 # Installation
336 #-------------------------------------------------------------------------
337
338 install-hdrs : $(install_hdrs)
339 $(MKINSTALLDIRS) $(install_hdrs_dir)
340 for file in $^; \
341 do \
342 $(INSTALL_HDR) $$file $(install_hdrs_dir); \
343 done
344
345 install-libs : $(install_libs)
346 $(MKINSTALLDIRS) $(install_libs_dir)
347 for file in $^; \
348 do \
349 $(INSTALL_LIB) $$file $(install_libs_dir); \
350 done
351
352 install-exes : $(install_exes)
353 $(MKINSTALLDIRS) $(install_exes_dir)
354 for file in $^; \
355 do \
356 $(INSTALL_EXE) $$file $(install_exes_dir); \
357 done
358
359 install : install-hdrs install-libs install-exes
360 ifeq ($(enable_stow),yes)
361 $(MKINSTALLDIRS) $(stow_pkg_dir)
362 cd $(stow_pkg_dir) && \
363 $(STOW) --delete $(project_name)-* && \
364 $(STOW) $(project_name)-$(project_ver)
365 endif
366
367 .PHONY : install install-hdrs install-libs install-exes
368
369 #-------------------------------------------------------------------------
370 # Regenerate configure information
371 #-------------------------------------------------------------------------
372
373 configure_prereq = \
374 $(src_dir)/configure.ac \
375 $(src_dir)/aclocal.m4 \
376 $(join $(addprefix $(src_dir)/, $(sprojs_enabled)), \
377 $(patsubst %, /%.ac, $(sprojs_enabled)))
378
379 $(src_dir)/configure : $(configure_prereq)
380 cd $(src_dir) && autoconf && autoheader
381
382 config.status : $(src_dir)/configure
383 ./config.status --recheck
384
385 sprojs_mk_in = \
386 $(join $(addprefix $(src_dir)/, $(sprojs_enabled)), \
387 $(patsubst %, /%.mk.in, $(sprojs_enabled)))
388
389 Makefile : $(src_dir)/Makefile.in $(sprojs_mk_in) config.status
390 ./config.status
391
392 dist_junk += config.status config.h Makefile config.log
393
394 #-------------------------------------------------------------------------
395 # Distribution
396 #-------------------------------------------------------------------------
397 # The distribution tarball is named project-ver.tar.gz and it includes
398 # both enabled and disabled subprojects.
399
400 dist_files = \
401 $(sprojs) \
402 README \
403 style-guide.txt \
404 mcppbs-uguide.txt \
405 scripts \
406 configure.ac \
407 aclocal.m4 \
408 configure \
409 config.h.in \
410 Makefile.in \
411
412 dist_dir := $(project_name)-$(project_ver)
413 dist_tgz := $(project_name)-$(project_ver).tar.gz
414
415 # Notice that when we make the distribution we rewrite the configure.ac
416 # script with the current version and we rerun autoconf in the new
417 # source directory so that the distribution will have the proper version
418 # information. We also rewrite the "Version : " line in the README.
419
420 dist :
421 rm -rf $(dist_dir)
422 mkdir $(dist_dir)
423 tar -C $(src_dir) -cf - $(dist_files) | tar -C $(dist_dir) -xpf -
424 sed -i.bak 's/^\(# Version :\).*/\1 $(project_ver)/' $(dist_dir)/README
425 sed -i.bak 's/\( proj_version,\).*/\1 [$(project_ver)])/' $(dist_dir)/configure.ac
426 cd $(dist_dir) && \
427 autoconf && autoheader && \
428 rm -rf autom4te.cache configure.ac.bak README.bak
429 tar -czvf $(dist_tgz) $(dist_dir)
430 rm -rf $(dist_dir)
431
432 # You can use the distcheck target to try untarring the distribution and
433 # then running configure, make, make check, and make distclean. A
434 # "directory is not empty" error means distclean is not removing
435 # everything.
436
437 distcheck : dist
438 rm -rf $(dist_dir)
439 tar -xzvf $(dist_tgz)
440 mkdir -p $(dist_dir)/build
441 cd $(dist_dir)/build; ../configure; make; make check; make distclean
442 rm -rf $(dist_dir)
443
444 junk += $(project_name)-*.tar.gz
445
446 .PHONY : dist distcheck
447
448 #-------------------------------------------------------------------------
449 # Default
450 #-------------------------------------------------------------------------
451
452 all : $(install_hdrs) $(install_libs) $(install_exes)
453 .PHONY : all
454
455 #-------------------------------------------------------------------------
456 # Makefile debugging
457 #-------------------------------------------------------------------------
458 # This handy rule will display the contents of any make variable by
459 # using the target debug-<varname>. So for example, make debug-junk will
460 # display the contents of the junk variable.
461
462 debug-% :
463 @echo $* = $($*)
464
465 #-------------------------------------------------------------------------
466 # Clean up junk
467 #-------------------------------------------------------------------------
468
469 clean :
470 rm -rf *~ \#* $(junk)
471
472 distclean :
473 rm -rf *~ \#* $(junk) $(dist_junk)
474
475 .PHONY : clean distclean