What is make? What is gcc?
Archive - Originally posted on "The Horse's Mouth" - 2015-11-28 07:43:56 - Graham EllisMake is a tool which lets you define a whole series of commands you need to run to get from the basic data and program source files that you work on during development, or distribute to your technical customers into the final product / products that you need.
Typically and traditionally, make reads a file called makefile that takes a series of instructions on the commands that are used to make a "target" from a "dependency", and runs those instructions if (and only if) the target doesn't exist, or is older than any of its dependencies. The order of operations is taen into account, with some targets in a process being dependencies for the next stage of the process. Make is very clever in that it allows you to make a very limited number of changes in your sources, and will then only rerun the steps needed when your rebuild your final produt, skipping those unchanged. However, make is only the pilot and not the aircraft - it only controls the work rather than doing the hard work, and it's of no use without its tools of trade such as gcc
Gcc is the tool which converts your C or C++ (or other language) into binary 'object' files for your target processor and operating system, then connects these object files and standard libraries together into a final executable program file. There are a number of intermediate steps (usually run in an automatic sequence), and the gcc command bolts these steps together depending on command line options given to it, which can be long and complex. That's one of the reasons you need a script (or, better, a makefile) so you don't have to keep re-keying the steps at the keyboard.
Although "gcc" stood initially fot the "Gnu C Compiler", it's now the "Gnu Compiler Collection" and to it's no longer just C ... C++ is an obvious extension but it will handle other languages like Fortran and Java (via gcj) for example.
For the bash scripting course I ran last week, I provided a brief "hello world" intorduction to make and the compiler tools. Two program source files were provided - demo.c and more.c - the main program and subsidiary functions for a little C demonstration. I also provided a simple makefile to store / reuse / control the various invocations of gcc needed to build the final executable program.
Although the tradiational, and taught, use of make is in building executable programs, it can also be used for other jobs with similar characteistings - be it to build a website, documentation, a database. For example, the makefile that's distributed with the Apache httpd web server not only builds the executable, but also the documentation. And a separate make process can be used to go through the multisteps to install the executabela and documentation
Such a clever idea there are other tools that do something similar - you have ant for the Java world, and in Ruby you have rake which you'll typically use to rake over the results of one of your tests on a database and prepare for the next test - removing damaged tables and re-creating them from source data. It's not a compile, but it's very much a process of the same pattern.