The TMS Development Platform

by Alexander Frey



Listing One



# a project makefile



# check input

ifndef TMS_BASE_DIR

$(error "Error: TMS_BASE_DIR not defined!")

endif

ifndef TMS_TARGET

$(error "Error: TMS_TARGET not defined!")

endif



# the directory containing this file

CURRENT_DIR = $(TMS_BASE_DIR)/MyProject/prj



# include common compiler flags, definitions and user settings

include $(TMS_BASE_DIR)/makefiles/$(TMS_TARGET)_makefile_settings.mak



# additional include directories, compiler and linker flags 

CINCS +=

CFLAGS +=

LDFLAGS +=



# objects

LIBOBJECTS= $(OBJDIR)/MyProject.o



APPOBJECTS= $(LIBOBJECTS) \ 

                $(OBJDIR)/testMyProject.o

# tests

TESTS = std



# targets

ARCHIVE     = MyProject

APPLICATION = MyProject



# include extern projects (dependencies)

include $(MAKE_DIR)/inc_MyTimer.mak



# create targets

include $(TMS_BASE_DIR)/makefiles/$(TMS_TARGET)_makefile_create.mak





Listing Two



# settings makefile for gcc



# check input

ifndef TMS_BASE_DIR

$(error "TMS_BASE_DIR not defined!")

endif

ifndef CURRENT_DIR

$(error "CURRENT_DIR not defined!")

endif

ifndef TMS_TARGET

$(error "TMS_TARGET not defined!")

endif

ifneq "$(TMS_TARGET)" "gcc"

$(error "TMS_TARGET not gcc!")

endif



# include user settings

#######################

include $(TMS_BASE_DIR)/makefiles/

                     user_settings/$(TMS_TARGET)_makefile_user_settings.mak

# check user settings

ifndef DEBUG

$(error "DEBUG not defined!")

endif

ifndef HWPLATFORM

$(error "HWPLATFORM not defined!")

endif

ifndef OS_TYPE

$(error "OS_TYPE not defined!")

endif

ifndef GCC

$(error "GCC not defined!")

endif



# You normally should not need to change the following; add 

# additional include-directories and compiler/linker flags in your makefile

#############################################################################

CC          = $(GCC)/gcc

AS          = $(GCC)/as

LD          = $(GCC)/gcc

AR          = $(GCC)/ar

CINCS       = -I. -I/usr/local/include -I/usr/include

ASMFLAGS    = 

CFLAGS      =  -DLINUX -DHW_X86

LDFLAGS     = 

LDPREFIX    = -l

LDSUFFFIX   = 

LDPATHPREFIX= -L



# input/output directories

##########################

MAKE_DIR = $(TMS_BASE_DIR)/makefiles/inc



REL_BINDIR    = ../bin/$(TMS_TARGET)

REL_LIBDIR    = ../lib/$(TMS_TARGET)

REL_OBJDIR    = ../obj/$(TMS_TARGET)

REL_SRCDIR    = ../src

REL_PRJDIR    = ../prj

REL_TESTDIR   = ../test

REL_EXTINCDIR = ../extinc

REL_EXTLIBDIR = ../extlib/$(TMS_TARGET)



ifeq "$(DEBUG)" "YES"

REL_BINDIR_EXP    = $(REL_BINDIR)/debug

REL_LIBDIR_EXP    = $(REL_LIBDIR)/debug

REL_OBJDIR_EXP    = $(REL_OBJDIR)/debug

REL_EXTLIBDIR_EXP = $(REL_EXTLIBDIR)/debug

else

REL_BINDIR_EXP    = $(REL_BINDIR)/release

REL_LIBDIR_EXP    = $(REL_LIBDIR)/release

REL_OBJDIR_EXP    = $(REL_OBJDIR)/release

REL_EXTLIBDIR_EXP = $(REL_EXTLIBDIR)/release

endif



BINDIR    = $(CURRENT_DIR)/$(REL_BINDIR_EXP)

