makefile and its uses - c++

What is a makefile and how do I use it?

A make file describes the compilation process. It describes which flags, compiler tools, linkers, etc. to use with which source code files and objects
More info
http://www.sis.pitt.edu/~mbsclass/tutorial/advanced/makefile/

The main purpose of a Makefile is to store every you need to build your project in one place. It contains the instructions for compiling your code, linking your compiled code, packaging the executables, extracting third party tools, and many other useful things. Pretty much any command you entire at the command line can be used in a makefile.
The advantage to using a makefile, when done correctly at least, is that anyone can easily build your entire project. It's as easy as typing make
An example of a Makefile for a windows project http://www.opussoftware.com/tutorial/TutMakefile.htm

Related

Do I have to fully rebuild LLVM after editing a file?

I am tweaking LLVM files and do a "make" in my build director to rebuild LLVM with the tweaked files, which is taking a while even though my changes were rather small (I understand that my one file will be affect other files). Do I have to use 'cmake --build .' to generate a new make file in the build directory or is it right to just call 'make'. And is it common for rebuilds to take a while?
I think, most time is spent re-linking the binaries, of which LLVM has many (opt, llc, etc.). One option to speed up the build is to enable LLVM_BUILD_LLVM_DYLIB and LLVM_LINK_LLVM_DYLIB and the other is to issue make opt instead of make, if you are mostly working with opt.
These options would make build system produce a single giant dynamic library (.so or .dll) containing all LLVM components (LLVMSupport, LLVMCodegen, etc), and make tools link to it. Linking to a dynamic library is much faster, because you don't need to re-link all the static code for each tool executable.
Also if you for example just modify a backend target, then its enough to issue make in tools/llc dir. This way only the required tool will be relinked, thus fasten the build process.

How to manage building a huge source code that uses gnu autotools?

I have multiple source codes which I have to cross-build and use together as one huge project. The building process of each source code is the same './configure-make-make install' commands with added parameters for cross compilation. So far I have been managing this by typing a really long configure command "./configure CC=....." in text editor and then copy pasting that on to terminal and running it. Then repeating the process for another source code. Taking care of multiple include paths, library paths, pkg-config paths etc. the process turns out to be very messy, error-prone and cumbersome. I have already used eclipse ide and have found no option for configuring the "./configure .." command to my need. Is there any elegant way to handle this problem? I would like a solution which will require me to write minimal amount of script/instruction.
Is there any elegant way to handle this problem?
If you want to automatize the configuration and compilation of several sub-projects which are actually one project, I suggest you to use the GNU/Autotools canonical way to deal with it with is Nested Autotools project
In that way you can do a project which contains all the other projects in the following fashion:
./UmbrellaProject
subproject1/
subproject2/
...
Makefile.am
Inside the parent project Makefile.am you will have a line at the beginning such as:
SUBDIRS = subproject1 subproject2
More information at the GNU Automake docs

Building Custom Files with scons

My C++ project includes a Bison parser. What is the scons function to call for building from ".l" and ".y" files (or alike)? By build I only mean compiling the grammar into source code.
I assume that building from lex/yacc files are natively supported, but I'm curious as to what would one need to do if one has to also build some files with an 'uncommon' compiler, say a DSL compiler for that specific project.
If you want to "teach" SCons how to process a new filetype, all you basically have to do is copying the command-line. Then you put this command into a so-called Builder, which will execute the required action at runtime and will care about the dependencies for you.
For a more detailed description of solutions to this problem, which actually depend on what exactly you want to accomplish, please have a look at our ToolsForFools guide.

What do you mean by 'make' command in linux?

First, i know that make is used for building the code. But which code?
But what does it mean by building a code, and after executing the make command, what is presented to the user?
Second, how is it different from make build_for_e2e?
What Wikipedia tells about make
Make is a build automation tool that automatically builds executable programs and libraries from source code
Compilation process becomes big and complex in big projects, where numbers of files need to be compiled, with flags and libraries. Where it will become hard for people to compile it one by one. So these types of tools were introduced, there are more similar tools available for same use like cmake, gradle, maven. e2e's Build is also a form of build process, with different form of specifications.
For C people mostly use make. It is helpful for porting software packages in different systems.
How make is used:
As said make is a tool, which will be available in our system, we can execute it by giving command make in the directory which needs to be compiled. Then make looks for Makefile, which is provided in the package directory and it contains information about compilation of the project. Then make as per info gathered from Makefile, it compiles the package.
You can also create Makefile for your project, so that it can be also supported and compiled with make. Simple tutorial for it can be found here. For big projects you can use gnu autotools contains autoconf and automake which will help you to create your all files required by make automatically. You can find tutorial regarding it here and here . These contains some basic information, you can find some advance tutorial regarding autotools, use google for more information on it.

What is MakeFile in Eclipse?

What is MakeFile in Eclipse? From the documentation:
A makefile is a text file that is referenced by the make command that
describes the building of targets, and contains information such as
source-level dependencies and build-order dependencies. The CDT can
generate a makefile for you, such projects are called Managed Make
projects. Some projects, known as Standard Make projects, allow you to
define your own makefile.
But the explanation does not help me understand what a MakeFile is. I am moving from VisualStudio/C# to Eclipse/C++. Is MakeFile analogous to Visual Studio's Metadata? When do I need to write a MakeFile, and why do I need it besides the C++ code?
[EDIT]
I used to develop on Windows with VS and C#. And now trying Eclipse/C++ on a Mac. I have never build anyone on Linux. So the answer I have read so far does not help explain anything at all.
A makefile in the simplest terms is a file that builds a program. These are normally used from the command line. If you have ever built something on linux you may have run ./configure ; make ; make install. You are using a makefile there.
More info...
https://en.wikipedia.org/wiki/Make_(software)
In simple terms: Make helps you create cross-platform configuration settings in one file, and it will work on surprisingly many platforms, including Windows or Mac OS-es.
Mentioning Windows, you should have Make installed on the computer you're installing on (on Windows, Cygwin and MinGW include Make). It's required only if the user will actually build the code from the source.
But of course, you should include Make code for each different platform (e.g. one for Unix-like, one for Windows, etc.)