1# -*- Mode: makefile -*-
2#
3# This Source Code Form is subject to the terms of the Mozilla Public
4# License, v. 2.0. If a copy of the MPL was not distributed with this
5# file, You can obtain one at http://mozilla.org/MPL/2.0/.
6
7# This Makefile is used to kick off a static rooting analysis. This Makefile is
8# NOT intended for use as part of the standard Mozilla build. Instead, this
9# Makefile will use $PATH to subvert compiler invocations to add in the sixgill
10# plugin, and then do a regular build of whatever portion of the tree you are
11# analyzing. The plugins will dump out several xdb database files. Various
12# analysis scripts, written in JS, will run over those database files to
13# produce the final analysis output.
14
15include $(topsrcdir)/config/config.mk
16
17# Tree to build and analyze, defaulting to the current tree
18TARGET_JSOBJDIR ?= $(TOPOBJDIR)
19
20# Path to a JS binary to use to run the analysis. You really want this to be an
21# optimized build.
22JS ?= $(DIST)/bin/js
23
24# Path to an xgill checkout containing the GCC plugin, xdb-processing binaries,
25# and compiler wrapper scripts used to automatically integrate into an existing
26# build system.
27SIXGILL ?= @SIXGILL_PATH@
28
29# Path to the JS scripts that will perform the analysis, defaulting to the same
30# place as this Makefile.in, which is probably what you want.
31ANALYSIS_SCRIPT_DIR ?= $(srcdir)
32
33# Number of simultanous analyzeRoots.js scripts to run.
34JOBS ?= 6
35
36all : rootingHazards.txt allFunctions.txt
37
38CALL_JS := time env PATH=$$PATH:$(SIXGILL)/bin XDB=$(SIXGILL)/bin/xdb.so $(JS)
39
40src_body.xdb src_comp.xdb: run_complete
41	@echo Started compilation at $$(date)
42	$(ANALYSIS_SCRIPT_DIR)/run_complete --foreground --build-root=$(TARGET_JSOBJDIR) --work-dir=work -b $(SIXGILL)/bin $(CURDIR)
43	@echo Finished compilation at $$(date)
44
45callgraph.txt: src_body.xdb src_comp.xdb computeCallgraph.js
46	@echo Started computation of $@ at $$(date)
47	$(CALL_JS) $(ANALYSIS_SCRIPT_DIR)/computeCallgraph.js > $@.tmp
48	mv $@.tmp $@
49	@echo Finished computation of $@ at $$(date)
50
51gcFunctions.txt: callgraph.txt computeGCFunctions.js annotations.js
52	@echo Started computation of $@ at $$(date)
53	$(CALL_JS) $(ANALYSIS_SCRIPT_DIR)/computeGCFunctions.js ./callgraph.txt > $@.tmp
54	mv $@.tmp $@
55	@echo Finished computation of $@ at $$(date)
56
57gcFunctions.lst: gcFunctions.txt
58	perl -lne 'print $$1 if /^GC Function: (.*)/' gcFunctions.txt > $@
59
60suppressedFunctions.lst: gcFunctions.txt
61	perl -lne 'print $$1 if /^Suppressed Function: (.*)/' gcFunctions.txt > $@
62
63gcTypes.txt: src_comp.xdb computeGCTypes.js annotations.js
64	@echo Started computation of $@ at $$(date)
65	$(CALL_JS) $(ANALYSIS_SCRIPT_DIR)/computeGCTypes.js > $@.tmp
66	mv $@.tmp $@
67	@echo Finished computation of $@ at $$(date)
68
69allFunctions.txt: src_body.xdb
70	@echo Started computation of $@ at $$(date)
71	time $(SIXGILL)/bin/xdbkeys $^ > $@.tmp
72	mv $@.tmp $@
73	@echo Finished computation of $@ at $$(date)
74
75rootingHazards.txt: gcFunctions.lst suppressedFunctions.lst gcTypes.txt analyzeRoots.js annotations.js gen-hazards.sh
76	@echo Started computation of $@ at $$(date)
77	time env JS=$(JS) ANALYZE='$(ANALYSIS_SCRIPT_DIR)/analyzeRoots.js' SIXGILL='$(SIXGILL)' '$(ANALYSIS_SCRIPT_DIR)/gen-hazards.sh' $(JOBS) > $@.tmp
78	mv $@.tmp $@
79	@echo Finished computation of $@ at $$(date)
80