Red Antigua Logo
Yet another piece of web.
Search this site (by Google)
Tools    (top)
Check a site for broken links
(W3C)

Perl modules    (top)
Tree::Numbered::Tools
(CPAN)
Perl tutorials    (top)
Perl modules
HTML::Template
CGI::Application
Cookies with CGI::Application
Upload files with CGI::Application
Download files with CGI::Application
Redirect with CGI::Application
CPAN shell
Install DBD::mysql from the CPAN shell
Perl trim function
Validate an IP with Perl
Run suid Perl scripts under Apache
Perl taint mode
Perl date functions with Date::Calc

In Spanish
Curso de Perl

C tutorials    (top)
C - Introduction
C - Absolute beginner's Emacs
C - Examples for beginners
C - Makefile examples
C - Autotools examples
Server configurations    (top)
DNS
Apache
Apache Authentication and Access Control
mod_perl on FreeBSD
MySQL
MySQL add account
phpMyAdmin
Squid
DHCP

UNIX on Windows    (top)
MSYS2 - UNIX environment for MS Windows 32/64 bits
Apache setup on Windows
MySQL setup on Windows
PHP setup on Windows
Perl setup on Windows
Emacs setup on Windows
PuTTY
WinSCP
GIMP on Windows
MinGW - gcc on Windows
MSYS - UNIX-styled shell on Windows
msysDTK - autotools on Windows
GDB for MinGW on Windows

Misc. FreeBSD/UNIX    (top)
'portupgrade' on FreeBSD
'ipf' on FreeBSD
'pf' on FreeBSD
'su' on FreeBSD
Mount an ISO image under FreeBSD
Load the correct sound driver under FreeBSD without knowing what sound card you are using
Simultaneous sound channels on FreeBSD
FreeBSD network stuff
DOS-to-UNIX file conversion
favicon.ico on UNIX
Emacs tips
Command Line Calculator
Save multimedia streams with 'mplayer'
xargs - solution to 'Argument list too long'
Process multiple images from the command line using 'ImageMagick'
Turn the system bell off under X Windows
Process each line in an input file from the command line (or in a shell script)
How to keep a program running in the background using 'nohup'
How to remove symbolic links in the current directory using 'find' and 'rm'
How to remove Emacs backup files in the current directory and all subdirectories using 'find' and 'rm'
How to execute .profile without logging in
Configure X to handle non-English characters
How to move /var to /usr/var

Redirect a web page    (top)
Redirect to another web page
Apache redirect
C redirect
Perl redirect
PHP redirect
HTML redirect
JavaScript redirect

Javascript    (top)
Trim function
Login form
Register form
Popup window

C - Makefile examples - Index
C tutorials » Makefile examples
What is a Makefile, and why use it?
Very brief: When compiling/linking any software project, using make and Makefiles makes life easier.

Why not compile from the command line? Or use a shell script to compile?
Compiling from the command line soon become tedious due to all the cc compiler flags:
cc -a -whole -lot -of -flags -and -arguments myprog.c -o myprog
make is smart enough to make you type less, even without a Makefile:
make myprog CFLAGS='-a -whole -lot -of -flags -and -arguments'
While a shell script is more suitable for generic usage, a Makefile is more powerful when it comes to passing environment variables, keeping compiled programs up to date, managing dependencies, etc.
make can be seen as a "specialized software compilation shell scripting tool".

Create the following one-liner Makefile, and you can forget about the flags and arguments one for all:
CFLAGS=-a -whole -lot -of -flags -and -arguments
Lets say you have several source code files in the same directory: myprog.c, yourprog.c, herprog.c, hisprog.c
They may now be compiled with the same flags:
make myprog yourprog herprog hisprog
Try that with a shell script! (Not impossible, but more complicated.)

Note for gcc newbies:
The Makefile examples listed here all use C source code as input, which will be compiled with gcc.
Therefore it is recommended to read the relatively short but valuable text Compiling with cc if you aren't up to date with gcc and its most common flags.

Note for BSD users:
The Makefiles have been tested with GNU make. If you have any problem using them, perhaps you are using BSD make when you type make. On a BSD system, chances are you also have GNU make installed, where it is called gmake. Check out the make portable example for a Makefile valid both for BSD make and GNU make.
  1. make minimalistic
  2. make file
  3. make hello
  4. make hello.o world.o main.o
  5. make dependencies
  6. make implicit
  7. make include
  8. make automatic variables
  9. make environment variables
  10. make wildcard
  11. make pattern
  12. make print data base
  13. make windows or not
  14. make cpp macro list
  15. make gtk
  16. make shared lib bsd
  17. make portable
  18. make image magick
  19. make docbook
  20. make automake
Last modified: Thu Sep 8 04:46:19 EDT 2016