Make requires an input file (called Makefile or makefile) which
describes the dependencies and rules for compiling.
This file must be stored in the ~
project/src directory.
For every target which has to be made list a dependency.
Make maximum use of environment variables and implicit rules.
If the implicit rules are not sufficient the define new
ones (there are many implicit rules - to find out a list of implicit
rules type make -p | less).
The following standard targets must exist in every Makefile :
Multi-platform support can be handled in one of two ways :
A simple example Makefile using this method is :
Makefile -------- # # Makefile for compiling the program "main" on multiple platforms # (sun and linux) # # author : andy gotz # # history : 7nov95 - created # #ifdef "sun4" CC = cc CFLAGS = -suncflags LFLAGS = -sunlflags INSTALLDIR = /usr/local/bin #else CC = gcc CFLAGS = -linuxcflags LFLAGS = -linuxlflags INSTALLDIR = /bootes/usr/local/bin #endif all : main main : main.o $(CC) $(LFLAGS) -o main main.o install : all cp main $(INSTALLDIR) clean : rm -rf *.o
Using this approach the above example would be two files :
Makefile.sun4 ------------- # # Makefile for comiling the program "main" on a sun4 # # author : andy gotz # # history : 7nov95 - created # CC = cc CFLAGS = -suncflags LFLAGS = -sunlflags INSTALLDIR = /usr/local/bin all : main main : main.o $(CC) $(LFLAGS) -o main main.o install : all cp main $(INSTALLDIR) clean : rm -rf *.o Makefile.linux ------------- # # Makefile for comiling the program "main" on a sun4 # # author : andy gotz # # history : 7nov95 - created # CC = cc CFLAGS = -linuxcflags LFLAGS = -linuxlflags INSTALLDIR = /bootes/usr/local/bin all : main main : main.o $(CC) $(LFLAGS) -o main main.o install : all cp main $(INSTALLDIR) clean : rm -rf *.o