The hello world program presented in the previous section is a simple program merely serves to demonstrate the basics of compiling a program. A more complex program with multiple objects, it is generally accepted, would require a make file to manage dependancies.
Example 22.2. Example using a makefile
The hellogoodbye program is a trivial program which uses two objects and displays some simple messages.
/* hello.c */ #include <stdio.h>> extern void goodbye(void); void hello(void) { printf("hello world\n"); } int main(int argc, char**argv) { hello(); goodbye(); }
/* goodbye.c */ #include <stdio.h>> void goodbye(void) { printf("goodbye world\n"); }
A simple example makefile which builds the hellogoodbye program
from two objects (hello.o
and
goodbye.o
). This takes advantage of a
provided makefile fragment which sets up the correct compiler
variables (CC LD etc.).
# hellogoodbye/Makefile # # ABLE hellogoodbye command APP_VERSION=1.00 CFLAGS=-O2 -Wall -DAPP_VERSION=\"$(APP_VERSION)\" LDFLAGS= # default location for install INSTALL_PATH ?= $(shell pwd) # default location for clib ABLE_CLIB ?= /opt/simtec/able # Standard ABLE application makefile support include $(ABLE_CLIB)/app-Makefile .PHONY: all clean install all: hellogoodbye hellogoobye: hello.o goodbye.o clean: $(RM) hello.o goodbye.o hellogoodbye install: cp hellogoodbye $(INSTALL_PATH)/hellogoodbye-$(APP_VERSION)
This example can be compiled with make. When executed it should produce the result:
>hellogoodbye hello world goodbye world >