shell - portable way to get `make´ version - shell

I'm writting my own "configure" script for my package. The Makefile uses some features (e.g.: the "call" function) that were added to GNU make in certain versions. I'd want to check if installed `make´ utility is GNU's one and if it support that features, but I have no idea about how to do it.
As the `configure´ script is supposed to be portable (and I want to avoid Autoconf, SCons... and any other, although that's not the question) I need a portable solution. I have looked through my GNU make's documentation and did not find anything useful.
Thanks in advance (and, of course, sorry if this question is irrelevant or if you guess that checking presence & usability of `make´ tool is not part of configure's job).
PS: I've just found `make -p´ option, whose first line prints # GNU Make 3.81 for me, but, another time, I don't know if that's another GNU extension or if it is "standard".

I would run make --version.
If it is GNU make it will be something like:
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.
So the first line contains the version version and indicates that it is GNU make. If the first line contains something else, including maybe an error message that the version option is not supported, it is not.
You could also emit a temporary Makefile from your configure script, containing those commands that you require. If the make you find on can run it without errors, I.e. with exit code 0, you’re good. No need to determine the exact version. Checking for features is in the spirit of the "real" autoconf and probably more reliable than checking version numbers and using the implicit knowledge of what they support and what not.
Finally, consider looking into the "real" configure / autoconf tool to see how they do it - or even use it instead of your own.

make --version is a "local standard" for GNU tools. If you aren't going to support other makes, it's enough for your purpose, assuming:
that you know version number of GNU make where the features you use were added,
that some other implementation of make won't interpret --version in a harmful way, and won't describe itself as GNU Make 9.99.

Related

When using clearmake, MAKEFILE_LIST is an empty list

When I use clearmake -C gnu on makefiles that use the MAKEFILE_LIST variable, MAKEFILE_LIST is empty. But when I use regular GNU make on the same makefiles, MAKEFILE_LIST is a list of file paths and names (as it should be).
To see what MAKEFILE_LIST is equal to, I'm using $(info $$MAKEFILE_LIST is [${MAKEFILE_LIST}]). There are no spaces in any of the file names, so I know that's not causing any problems, and the ClearCase manual lists some features of GNU make that clearmake does not support, but MAKEFILE_LIST is not among those features.
Has anyone else experienced a similar problem with clearmake and MAKEFILE_LIST? If so, were you able to fix it and how?
Had to look up the MAKEFILE_LIST macro to see what it did. And yes, this isn't something that clearmake currently supports. It's also not something listed as explicitly not supported.
I used the sample make snippet at https://www.gnu.org/software/make/manual/html_node/Special-Variables.html to confirm the lack.
I can't categorize this as a defect, so the best bet would be to avoid the middleman and enter the RFE in the Developerworks RFE community at https://www.ibm.com/developerworks/rfe/
If at all possible, can you please provide a "business justification" in Manager-Speak (Dollars lost/Man hours needed to work around not having the capability)? Like every other non-startup development shop, developer time is at a premium, so it's important to put the impact in.
I can't say that you'll get the answer you want, but you should get a response.
From what you've written looks pretty clear that it's not supported; just because it's not listed in the manual doesn't mean that they support it. That manual might have just not been updated. However, MAKEFILE_LIST was added in GNU make 3.80 which was released in 2002. Pretty lame if they don't indeed support it.
For the amount of $$ you're paying for ClearCase, I would recommend you contact their support and ask them directly rather than trying to get answers from StackOverflow :).
In any event if you want answers from people who use ClearCase I suggest you add that, or at the very least clearmake, to your list of tags.
As illustrated in "Rational ClearCase: clearmake -C gnu and GNUmake diferences.", clearmake is not gmake.
And this thread makes it clear that "base ClearCase" isn't exactly actively developed (though it is still very much maintained with ClearCase 9.x, as shown in this recent clearmake output format).
MAKEFILE_LIST is not mentioned in "env_ccase" (which includes standard UNIX and Linux EVs that are particularly important for ClearCase and MultiSite), and I never had the occasion of using it.

Link go program vs GNU readline statically

