What does gcc -E option stand for? - gcc

According to gcc manual, the -E option only preprocesses the .c source file, without running the compiler and just giving an input file (.i). But what does the -E stand for?

Summary
This option was introduced on compilers much earlier than GCC, and GCC used the same naming for compatibility.
My best guess from the historical evidence is that -E stands for "expand macros".
The authors of those earlier compilers couldn't call it -P because there was already a -P option, which also ran only the preprocessor, but wrote the output to .i files instead of to standard output. -p was also taken.
Over time, -E became preferred to -P, and when GCC was written, it supported only -E and not -P.
Despite being supposedly off topic for Stack Overflow, I think a bit of history will help explain how this option got its name.
gcc(1) inherited its basic command line options from much earlier Unix C compilers. Many versions can be found in the Unix Tree archive.
It looks like the first version that supported -E was Research Unix V7, circa 1979: cc(1) source, man page source. There was also a -P option that also just ran the preprocessor, but sent the result to a file foo.i instead of to standard output. V6 had already supported -P but not -E: cc(1) source, man page source.
This at least answers why -E wasn't named -P instead: because -P was already in use. (And -p was also taken, it was used to request profiling.) The only hint I found as to why -E was chosen is that the corresponding flag variable in the source code is named exflag. I would hazard a guess that this stands for "expand", as what -E does is basically to expand macros.
It appears that -P was eventually deprecated in favor of -E. V8 still supported it, but omitted it from the man page. V10 (circa 1989) included two versions of the compiler, cc which compiled traditional C, and lcc for ANSI C. The man page says that cc supports -P with the preprocessor behavior, but for lcc, -P did something else ("write declarations for all defined globals on standard error"). They both supported -E. On other fronts, 32V and BSD, at least initially, supported both, but -P would emit a warning that it was obsolete and -E should be used instead.
It looks like gcc, from its earliest version, only supported -E and not -P. Since then, a -P option has been introduced, but it does something else ("inhibit generation of linemarkers").

Related

What is the practical purpose of -c in the linux install (/usr/bin/install) command?

What is the practical purpose of -c in the linux install command? The man page shows:
-c (ignored)
I came across this scenario while installing Nagios command-mode:
/usr/bin/install -c -m 775 -o nagios -g nagios -d /usr/local/nagios/var/rw
From the install man page:
-c Copy the file. This is actually the default. The -c option is only included for backwards compatibility.
I think it exhibits the same behavior for copying files and creating directories. Also, taking a look at https://github.com/NagiosEnterprises/nagioscore/blob/master/Makefile.in#L37-L39 and https://github.com/NagiosEnterprises/nagioscore/blob/master/Makefile.in#L415-L421 we can see that these are set by the ./configure script.
Taking a look at configure.ac we see that it is the default autoconf macros that determine the binary to use: https://github.com/NagiosEnterprises/nagioscore/blob/master/configure.ac#L17-L19. And it is Nagios specific for setting the $(COMMAND_OPTS): https://github.com/NagiosEnterprises/nagioscore/blob/master/configure.ac#L237-L240.
Hope this helps!
TL;DR: It's a relic and doesn't matter :)
Historically, BSD's install would not copy files unless specified with the -c option. GNU Coreutils's version of install copied files by default, and provided -c as a BSD-compatibility option that is ignored. The GNU Coreutils manpage simply says
-c (ignored)
and doesn't provide context. This is the version of coreutils present on most Linux systems.
FreeBSD's manpage is a little bit more descriptive:
-c Copy the file. This is actually the default. The -c option is only included for backwards compatibility.
Nowadays, there's no particular reason to use the -c option unless you want compatibility with very old systems. That being said there's also no particular downside to leaving it in since it's unlikely you'll be hitting the character limit for the command line, so it's kind of an "up to you" sort of thing.

Where to find the ruby executable documentation?