LIBDIR    = $(CURRENT_DIR)/$(REL_LIBDIR_EXP)

SRCDIR    = $(CURRENT_DIR)/$(REL_SRCDIR)

OBJDIR    = $(CURRENT_DIR)/$(REL_OBJDIR_EXP)

PRJDIR    = $(CURRENT_DIR)/$(REL_PRJDIR)

TESTDIR   = $(CURRENT_DIR)/$(REL_TESTDIR)

EXTINCDIR = $(CURRENT_DIR)/$(REL_EXTINCDIR)

EXTLIBDIR = $(CURRENT_DIR)/$(REL_EXTLIBDIR_EXP)



CINCS   += -I$(SRCDIR)

LDFLAGS += $(LDPATHPREFIX)$(LIBDIR)



# shared libraries dir

ifeq "$(DEBUG)" "YES"

SHAREDLIB_DIR = $(TMS_BASE_DIR)/sharedlibs/$(TMS_TARGET)/debug

else

SHAREDLIB_DIR = $(TMS_BASE_DIR)/sharedlibs/$(TMS_TARGET)/release

endif

LDFLAGS += $(LDPATHPREFIX)$(SHAREDLIB_DIR)



# Debug/Release versions differ by compiler/linker flags

########################################################

ifeq "$(DEBUG)" "YES"

CFLAGS  += -Wall -g -O0 -D_DEBUG

LDFLAGS += -g -lc

else

CFLAGS  += -Wall -O3 -DNDEBUG

LDFLAGS += -lc

endif



# Tools

#######

ifeq "$(OS_TYPE)" "Linux"

CMD_COPY        = cp

CMD_COPY_FLAGS  = 

CMD_DEL         = rm -f

CMD_COPY_FLAGS  = 

else

$(error "OS_TYPE not Linux!")

endif





Listing Three



# create makefile for gcc

# additional include directories

CINCS += -I$(EXTINCDIR)

# additional linker flags 

LDFLAGS += $(LDPATHPREFIX)$(EXTLIBDIR)



# compile objects

###################

$(OBJDIR)/%.o: $(SRCDIR)/%.c

    @ echo "Compiling C file $<" 

    @ $(CC) -fpic -c $(CFLAGS) $(CINCS) -o $@ $<

$(OBJDIR)/%.o: $(SRCDIR)/%.cpp

    @ echo "Compiling C++ file $<" 

    @ $(CC) -fpic -c $(CFLAGS) $(CINCS) -o $@ $<



# targets

###################

# Target 1: create library

lib:    lib$(ARCHIVE).a



# Target 1b: create shared library

dll:    lib$(SHAREDLIB).so.1.0.1



# Target 2: create executable

exe:    $(APPLICATION) 



# Target 3:   all dependencies and this component

dep:    $(DEPENDENCIES) 



# Target 4: clean all output directories

