Compiling with autotools: Retroactively change configure flags - compilation

Say I have compiled a project (not my own) with autotools and passed some flags to configure. Now I want to compile this same project again, but with slightly different configure flags. Is there a way to tell the configure script to use the old flags, but update them with some additional ones?

I would love to see an easier approach, but to simply add flags you can do:
sed -i '/^ac_configure_extra_args=/s/$/--new-flag --other-flag/' config.status
./config.status --recheck
Normally, I manually edit config.status to do this, and not all sed support -i, but you get the idea. Change the original flags as they are defined in config.status to be the flags you want.
Another option is to cut-n-paste the original configure invocation out of the top of config.log and edit it.

Related

Makefile generate by CMake contains 'cmake' command

I'm trying to use cmake for the first time and it seam to be good except one things.
In the generated makefile, there are some kind of 'cmake command'. Like :
$(CMAKE_COMMAND) -E cmake_progress_start ... etc ...
I really want to generate makefile without any $(CMAKE_COMMAND).
Is it possible ?
Thx.
I doubt you can achieve that, because cmake executable is used to regenerate Makefiles if any of CMakeLists.txt are changed.
I just want to generate Makefile and ensure me that I can build my source code without Cmake.
I found a solution by just do :
make -i
It will ignore error and a call to cmake append and that work. It's a huge workaround but that's work so...
Thx for your answer.

Generate make file

I have a golang CLI program which generates a makefile to a specific project. While this works, there is an issue when the project already has a makefile. Of course I can check that in advance to avoid collusion, but how is it suggested to do it?
I'm not an expert in makefiles, but how can I create second makefile (maybe with the project name or something) that user can run via make (I guess with additional steps or info to the terminal)
You can generate it as Makefile.project and document to be run as make -f Makefile.project
You can give your Makefile whatever filename. Then make must be executed with parameter -f <your_filename> or --file=<your_filename>. See make manual on filenames.
Which version of make are you using? Some versions run special makefiles before others. For example, GNU make looks for the following files and runs the first one it finds: GNUmakefile, Makefile, makefile.
If you are using GNU make, then name your generated file GNUmakefile and add in the making any makefile already in the directory. That way, anyone running make in the directory will automatically run the generated makefike first.

How to Change the Default Command That make Executes?

By default, when running make to compile a C source code file named prog.c
make prog
the default command that executes is
cc prog.c -o prog
Sometimes I really need to include some additional flags. I know that when there are no Makefiles, make relies on some environment variables.
On Ubuntu 14.04, how to configure these variables to change the command that gets executed by default?
Step by step answers will be appreciated!
When no makefile is present (or no rule exists in that makefile) make relies on a default built-in database of rules. Run make -p to get make to spit out all the rules it knows about (in the no makefile case that will be the default ones).
When you look at that list you will find a pattern rule for building C source into object files or executables. Those rules have variables in them (like CFLAGS, LDFLAGS, etc.) that can be used to control exactly what you are trying to. That's why they are there (and are why that default command has such funny spacing, in case you ever wondered about that).

Is there a way to make a c++ compiler flag as default

Just like we specify input flags in the settings of the project in Xcode
Can I make few flags like -O3 or -fopenmp as default flags in command line when I use Terminal.
So that I dont have to type them everytime I compile some c++ fies. Is there a file in the installed gcc or C++ that I can edit to make them default.
Please let me know
thanks
For situations like this you'd probably use a makefile if it's project specific (or other similar automated build management like scons or cmake).
If you want it always on the terminal, you can alias your command to always specify those options, i.e.
alias g++='g++ -O3 -fopenmp'
Note that you said 'terminal' so I assume this is a type of *nix. If that is the case you can also set this into your terminal profile, like ~/.bashrc if you use bash, or ~/.zshrc if you use zsh, etc.

Control GNU autotools make output

I am using GNU autoconf/automake. Is there any way I can control what make prints to stdout from configure.ac or Makefile.am? For example, suppress mv and cp commands being printed out to the screen, only print the name of the file being compiled by gcc rather than the whole command line, highlight gcc warnings in some way.
Is Prettify Automake what you want?
Edit: As of Automake 1.10b, silent-rules is built-in. Not the same code or style but similar in effect.
Modern Automake (after in 1.10b) supports --silent-rules which will suppress the full compile command. (eg, output is "CC foo" instead of "gcc -DHAVE_CONFIG_H ...") That may be all you need. You need to add "silent-rules" to AM_INIT_AUTOMAKE and pass --enable-silent-rules to configure (or put it in CONFIG_SITE) to enable the feature. See the automake docs for details.
I believe the easiest thing is to write a wrapper script which runs *make and parses the output. I believe I have seen this being done in Ubuntu somewhere ...

Resources