• Ben Avison's avatar
    Changes to facilitate platform independence. · 4477e695
    Ben Avison authored
    Detail:
     CApp:
      * New variable CLEAN_DEPEND is now the preferred way to specify additional
        clean actions because GNU make doesn't have an equivalent to amu's :: rules
      * Can now indicate preference to use C++ linker options using LINK_TYPE
      * Gains install phase support:
        + INSTALLAPPFILES lists the files to be copied, effectively specified
          relative to LocalRes$Path
        + Adopted INSTTYPE concept from DDE makefiles for cases where executable
          and support files need to be installed to different locations
        + Unusual cases can override this implementation using CUSTOMINSTALLAPP
          and/or CUSTOMINSTALLTOOL
    
      CLibrary:
      * New variable CLEAN_DEPEND is now the preferred way to specify additional
        clean actions because GNU make doesn't have an equivalent to amu's :: rules
      * -o is no longer a mandatory argument to libfile - now in ARFLAGS rather
        than used explicitly
    
      DbgRules / StdRules:
      * Macroised some Norcroft-specific features
    
      HostTools:
      * Clean phase support was incomplete
    
      StdTools:
      * A few additional tool definitions
      * Added macro definitions for common C options
      * C's enable-warnings and suppress-function-name-embedding options now on by
        default because they're usually (maybe even universally?) used - it won't
        hurt if they're specified again by existing makefiles
      * C++ now has equivalent INCLUDES and DEFINES variables, and the standard C++
        headers are on the default include path
      * SEP is defined as the directory separator character and can be used from
        top-level makefiles in a platform-independent way
    
      Functionally equivalent versions of the following makefile fragments
      have been developed so far for executing on a Posix build host:
        AppLibs, CApp, CLibrary, DbgRules, HostTools, StdRules, StdTools
      These suport native compilers (when APCS=Host) and cross-compilers,
      and GCC (when TOOLCHAIN=GNU) and Norcroft toolchains - typically these
      environment variables would be selected by running an Env file.
    
    Admin:
      Tested by building as many as possible of the DDE components on RISC OS
      and on Linux, using native and cross compilers, and using Norcroft and
      GNU toolchains.
    
    Version 5.01. Tagged as 'BuildSys-5_01'
    4477e695
CLibrary 6.11 KB
# Makefile fragment for C and C++ libraries for applications and modules
#
# This makefile provides the following phony targets:
#
#    all_libs  export_hdrs  export_libs
#
#
# This fragment uses the following macros set by the master makefile.
#
#
# COMPONENT          (the name of the component)
# TARGET       (opt) (the leafname of the primary target - otherwise ${COMPONENT})
# LIBRARY      (opt) (the leafname of the application library - otherwise ${TARGET})
# LIBRARYZM    (opt) (the leafname of the module library - otherwise ${LIBRARY}zm)
# LIBRARYD     (opt) (the leafname of the debug app library - otherwise ${LIBRARY}d)
# LIBRARYDZM   (opt) (the leafname of the debug module library - otherwise ${LIBRARY}dzm)
# LIBRARIES    (opt) (libraries to build/export - otherwise ${LIBRARY} and ${LIBRARYZM})
# LIBEXT       (opt) (subdir or filename extension for library files - otherwise a)
# EXPDIR       (opt) (the target directory - otherwise ${LIBDIR}/${TARGET})
# DIRS         (opt) (stamp object for directory creation - otherwise _dirs)
# HDRS         (opt) (header files to export, no h. prefix - otherwise ${TARGET})
# ASMHDRS      (opt) (assembly header files to export, no Hdr. prefix - otherwise none)
# OBJS               (object files, no o. or oz. prefixes)
# DBG_OBJS     (opt) (debug build object files, no o. or oz. prefixes - otherwise ${OBJS})
# APP_OBJS     (opt) (object files for application version - otherwise derived from ${OBJS})
# APP_DBG_OBJS (opt) (object files for debug app version - otherwise derived from ${DBG_OBJS})
# MOD_OBJS     (opt) (object files for module version - otherwise derived from ${OBJS})
# MOD_DBG_OBJS (opt) (object files for debug module version - otherwise derived from ${DBG_OBJS})
# CLEAN_DEPEND (opt) (phony target for additional clean actions)
# CUSTOMLIB    (opt) (set to "custom" to override the application library rule)
# CUSTOMLIBZM  (opt) (set to "custom" to override the module library rule)
# CUSTOMLIBD   (opt) (set to "custom" to override the debug application library rule)
# CUSTOMLIBDZM (opt) (set to "custom" to override the debug module library rule)
# SOURCES_TO_LINK (opt) (files which need be linked to by the link farm, in addition to contents of c and h directories)
#
#
# It relies on the following from the build system:
#
#
# PHASE            (export phase discriminator)
#
#
# It relies on the following generic tool macros from the StdTools makefile
#
#
# CP + CPFLAGS     (copy, cp etc.)
# WIPE + WFLAGS    (recursive delete)
# RM               (non-recursive delete)
# AS + ASFLAGS     (assembler)
# MKDIR            (cdir/mkdir -p)
# ECHO
# AR + ARFLAGS     (libfile/ar)
# TOUCH            (create/touch)
# NOP
#
#
# It relies on the following from the StdRules makefile
#
#
# .c.o  .c.oz  .c++.o  .cpp.o  .c++.oz  .c++.oz  .s.o  .s.oz
#
#
# It relies on the following from the DbgRules makefile
#
#
# CDFLAGS  C++DFLAGS  ASDFLAGS
# .c.od  .c.odz  .c++.od  .cpp.od  .c++.odz  .cpp.odz  .s.od  .s.odz
#
#

