22.4. A simple command built with two objects

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");

main(int argc, char**argv)
/* 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



# 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

        $(RM) hello.o goodbye.o hellogoodbye

        cp hellogoodbye $(INSTALL_PATH)/hellogoodbye-$(APP_VERSION)

This example can be compiled with make. When executed it should produce the result:

hello world
goodbye world