clean:

    @ echo "Performing clean-up for $(ARCHIVE)"

    @ -$(CMD_DEL) $(OBJDIR)/*.o $(CMD_DEL_FLAGS)

    @ -$(CMD_DEL) $(LIBDIR)/*.a $(CMD_DEL_FLAGS)

    @ -$(CMD_DEL) $(LIBDIR)/*.so.* $(CMD_DEL_FLAGS)

    @ -$(CMD_DEL) $(BINDIR)/*.out $(BINDIR)/core $(CMD_DEL_FLAGS)

    @ -$(CMD_DEL) $(SHAREDLIB_DIR)/lib$(SHAREDLIB).so



# Target 5: execute tests

 .PHONY: test $(TESTS)

 test: $(TESTS) 

 $(TESTS): 

    @ echo ""

    @ echo "Executing $(APPLICATION) with parameter(s): $@"

    @ cd $(PRJDIR); /lib/ld-linux.so.2 --library-path $(SHAREDLIB_DIR) 

                                             $(BINDIR)/$(APPLICATION).out $@

#   simple version without special shared library path:

#   @ cd $(PRJDIR); $(BINDIR)/$(APPLICATION).out $@



# creation

###################

# Target 1: create library

ifneq "$(ARCHIVE)" "notavailable"

lib$(ARCHIVE).a: $(LIBOBJECTS) 

    @ echo "Creating Archive $@" 

    @ -$(CMD_DEL) $(LIBDIR)/$@ $(CMD_DEL_FLAGS)

    @ $(AR) rc $(LIBDIR)/$@ $(EXT_ARCHIVE) $(LIBOBJECTS)

else

lib$(ARCHIVE).a:

    @ echo "Library not available"

endif



# Target 1b: create shared library

ifneq "$(SHAREDLIB)" ""

lib$(SHAREDLIB).so.1.0.1: $(LIBOBJECTS) 

    @ echo "Creating Shared Library $@" 

    @ -$(CMD_DEL) $(LIBDIR)/$@ $(CMD_DEL_FLAGS)

    @ $(LD) -shared $(LIBOBJECTS) $(EXT_ARCHIVE) $(LDFLAGS) -o $(LIBDIR)/$@

    @ ln -f $(LIBDIR)/$@ $(SHAREDLIB_DIR)/lib$(SHAREDLIB).so

else

lib$(SHAREDLIB).so.1.0.1: $(LIBOBJECTS) 

    @ echo "Shared library not available"

endif



# Target 2: create executable

ifneq "$(APPLICATION)" "notavailable"

$(APPLICATION): $(APPOBJECTS) 

   @ echo "Linking $(APPLICATION)" 

   @ -$(CMD_DEL) $(BINDIR)/$(APPLICATION).out $(CMD_DEL_FLAGS)

   @ $(LD) $(APPOBJECTS) $(EXT_ARCHIVE) $(LDFLAGS) 

                            -o $(BINDIR)/$(APPLICATION).out

else

$(APPLICATION):

    @ echo "Executable not available"

endif



# Target 3: external dependecies are defined in the 'inc'-makefiles





Listing Four



# user makefile for gcc



# define Debug or Release version

ifndef DEBUG

DEBUG = YES

endif



# select hardware platform

ifndef HWPLATFORM

HWPLATFORM = Linux

endif



# os version of build system

ifndef OS_TYPE

OS_TYPE = Linux

endif



# location of compliler etc.

ifndef GCC

GCC = /usr/bin

endif





Listing Five



# inc-makefile for MyTimer



# the name of the component

MYTIMER_NAME = MyTimer



# the directory containing the project makefile

MYTIMER_DIR  = $(TMS_BASE_DIR)/shared/MyTimer/prj



# add component to dependencies list

DEPENDENCIES += $(MYTIMER_NAME)



# additional include directories

CINCS += -I$(MYTIMER_DIR)/$(REL_SRCDIR) 



# include library in linker flags

LDFLAGS += $(LDPREFIX)$(MYTIMER_NAME)$(LDSUFFFIX) 

LDFLAGS += $(LDPATHPREFIX)$(MYTIMER_DIR)/$(REL_LIBDIR_EXP) 



# if target 'dep' specified, execute the projects makefile.

# Note: the dependencies are not built recursively

$(MYTIMER_NAME):

    @ echo "Building Dependency $@" 

    @ $(MAKE) -s -f $(MYTIMER_DIR)/makefile.mak \

      TMS_TARGET=$(TMS_TARGET) $(subst dep, , $(MAKECMDGOALS))





Listing Six



# inc-makefile for MyTimer (switch)



ifeq "$(TMS_TARGET)" "msvc60"

MYTIMER_IMP  = MyTimer_win32

endif

ifeq "$(TMS_TARGET)" "gcc"

MYTIMER_IMP  = MyTimer_linux

endif



include $(MAKE_DIR)/inc_$(MYTIMER_IMP).mak







6



