lindenb / makefile2graph Goto Github PK
View Code? Open in Web Editor NEWCreates a graph of dependencies from GNU-Make; Output is a graphiz-dot file or a Gexf-XML file.
License: MIT License
Creates a graph of dependencies from GNU-Make; Output is a graphiz-dot file or a Gexf-XML file.
License: MIT License
Thanks!
Thanks!
Makefile2graph shows incorrect output for makefiles using VPATH. Example:
ake -nd --no-builtin-rules
GNU Make 4.1
Built for x86_64-pc-linux-gnu
Copyright (C) 1988-2014 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Reading makefiles...
Reading makefile 'Makefile'...
Updating makefiles....
Considering target file 'Makefile'.
Looking for an implicit rule for 'Makefile'.
No implicit rule found for 'Makefile'.
Finished prerequisites of target file 'Makefile'.
No need to remake target 'Makefile'.
Updating goal targets....
Considering target file 'all'.
File 'all' does not exist.
Considering target file 'build/main'.
Considering target file 'build/main.o'.
Looking for an implicit rule for 'build/main.o'.
Trying pattern rule with stem 'main'.
Trying implicit prerequisite 'main.cpp'.
Found prerequisite 'main.cpp' as VPATH 'src/main.cpp'
Found an implicit rule for 'build/main.o'.
No need to remake target 'build/main.o'.
Finished prerequisites of target file 'build/main'.
Prerequisite 'build/main.o' is older than target 'build/main'.
Prerequisite 'build/response.o' is older than target 'build/main'.
Prerequisite 'build/parse.o' is older than target 'build/main'.
Prerequisite 'lib/libmagic.so' is older than target 'build/main'.
No need to remake target 'build/main'.
Finished prerequisites of target file 'all'.
Must remake target 'all'.
Successfully remade target file 'all'.
make: Nothing to be done for 'all'.
makefile2graph
outputs
digraph G {
n2[label="all", color="red"];
n3[label="build/main", color="green"];
n4[label="build/main.o", color="green"];
n11[label="build/parse.o", color="green"];
n7[label="build/response.o", color="green"];
n14[label="lib/libmagic.so", color="green"];
n5[label="main.cpp", color="green"];
n12[label="parse.cpp", color="green"];
n10[label="parse.h", color="green"];
n8[label="response.cpp", color="green"];
n6[label="response.h", color="green"];
n13[label="src/parse.h", color="green"];
n9[label="src/response.h", color="green"];
n3 -> n2 ;
n4 -> n3 ;
n11 -> n3 ;
n7 -> n3 ;
n14 -> n3 ;
n5 -> n4 ;
n6 -> n4 ;
n12 -> n11 ;
n13 -> n11 ;
n10 -> n7 ;
n8 -> n7 ;
n9 -> n7 ;
}
At least half of those should start with src/
.
I tried makefile2graph on its own Makefile and got an empty graph.
My version of make is: 4.2.1.
Hi,
Thanks for this tool; I'm using it to write a tutorial. Would you consider swapping the colours for the ellipses of each file? At the moment they are green/red. This is not a good choice for colorblind readers. A better default (and perhaps softer) might be to take some colours from the palettes available at: https://colorbrewer2.org/#type=qualitative&scheme=Set2&n=3
e.g. I've changed my local copy make2graph L375 to:
(t->must_remake?"#fc8d62":"#66c2a5") /* https://colorbrewer2.org/#type=qualitative&scheme=Set2&n=3 */
Best wishes, stephen
Before I found this, I found this: https://github.com/TomConlin/MakefileViz
When I used this I found that processes themselves were not visualised. It would be quite cool if it showed the processes that were used as well in between inputs and outputs. I realise that each recipe itself would be considered a process, where the recipes call other processes. Later in the future, this can be used to visualise to create subgraphs within a larger graph.
Could it be possible to be a bit more verbose in the README.md
when explainin the compilation/installation process? Like saying the output of the compilation is just a binary/blob called make2graph
. This would help people using Makefiles, but not used to the build/compilation process of C projects.
Also mentioning some common/standard practices like putting that binary in /usr/local/bin
on Unix environments (or any other viable/sensible place in $PATH
) helps in giving a bit of context for people not used to compile C projects from source code.
I see there's a bash script called makefile2graph
that perhaps could/need to be placed somewhere else (available in $PATH
). I am assuming this bash script should automagically take care of locale issues, a bit of context around that locale thing and where to "install it" in a canonical place could help.
Regarding the pipe example into dot
to generate a png image: a bit of context around graphviz could help in understanding what that dot
command is doing, as the logical connection between dot
and the graphviz context was not clear to me and querying a web search engine for "dot png" did not help. In my case on Debian I had to run sudo apt-get install graphviz
to then install the dot
command.
Thanks for this great visual tool, I find it very helpful when building projects made by a combination of different programming languages, cloud infrastructure building processes, remote deployments in cloud providers, and remote monitoring tools for the build process :-)
Consider the following Makefile
all: hello.b hello.c
hello.a:
touch $@
%.b %.c: %.a
touch $*.b $*.c
Instead of properly connecting the two pattern rule targets, only one of
them is connected the in the dot
output
I believe this is because the make -d
output just says that the second
has "already been considered"
# make -rRBndC example
GNU Make 4.2.1
Built for x86_64-redhat-linux-gnu
Copyright (C) 1988-2016 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Reading makefiles...
Reading makefile 'Makefile'...
Updating makefiles....
Considering target file 'Makefile'.
Looking for an implicit rule for 'Makefile'.
No implicit rule found for 'Makefile'.
Finished prerequisites of target file 'Makefile'.
No need to remake target 'Makefile'.
Updating goal targets....
Considering target file 'all'.
File 'all' does not exist.
Looking for an implicit rule for 'all'.
No implicit rule found for 'all'.
Considering target file 'hello.b'.
Looking for an implicit rule for 'hello.b'.
Trying pattern rule with stem 'hello'.
Trying implicit prerequisite 'hello.a'.
Found an implicit rule for 'hello.b'.
Considering target file 'hello.a'.
Finished prerequisites of target file 'hello.a'.
Making 'hello.a' due to always-make flag.
Must remake target 'hello.a'.
make[1]: Entering directory '/home/dacoda/projects/tea-dragon-society/src/third-party/makefile2graph/test/example'
touch hello.a
Successfully remade target file 'hello.a'.
Finished prerequisites of target file 'hello.b'.
Prerequisite 'hello.a' is newer than target 'hello.b'.
Must remake target 'hello.b'.
touch hello.b hello.c
Successfully remade target file 'hello.b'.
Considering target file 'hello.c'.
File 'hello.c' was considered already.
Finished prerequisites of target file 'all'.
Must remake target 'all'.
Successfully remade target file 'all'.
make[1]: Leaving directory '/home/dacoda/projects/tea-dragon-society/src/third-party/makefile2graph/test/example'
With a different flag, however, it seems possible to have make
let us
know that it is building more than one file with a single recipe
# make -rRpBC example | grep -C5 'Also makes'
touch $@
hello.b: hello.a
# Implicit rule search has been done.
# Implicit/static pattern stem: 'hello'
# Also makes: hello.c
# Last modified 2020-09-18 17:55:32.792450404
# File has been updated.
# Successfully updated.
# automatic
# @ := hello.b
Hi,
I just noticed that make install
installs extra documentation in /usr/local/share/makefile2graph
when I would have expected it in /usr/local/share/doc/makefile2graph
:
install LICENSE README.md screenshot.png /usr/local/share/makefile2graph
I assume that is was a simple mistake, resolved like this:
diff --git a/Makefile b/Makefile
index 1e1fb81..33394aa 100644
--- a/Makefile
+++ b/Makefile
@@ -2,7 +2,7 @@ prefix = /usr/local
bindir = $(prefix)/bin
sharedir = $(prefix)/share
docdir = $(sharedir)/doc
-pkgdocdir = $(sharedir)/makefile2graph
+pkgdocdir = $(docdir)/makefile2graph
mandir = $(sharedir)/man
man1dir = $(mandir)/man1
Could you tag a new stable release so that distributions like homebrew can pick up the new features recently added?
Suggestions:
M2G_VERSION
It should be as follow in Readme/Compilation:
make
make install
without "make install": "make2graph" is not visible from user. Then the usage should be "make -Bnd | ./YOUR_PATH_OF_MAKE2GRAPH/make2graph > output.dot
In Usage, it is better if you use:
cd YOUR_CODE_REPO
make -Bnd | make2graph | dot -Tpng -o out.png
Hi, I think this tool is fun and awesome for visualizing projects.
Are you interested in PRs for adding sub-makefile (recursive make invocation) support? It looks like make -Bnd provides all the output needed for this. From your experience, do you think there's something that makes this much harder, or was it just outside your use case?
Is there any way to use makefile2graph to show the tree of targets, instead of the tree of files?
The use cases I have are often not files, but merely .PHONY
targets, which are any kind of jobs, not necessarily compilations, which lead to files being created. They might be something like running tests and outputting test result, or running a linter, which outputs comments about files.
Hi, thanks for this library.
I'm running Mac OS 10.6.8 and wasn't able to build the repo due to the following compilation error:
$ make
cc -O3 -Wall make2graph.c -o make2graph
make2graph.c: In function ‘targetName’:
make2graph.c:137: warning: implicit declaration of function ‘strndup’
make2graph.c:137: warning: incompatible implicit declaration of built-in function ‘strndup’
Undefined symbols:
"_strndup", referenced from:
_targetName in cczR4fIs.o
ld: symbol(s) not found
collect2: ld returned 1 exit status
make: *** [make2graph] Error 1
As it turns out strndup is not a standard lib function and is not available on Mac OS and other BSDs, see here: https://bitbucket.org/gward/vcprompt/issue/1/compilation-fails-on-macos-1058
Submitting fix as a pull request shortly.
My dependency tree is rather large. Is it possible for make to not expand the variables and keep the variable names to reduce the number of edges in the graph? I.e. it won't output an edge for each C-file, instead it will output one edge for the variable where the C-files are set. I understand that this is something for make to implement, but I can't find anything in the manual.
Hi
I try to use makefile2graph but have some issues:
1-instead of CMAKE I create script that manually go through path and run "make files" here is the script: (when each module make refer to some other till project make completely):
for MODULE in \
src/module1 \
src/module2 \
src/module3 \
src/app/module4 \
...
src/app4/moduleN \
do
cd $MODULE; echo
make clean;make
done
I run below command to generate graph in each module path:
/usr/bin/make -Bnd | ${GDIR}/make2graph | dot -Tpng -o /tmp/test.png
but how can I run this on root of project? (there is no global make file that exist on top of project, script make them one by one)
2-how can I see each module use which lib, now when I run it on each module path it only show that module refer to lib and won't show use which lib!
Any idea?
Thanks,
It seems that it is really hard to see a horizontal graph, I really hope for an option for a vertical graph.
Hi Pierre,
Just trying out makefile2graph on a very basic makefile:-
all : file1
file1: file0
cat file0 > file1
I get this error:-
$ make -Bnd | make2graph
Cannot get target name in "Considering target file 'makefile'.".
make: write error
Am I missing something?
Thanks for writing makefile2graph. The last release was already some years ago and is missing features like e225ea0. Could you maybe tag a new one?
Thanks!
Hi,
I compile a c program to Webassembly. It generates .wasm files.
I want to find the source .c file that generates .wasm file.
Does your tool find this relation between .c file and .wasm file?
I mean, can we consider .wasm file is depended on .c file. So, there is a dependency between .wasm file and .c file.
When I run this on my makefile, the same file (ag_census_both_village_summary_combined.RData) is shown twice in the resulting output, once with its relative path ("../data/created/") and once without. Attached makefile (as .txt since Github won't allow it without an extension) and resulting output .txt file.
Considering this simple Makefile:
%.a:
echo "$@" > $@
%.b : %.a
echo "$@" > $@
%.z : %.b
echo "$@" > $@
If 1.a does not exist make2graph yields:
rm 1.a
/opt/make-4.1/bin/make -Bnd 1.z | make2graph | dot -Tpng -o Makefile_1.png
However, if 1.a already exists an additional (false?) dependency is drawn:
touch 1.a
/opt/make-4.1/bin/make -Bnd 1.z | make2graph | dot -Tpng -o Makefile_2.png
Same problem with make-3.81 or j4make
Make is localized on many platforms, since your parser seems to parse only english output you should maybe add that to the description.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.