Computer Science Canada

[Tip] Makefiles

Author:  wtd [ Wed May 31, 2006 11:12 am ]
Post subject:  [Tip] Makefiles

Learn to use makefiles.

This means practicing. A lot.

When you want to compile your "hello world" program... write a makefile.

You'll be glad you did.

Author:  md [ Wed May 31, 2006 11:24 am ]
Post subject: 

A simplish makefile for a "Hello, world" app. The code is all in the file main.cpp. It could be simpler yes... but this gives an idea of how things can be done without making it horribly complicated (see http://files.nxor.org/makefile).

code:
#
#   "Hello, world" makefile
#   
#

########################################
# compiler & linker
#
CC = g++
LN = g++


########################################
# build options
#
CXX_FLAGS = -g -Wall
LN_FLAGS =
LN_LIBS =

########################################
# rules

#default rule
all: hello

# main
main.o : main.cpp
        ${CC} ${CXX_FLAGS} main.cpp -o main.o

# the app       
hello : main.o
        ${LN} ${LN_FLAGS} ${LN_LIBS} main.o -o hello
       
# clean
.PHONY : clean
clean :
        touch main.o
        touch hello
        rm main.o hello


: