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