How to get more verbose output from Scons - scons

How should I change SConstruct in order to see the details of how each file is compiled?
Currently, scons only outputs a bunch of 'compiling xxx.c ...'.

It's possible with an SConstruct file to do:
SetOption('silent')
which will suppress the output of any command. Is it possible you have one of these floating around somewhere?
Addendum:
You can also set the CCOMSTR variable to override the build message for C compiles (there's a different variable for each builder though), and there's even a (not terribly well documented) PRINT_CMD_LINE_FUNC variable which would provide a general override.

Related

error with vim errorformat using make project invoking multiple compilers

I have a make project creating binaries using various back-ends…
→ C, C++, csharp, java… on linux using mono csharp compiler, gcc, etc…
if I choose a single back-end (example csharp) by open a XXX.cs file than the make-output-error parser working OK… this mean error-output is parsed proper and I can jump to the error right away…
if I choose the toplevel make… (open vim without file on a toplevel directory) than the make-output-error parser does not work properly.
I discovered that the vim errorformat variable has changed between 1. and 2.
and now my question: how I can tell vim to recognize the error-output from C,C++,CSharp… and Java during run of the toplevel make ?
Whatever filetype plugin you have for C# is probably changing the value of :help 'errorformat' to work with C# compilers while you are left with the default value when running your top level make which, I assume, outputs errors as-is, without any filtering.
In order for Vim to interpret correctly the potentially mixed output of all your compilers you could:
set errorformat to a value that would work with all those formats,
or add a step to your build process that unifies every native output format into a single format that Vim can interpret without effort.
First option, find the errorformat values used by every compiler and prepend them to the default value at startup:
set errorformat^=<efm for c#>
set errorformat^=<efm for cpp>
...
Second option, I've been thinking for many years about writing a program that would do just that but never found the time to even write a README.md. If such a thing doesn't exist you will have to sed and awk your way on your own I'm afraid.

How to tell SCons to stop computing implicit dependencies in a particular directory?

My SCons project depends on a lot of third party libs, each providing dozens or hundreds of include files.
My understanding of how SCons works is that, on each build, it parses the source files of my project to find the #include directives, and it uses the value of env['CPPPATH'] to find these files and compute their md5 sum.
This scanning is costly, and thus I would like to optimize this process by teaching SCons that all the headers of my third party files will never change. This property is actually enforced by the tool that manages our third party libs.
I know there is a --implicit-deps-unchanged option that forces scons to assume that the implicit dependencies did not change, but it works globally. I did not find a way to restrict this option to a particular directory. I tried to find if the default Scanner of implicit C++ files can be configured, but found nothing. I think it is possible to avoid using CPPPATH, and instead only give the -I option to the compiler directly, but it is cumbersome.
Is there any way to optimize SCons by teaching him that files in a directory will never, ever change?
You can try pre-expanding the list of header file paths into CCFLAGS.
Note that doing so means they will not be scanned.
for i in list_of_third_party_header_directories:
env['CCFLAGS'].append('-I' + i)
In this case the contents of CPPPATH would be your source directories, and not the third-party ones which you assert don't change.
Note that changing the command line of your compile commands in any way (unless the arguments are enclosed in $( $)) will cause your source files to recompile.

In SCons, how to set a C preprocessor define temporarily

My C code contains #ifdef FOO. Can add something to the SCons command line to set the define, without having to modify the SConstruct/SConscript files?
I know there is a construction variable CFLAGS, and if I could get -DFOO into it, that should work. But, I cannot find a way to set construction variables from the command line.
No, unless your SConstructs/SConscripts support some sort of option/variable that you could give on the command-line (see chap. 10 "Controlling a Build From the Command-Line" in the UserGuide http://www.scons.org/doc/production/HTML/scons-user.html ).
By design, SCons uses "clean" Environments (no shell variables are imported) to protect your builds and make them repeatable. You can't simply override this by suddenly injecting flags and options from the outside.
But you can, in the SConstructs, create your build Environment such that you allow it to "import" certain shell settings (or the whole os.environ). See also #1 of the "most frequently asked FAQ" at https://bitbucket.org/scons/scons/wiki/FrequentlyAskedQuestions#markdown-header-why-doesnt-scons-find-my-compilerlinkeretc-i-can-execute-it-just-fine-from-the-command-line .

How can I find out the dependencies and build rule used to build something in scons

I don't want to use scons --n, I want to see how something was built, not how it would be built now.
I presume its possible to use .sconsdblite somehow.
Has anyone done this?
The SCons man pages explains the --tree command line options that can be used to display the targets' dependency info.
The most basic way to use it is as follows:
# scons --tree=all
There are several different tree options explained therein, depending on your situation.
Additionally there are several --debug options available.
This might help do what you mention in your comments: --debug=explain
Print an explanation of precisely why scons is deciding to (re-)build
any targets. (Note: this does not print anything for targets that are
not rebuilt.)

How to convert a makefile into readable code?

I downloaded a set of source code for a program in a book and I got a makefile.
I am quite new to Linux, and I want to know whether there is any way I can see the actual source code written in C?
Or what exactly am I to do with it?
It sounds like you may not have downloaded the complete source code from the book web site. As mentioned previously, a Makefile is only the instructions for building the source code, and the source code is normally found in additional files with names ending in .c and .h. Perhaps you could look around the book web site for more files to download?
Or, since presumably the book web site is public, let us know which one it is and somebody will be happy to point you in the right direction.
A Makefile does not contain any source itself. It is simply a list of instructions in a special format which specifies what commands should be run, and in what order, to build your program. If you want to see where the source is, your Makefile will likely contain many "filename.c"'s and "filename.h"'s. You can use grep to find all the instances of ".c" and ".h" in the file, which should correspond to the C source and header files in the project. The following command should do the trick:
grep -e '\.[ch]' Makefile
To use the Makefile to build your project, simply typing make should do something reasonable. If that doesn't do what you want, look for unindented lines ending in a colon; these are target names, and represent different arguments you can specify after "make" to build a particular part of your project, or build it in a certain way. For instance, make install, make all, and make debug are common targets.
You probably have GNU Make on your system; much more information on Makefiles can be found here.
It looks like you also need to download the SB-AllSource.zip file. Then use make (with the Makefile that you've already downloaded) to build.

Resources