I was trying to find the list of command-line arguments available for the ruby executable in http://ruby-doc.com/ but I could not find anything. After a Google search for "ruby interpreter command line options" I could only find this page, which applies to Ruby 1.4 only. Where can I find the documentation for the ruby executable in an 'official' source, like ruby-doc.com? Thanks!
Easiest option is to run man ruby. It will show your locally installed interpreter options.
Definitive option is the ruby repository on GitHub. Navigate to the version you need in the releases and locate man/ruby.1 file in the tree. The file contains definitions for CLI arguments.
Example: Ruby 2.3.0 interpreter CLI arguments definitions are here.
There is no such thing as "the Ruby executable". Every Ruby implementation has their own commandline executable. (Actually, come to think of it, SmallRuby and BlueRuby didn't have a commandline executable at all.)
And every Ruby implementation has their own commandline flags. That's why there cannot be a document explaining all the options: which implementation's options would that document?
For example, JRuby's --jdb flag to run under the Java Debugger simply doesn't make sense for IronRuby, Rubinius, MacRuby, Topaz, Cardinal, MRuby, or YARV. Rubinius's flag to turn on the sampling profiler doesn't make sense for implementations that don't have a sampling profiler. Rubinius's flag to turn on the native code JIT compiler doesn't make sense for implementations that don't have a native code JIT compiler. And so on.
However, there are a couple of options that most implementations agree on:
-0
-a
-c
-C
-d
-e
-E
-F
-i
-I
-l
-n
-p
-r
-s
-S
-T
-v
-w
-W
-x
BUT!!!
If you look at MRuby, which is the Ruby implementation written by Yukihiro "matz" Matsumoto, Ruby's creator, which is intended to be a lightweight implementation of the minimum core that can still be called "Ruby", it only supports these options:
-b load and execute RiteBinary (mrb) file
-c check syntax only
-e 'command' one line of script
-v print version number, then run in verbose mode
--verbose run in verbose mode
--version print the version
--copyright print the copyright
Of these, -b is clearly implementation specific, and -c, -v, --version, and --copyright have no runtime impact, so we can interpret this as meaning that -e is the only option that must be supported by a conforming Ruby implementation … after all, it is the only option supported by the Ruby implementation written by the only person who can legitimately have a say in what it means to be "a Ruby implementation".

Is there an easy way to COLOR-CODE the compiler outputs?

gcc (or other compilers) often generate huge text output and it's very difficult to see where the error is or miss warnings. I've done some search but havn't found a clean simple solution to color code the compiler output (so for instance warnings are yellow, errors are red, etc...)
Gcc 4.9 seems to have added this feature via the -fdiagnostics-color flag:
here's an alternative if you are looking for something very simple:
#!/bin/bash -e
make ${#} 2>&1 | perl -wln -M'Term::ANSIColor' -e '
m/Building|gcc|g++|\bCC\b|\bcc\b/ and print "\e[1;32m", "$_", "\e[0m"
or
m/Error/i and print "\e[1;91m", "$_", "\e[0m"
or
m/Warning/i and print "\e[1;93m", "$_", "\e[0m"
or
m/Linking|\.a\b/ and print "\e[1;36m", "$_", "\e[0m"
or
print; '
Just alias your make to this script and make sure it's executable...
Debian and Ubuntu gives the colorgcc package for that purpose.
And I usually run gcc (and make) thru emacs with M-x compile then the messages are colorized.
addenda
GCC 4.9 has a native colorization facility and GCC 6 - released end of April 2016 - (and probably GCC 5 too) is enabling it by default (when stdout is a terminal).
Ok, I'll just leave a notice about my own (python based) tool also :)
It is called Pluggable Output Processor and designed not only to colorize output of one particular program. Here is sample GCC output before:
After:
See colorgcc, a perl script that coulours the gcc output.
How to install and use colorgcc to colorize your gcc compiler output:
At least 3 answers here so far mention colorgcc, but NONE OF THEM EXPLAIN HOW TO INSTALL IT! (And it's not obvious). So, here's how to install the latest version in Ubuntu!
Go here and click "Clone or download" --> "Download Zip". I saved it into "~/Downloads/Install_Files"
Navigate to it in your file browser and right click it and go to "Extract Here." I now have a directory called "~/Downloads/Install_Files/colorgcc-master".
Copy the "colorgcc.pl" script to "/usr/bin/colorgcc" to "install" it (be sure to use the correct directory according to where you extracted it above): sudo cp ~/Downloads/Install_Files/colorgcc-master/colorgcc.pl /usr/bin/colorgcc
Make it executable: sudo chmod +x /usr/bin/colorgcc
Make the "~/bin" directory if it does not yet exist: mkdir ~/bin
*Make symbolic links that point to "/usr/bin/colorgcc" so that whenever you call gcc or g++ it automatically calls colorgcc instead:
ln -s /usr/bin/colorgcc ~/bin/g++
ln -s /usr/bin/colorgcc ~/bin/gcc
(if you ever want to uninstall colorgcc for some reason just delete these symbolic links "~/bin/g++" and "~/bin/gcc", and the Perl script: "/usr/bin/colorgcc" and you're done)
Done!
Here is a sample g++ output now when I call g++ -Wall -std=c++11 time_until_overflow_2.cpp -o time_until_overflow_2:
*Note: making these symbolic links in "~/bin" only works if "~/bin" is in your PATH variable in a location before the folder where the actual gcc and g++ executables are located. To ensure you have "~/bin" in your path you can view the PATH variable contents with: echo $PATH. If you don't see "/home/YOUR_USERNAME/bin" at the beginning of your path, add it with: export PATH=~/bin:$PATH.
References:
See here for more info. and for where I originally learned most of these steps: https://imranfanaswala.wordpress.com/2009/02/02/setting-up-colorgcc/. Thanks Imran Fanaswala!
~GS
you can use GilCC which is a Ruby tool that will convert GCC output to color in real-time. Right now you have two choices: Perl script (colorGCC) or GilCC and if you already work with Ruby you will like GilCC.
Unique to GilCC; GilCC has warning and errors counters and also shows compile time, very handy when you are trying to improve things. Because it is in Ruby it is cross platform. It is flexible and you can add more gems to customize it anyway you want.
The link to the download page is here.
https://github.com/gilmotta/GilCC
Although GCC 4.9 has -fdiagnostics-color option to enable colored outputs to terminals, I have created a tiny tool called 'crror' to get colorized compiler output.
It supports outputs from make as well. I can add colorize patterns for other tools if anyone requires.

Makefile odd behaviour

I've got this Makefile that is presenting some odd behaviour:
$ javac -d Classes -sourcepath .. -classpath `for x in \`ls Classes/jars/*\`; do echo -n $x:; done` PCA/PCAClassifier.java
compiles the java just fine. But for somereason when I call
make PCA
I get:
Compiling PCAClassifier
javac -d Classes -sourcepath .. -classpath `for x in \`ls Classes/jars/*\`; do echo -n $x:; done` PCA/PCAClassifier.java
javac: invalid flag: Classes/jars/Jama.jar:
Usage: javac <options> <source files>
use -help for a list of possible options
make: * [Classes/RobotSuite/PCA/PCAClassifier.class] Error 2
I am so confused. Anyone have a solution?
Make version info:
GNU Make 3.81
Copyright (C) 2006 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.
There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A
PARTICULAR PURPOSE.
This program built for i386-apple-darwin10.0
Background: Working on a group project. I'm running Ubuntu, my partner is running Mac OS X. For whatever reason, This makefile works just fine on my computer, but not on his. Even though the command works in his BASh terminal, somehow Make isn't sending it correctly.
You have given us almost no information to go on. Nonetheless, you are in luck!
On Mac OS X, bash has been built with --enable-strict-posix-default and hence the xpg_echo shell option defaults to being on in POSIX mode. POSIX mode is on when the shell has been invoked as /bin/sh, as it has been when it is invoked by Make, unless you instruct it otherwise by setting the $(SHELL) make variable (which you probably shouldn't).
This is the difference between Linux and Mac OS that is killing your makefile. When xpg_echo is on, the shell's built-in echo treats -n as just another argument to be printed (and hence also prints a newline). So the single classpath argument that you're trying to construct ends up as a bunch of separate arguments (half of which are "-n") and javac gets confused.
(This doesn't happen on the command line, even on Mac OS X, because then the shell has been invoked as /bin/bash, so it's not in POSIX mode and xpg_echo is off.)
So you have a number of options for fixing this:
Use /bin/echo -n in your shell snippet; unlike the built-in one, the real echo command these days mostly always understands -n;
Construct the classpath argument in a less roundabout way than your shell for loop; for example
... -classpath `ls Classes/jars/* | tr '\n' :` ...
or, if you are already assuming GNU Make, using make wildcards and functions instead of a shell snippet;
Have your colleague add shopt -u xpg_echo to an appropriate bash startup file on their machine (however this will just lead to future confusion when your next Mac OS-using colleague comes along and you've all long since forgotten how you fixed this this time).
Finally, a general note about debugging makefiles: when a javac ... command in a makefile recipe is giving incomprehensible error messages, change it to echo javac ... instead. Then you'll be able to see exactly how it's being invoked -- which, as seen here, may not be what you intended.

Unable to compare all GNU Unix manuals with all Unix Manuals in Mac

I would like to compare all GNU Unix manuals and and Mac's Unix manuals by sdiff.
I do not know how you go through, for instance, all Mac's Unix manuals and then save them to a file.
The comparison can be done by the following code when the manuals are in two files
sdiff <(file1) <(file2)
Perhaps, there is some index of Unix command names such that we can do the following
sdiff <(man *[in the index]) <(man *[in the index])
How can you compare all GNU Unix manuals with all Unix manuals in Mac?
[edit]
Mac's manuals are at /usr/share/man/man[1-9]/*.
I have an encoding problem with them when I try to cat them.
Another problem is to find the location of Coreutils' manuals.
Your goal, to identify the differing parameters for the different BSD vs GNU/Linux versions of the various programs, is going to be somewhat tedious. It's useful to note that there are other variants of all commands as well. There are system V versions and BSD versions and GNU versions, and the Mac uses a mish-mash of all 3. In any event, as a starting point, the files themselves are filled with formatting macros that you have no interest in. Pipe the output of man through 'col -b' to get data you can diff. In terms of generating the list of commands, you could just ls -1 /bin /usr/bin' Then something like this would get you most of the way:
while read command ; do
man $command | col -b > output1
man ./path/to/GNU/$command | col -b > output2
diff output1 output2 | grep '^[ ]*-' > $command.diffs
done<<EOF
diff
grep
sort
...
...
EOF
GNU means (G)NU is (N)ot (U)nix. GNU is not based, in any way on UNIX, it could not be due to copyright and licensing issues.
Most GNU documentation was written in texinfo format (which Debian later converted to roff (man) format as users wanted man pages). The documentation is in no way based upon the BSD documentation, everything in GNU was written from scratch.
Trying to diff between the two is like diffing a dictionary against a thesaurus. You will find that they both contain many of the same words, but are entirely different books written by entirely different people.
The documentation in no way adequately explains the differences between GNU and BSD (and by extension MacOS).
All man pages exist within the /usr/share/man/*; I'm not sure what you are attempting to accomplish here. Mac runs on BSD, so most applications are going to be the same as the ones you would find on the BSD machine. If you still wanted to do it, you would need to grab the manual pages of the same applications in *nix as in Mac as well as the same version (since the man page can change). And yea, I would say that doing a diff /usr/share/man/man[0-9]/* and the expanded tar of all the man pages from the linux box.

Resources