I'm writing a Go program that uses the GNU readline library for a fancy command line interface. In order to simplify the installing process and not worry about the library version and other stuff, I want to link it statically.
The problem is I don't really know how to do it. If I precompile the library, I would have to provide several versions of my code, with the different versions of the .a or .lib readline library. To avoid this problem I was thinking of just including the current readline code to my go project, and let the go tool compile it when it build the go project. However, to build the readline library, is necessary to use make. Is there a way of telling the go tool how to build the C code?
Yes, you can certainly do that. I've recently done something similar with a different project, mainly because the code was not available as a library (Ubuntu compiles just the command line tool for it). To achieve it, I've run the autoconf script with options that I figured would be sensible in most systems, and copied the C code together with the automatically built config.h header file into the Go package directory. Then, I've built the original C code with make once and observed which options gcc would get while compiling and linking it, and copied the appropriate ones into cgo's LDFLAGS and CFLAGS options (you can also inspect the Makefile, but that was easier).
A couple of side notes:
Have you considered doing the readline work in Go itself? The ssh terminal package works at least as a pretty good seed, if it doesn't solve your problem completely.
Remember that readline, although being a library, is GPL. You'll necessarily have to license your own software as GPL as well if you link or embed it. There are other smilar libraries available with less strict licenses, if you care.
I recommend avoiding readline, better alternatives exist; like https://github.com/edsrzf/fineline

multiple-version gcc management in gentoo system

I know we can always use eselect to change the compiler version. My question is that possible to bind different version to different users. For example, I would like root to use stable version for sure. and meanwhile, I would like my normal user to use some edge-cutting version.
I expect some clean solution instead of switch manually by using eselect
Thanks
I really hope you're not using eselect for this. eselect-compiler was killed off years ago because it was experimental and had many problems. gcc-config is what you should be using. Unfortunately it doesn't have per-user support like we have for Java. You can always call the specific version explicitly (e.g. gcc-4.6.2 instead of just gcc). If you're building software with autotools then you can do it with...
CC=gcc-4.6.2 ./configure
make
You can use gcc-config to print the environment variables necessary to use a specific GCC version. For example, to use gcc-7.2.0 for the remainder of your shell session:
eval "$(gcc-config --print-environ x86_64-pc-linux-gnu-7.2.0)"

Checking and compiling Protocol Buffers using GNU build tools

So I've this project which depends on Google's Protocol Buffers compiler and libraries. Checking for the libraries is easy as a pkg-config file is provided, thus the checking process is reduced to PKG_CHECK_MODULES([protobuf], protobuf). Yet I'd like to check for the protoc compiler, or similar tool (in order to auto-magically build my .proto files).
Could anyone please provide some form of macro, or good tutorial on macro making (I haven't found anything useful so far...).
Julian.
To check for the presence of particular programs, you should use either AC_CHECK_PROG or AC_PATH_PROG. See the GNU Autoconf Manual.
AC_PATH_PROG(PROTOC, protoc, no)
if test "x$PROTOC" = "xno" ; then
AC_MSG_ERROR([protoc is not found])
fi
See also this other question.

Tool for debugging makefiles

I have a large legacy codebase with very complicated makefiles, with lots of variables. Sometimes I need to change them, and I find that it's very difficult to figure out why the change isn't working the way I expect. What I'd like to find is a tool that basically does step-through-debugging of the "make" process, where I would give it a directory, and I would be able to see the value of different variables at different points in the process. None of the debug flags to make seem to show me what I want, although it's possible that I'm missing something. Does anyone know of a way to do this?
Have you been looking at the output from running make -n and make -np, and the biggie make -nd?
Are you using a fairly recent version of gmake?
Have you looked at the free chapter on Debugging Makefiles available on O'Reilly's site for their excellent book "Managing Projects with GNU Make" (Amazon Link).
I'm sure that remake is what you are looking for.
From the homepage:
remake is a patched and modernized version of GNU make utility that adds improved error reporting, the ability to trace execution in a comprehensible way, and a debugger.
It has gdb-like interface and is supported by mdb-mode in (x)emacs which means breakponts, watches etc. And there's DDD if you don't like (x)emacs
From the man page on make command-line options:
-n, --just-print, --dry-run, --recon
Print the commands that would be executed, but do not execute them.
-d Print debugging information in addition to normal processing.
The debugging information says
which files are being considered for remaking,
which file-times are being compared and with what results,
which files actually need to be remade,
which implicit rules are considered and which are applied---
everything interesting about how make decides what to do.
--debug[=FLAGS] Print debugging information in addition to normal processing.
If the FLAGS are omitted, then the behaviour is the same as if -d was specified.
FLAGS may be:
'a' for all debugging output same as using -d,
'b' for basic debugging,
'v' for more verbose basic debugging,
'i' for showing implicit rules,
'j' for details on invocation of commands, and
'm' for debugging while remaking makefiles.
I'm not aware of any specific flag that does exactly what you want, but --print-data-base sounds like it might be useful.
remake --debugger all
More info https://vimeo.com/97397484
https://github.com/rocky/remake/wiki/Installing
There is a GNU make debugger project at http://gmd.sf.net which looks quite useful. The main feature supported by gmd is breakpointing, which may be more useful than stepping. To use this, you download gmd from http://gmd.sf.net and gmsl from http://gmsl.sf.net, and do an 'include gmd' in your makefile.

Resources