ChorusOS 5.0 Source Delivery Guide

Building a Component With imake

This section describes how to build a ChorusOS component with imake and the basic operations needed to manage your component. The information is provided in the form of a tutorial, leading you through an example which shows you how to perform each step.

The procedures below show you how to build a very simple ChorusOS component called TEST, containing an application that displays a short message.

Build a TEST Component
  1. Create a TEST directory in your /tmp directory to contain your new component.

    host% cd /tmp/TEST
    host% mkdir TEST
    
  2. Add the files listed below to the TEST directory

    • Makefile.bin

    • Makefile.src

    • Project.tmpl

    • Imakefile

    • src.df

    Examples of these files are given below.


Example 4-7 Creating a TEST Component: Makefile.bin

The Makefile.bin file can contain the following information:

COMPONENT += TEST
ROOT      += $(TEST_DIR)/root

TEST.all::

The first line in the output, which declares the component's name, is mandatory.

As the COMPONENT variable is the list of all components to be configured, use '+=', and not '='.

The ROOT variable contains a list of directories to be copied to the target root file system.



Example 4-8 Creating a TEST Component: Makefile.src

The Makefile.src file, can contain the following information:

all:: TEST.all 

TEST.all:: NUCLEUS.all OS.all DRV.all
TEST.all:: $(TEST_DIR)/DONE

$(TEST_DIR)/DONE: $(TEST_DIR)/Makefile
        sh $(DEVTOOLS_DIR)/resync TEST -f $(TEST) -s $(TEST_DIR)
        cd $(TEST_DIR); $(make)
        touch $(TEST_DIR)/DONE

$(TEST_DIR)/Makefile: $(TEST)/Imakefile
        sh $(DEVTOOLS_DIR)/ChorusOSMkMf $(BUILD_DIR) -s $(TEST) 
        -b $(TEST_DIR) -d
$(TEST_DIR)
        cd $(TEST_DIR); $(make) Makefiles

TEST_DIST = $(BUILD_DIR)/dist-TEST
TEST.dist: TEST.all
        rm -rf $(TEST_DIST)
        cd $(TEST_DIR); $(make) DIST_DIR=$(TEST_DIST)

This file is more complex than the Makefile.bin file as it describes how to build the component. The first lines of output give the list of components that must be built before the TEST component.

As your application requires operating system services, you must build the NUCLEUS and OS components before building the TEST component.



Example 4-9 Creating a TEST Component: Project.tmpl

The Project.tmpl file can contain the following information:

#include "Package.rules"

SRC_DIR         = SourceDir
BUILD_DIR       = BuildDir
DIST_DIR        = DistDir

VPATH           = $(SRC_DIR)$(REL_DIR)

WARN            = $(WARN_ON)

TEST_DIST_BIN   = $(DIST_DIR)/bin/test


Example 4-10 Creating a TEST Component: Imakefile

The Imakefile indicates that you will have subdirectories (in this case /src).

#define IHaveSubdirs

SUBDIRS = \
        src

DistFile(Makefile.bin,$(DIST_DIR))


Example 4-11 Creating a TEST Component: src.df

The src.df contains the following information:

. ../Paths
VARIABLES="OS_DIR NUCLEUS_DIR"
BDIR=${BUILD_DIR}
SUB_DIRS=src

This file sets the parameters required for the make command to work.


Creating a Simple Hello Application

You now need to create an application for the TEST component to perform.

  1. Create a subdirectory, src, within your /tmp/TEST directory.

    host% cd /tmp/TEST
    host% mkdir src
    
  2. Create the following two files:

    bonjour.c

    This source file will say "Hello World":

    #include <stdio.h>
    int main()
    {
          /* Print the message */
      printf("Hello World\n");
      return 0;
    }

    Imakefile

    This file provides rules to build the application:

    CSRCS=  bonjour.c 
    
    OBJS= $(CSRCS:.c=.o)
    
    DEBUG=$(DEBUG_ON)
    
    UserActorTarget(bonjour_u,bonjour.o,)
    SupActorTarget(bonjour_s, bonjour.o,)
    
    DistActor(bonjour_u, $(DIST_DIR)/root/test/src)
    DistActor(bonjour_s, $(DIST_DIR)/root/test/src)
    The Imakefile file declares:
    • The source files to be compiled.

    • The libraries to be used.

    • The fact that you want to build the bonjour actor.

    • The fact that you want to copy the bonjour actor into the root/bin directory, once it is built.

  3. Build your component in your work directory using the make command

    host% make
    
  4. Add the bonjour binary file to the target file system

    host% make root
    
Adding the Component to the System Configuration

Once you have created the component, with its application, you must include it in the system configuration.

  1. Run make reconfigure

    Use the make reconfigure command in the directory in build_dir in which you have previously run configure to build your system image. Run make to compile your component:

    host% make reconfigure='-s /tmp/TEST'
    
  2. Compile the component

    Type make to compile your TEST component.

    host% rm -rf build_dir/build-TEST
    host% make