LIBDIR        = ${BUILDDIR}/Export/${APCS}/Lib

TARGET       ?= ${COMPONENT}
LIBRARY      ?= ${TARGET}
LIBRARYZM    ?= ${LIBRARY}zm
LIBRARYD     ?= ${LIBRARY}d
LIBRARYDZM   ?= ${LIBRARY}dzm
LIBRARIES    ?= ${LIBRARYZM} ${LIBRARY}
LIBEXT       ?= a
EXPDIR       ?= ${LIBDIR}/${TARGET}
DIRS         ?= _dirs
HDRS         ?= ${TARGET}
ASMHDRS      ?=
DBG_OBJS     ?= ${OBJS}
APP_OBJS     ?= $(addsuffix .o,${OBJS})
APP_DBG_OBJS ?= $(addsuffix .od,${DBG_OBJS})
MOD_OBJS     ?= $(addsuffix .oz,${OBJS})
MOD_DBG_OBJS ?= $(addsuffix .odz,${DBG_OBJS})

EXPORTING_HDRS    = $(addsuffix .exphdr,${HDRS})
EXPORTING_ASMHDRS = $(addsuffix .expasm,${ASMHDRS})
EXPORTING_LIBS    = $(addsuffix .explib,${LIBRARIES})
TARGET_LIBS       = $(addsuffix .${LIBEXT},${LIBRARIES})

SOURCES_TO_SYMLINK += $(wildcard c/*) $(wildcard h/*) $(wildcard s/*)

ifneq (objs,$(notdir ${CURDIR}))

# Makefile invoked from same directory
# Create link farm, then execute the makefile from within it

all_libs export_hdrs export_libs clean links: ${SYMLINK_DEPEND}
ifneq (clean,${MAKECMDGOALS})
	$(foreach linksource,${SOURCES_TO_SYMLINK}, \
		$(shell \
			linkdest=`echo ${linksource} | sed -e 's,\([^/]*\)/\([^/]*\)$$,\2.\1,' -e 's,^,objs/,'`; \
			linkdestdir=`echo $$linkdest | sed -e 's,/[^/]*$$,,'`; \
			linkbackpath=`echo $$linkdestdir | sed -e 's,[^/]*,..,g'`; \
			[ -d ${linksource} ] || [ -L $$linkdest ] || ${MKDIR} $$linkdestdir; \
			[ -d ${linksource} ] || [ -L $$linkdest ] || ln -s $$linkbackpath/${linksource} $$linkdest; \
		 ) \
	)
endif
	@[ -d objs ] || ${MKDIR} objs
ifneq (links,${MAKECMDGOALS})
	@${MAKE} -C objs -f ../$(firstword ${MAKEFILE_LIST}) ${MAKECMDGOALS}
endif

else

# Makefile invoked from objs subdirectory

all_libs: ${TARGET_LIBS}
	@${ECHO} ${COMPONENT}: library built

${DIRS}:
	${TOUCH} $@

clean :: ${CLEAN_DEPEND}
	@${ECHO} Cleaning...
	@cd .. && ${WIPE} objs ${WFLAGS}
	@${ECHO} ${COMPONENT}: cleaned

export: export_${PHASE}
	${NOP}

export_: export_libs export_hdrs
	${NOP}

create_exp_hdr_dirs:
	${MKDIR} ${EXPDIR}

create_exp_lib_dir:
	${MKDIR} ${EXPDIR}

.SUFFIXES: .exphdr .expasm .explib .h .Hdr .${LIBEXT}
.h.exphdr:;         ${CP} $< ${EXPDIR}/$< ${CPFLAGS}
.Hdr.expasm:;       ${CP} $< ${EXPDIR}/$< ${CPFLAGS}
.${LIBEXT}.explib:; ${CP} $< ${EXPDIR}/$< ${CPFLAGS}

export_hdrs: create_exp_hdr_dirs ${DIRS} ${EXPORTING_ASMHDRS} ${EXPORTING_HDRS}
	[ ! -f ../VersionNum ] || ${CP} ../VersionNum ${EXPDIR}/LibVersion ${CPFLAGS}
	@${ECHO} ${COMPONENT}: header export complete

export_libs: create_exp_lib_dir ${DIRS} ${EXPORTING_LIBS} ${TARGET_LIBS}
	[ ! -f ../VersionNum ] || ${CP} ../VersionNum ${EXPDIR}/LibVersion ${CPFLAGS}
	@${ECHO} ${COMPONENT}: library export complete

${LIBRARY}${CUSTOMLIB}.${LIBEXT}: ${DIRS} ${APP_OBJS}
	${AR} ${ARFLAGS} ${LIBRARY}.${LIBEXT} ${APP_OBJS}

${LIBRARYZM}${CUSTOMLIBZM}.${LIBEXT}: ${DIRS} ${MOD_OBJS}
	${AR} ${ARFLAGS} ${LIBRARYZM}.${LIBEXT} ${MOD_OBJS}

${LIBRARYD}${CUSTOMLIBD}.${LIBEXT}: ${DIRS} ${APP_DBG_OBJS}
	${AR} ${ARFLAGS} ${LIBRARYD}.${LIBEXT} ${APP_DBG_OBJS}

${LIBRARYDZM}${CUSTOMLIBDZM}.${LIBEXT}: ${DIRS} ${MOD_DBG_OBJS}
	${AR} ${ARFLAGS} ${LIBRARYDZM}.${LIBEXT} ${MOD_DBG_OBJS}

include $(wildcard *.d)
include $(wildcard *.dz)
include $(wildcard *.dd)
include $(wildcard *.ddz)

endif

# EOF