CLibrary 7.71 KB
Newer Older
1
# Makefile fragment for C and C++ libraries for applications and modules
Ben Avison's avatar
Ben Avison committed
2 3 4

INCLUDED_CLIBRARY = YES

5 6 7
#
# This makefile provides the following phony targets:
#
8
#    all_libs  export_hdrs  export_libs  install
9 10 11 12 13 14 15 16 17 18 19 20 21
#
#
# 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)
22 23 24
# LIB_DEPENDS  (opt) (any extra dependencies to assert before making LIBRARIES)
# EXPDIR       (opt) (the target directory - otherwise ${LIBDIR}/${TARGET} or
#                                  for a disc install ${INSTDIR}/${TARGET})
25 26 27
# 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)
28
# EXPORTS      (opt) (dependencies for export_hdrs phase - otherwise deduced from ${HDRS} and ${ASMHDRS})
29 30
# OBJS               (object files, no o. or oz. prefixes)
# DBG_OBJS     (opt) (debug build object files, no o. or oz. prefixes - otherwise ${OBJS})
31 32 33 34
# APP_OBJS     (opt) (release application object files, no o. or oz. prefixes - otherwise ${OBJS})
# APP_DBG_OBJS (opt) (debug application object files, no o. or oz. prefixes - otherwise ${DBG_OBJS})
# MOD_OBJS     (opt) (release module object files, no o. or oz. prefixes - otherwise ${OBJS})
# MOD_DBG_OBJS (opt) (debug module object files, no o. or oz. prefixes - otherwise ${DBG_OBJS})
35 36 37 38
# 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)
39
# SOURCES_TO_SYMLINK (opt) (files which need be linked to by the link farm, in addition to contents of c and h directories)
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88
#
#
# 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
DIRS         ?= _dirs
HDRS         ?= ${TARGET}
ASMHDRS      ?=
DBG_OBJS     ?= ${OBJS}
89 90 91 92 93 94 95 96
APP_OBJS     ?= ${OBJS}
APP_DBG_OBJS ?= ${DBG_OBJS}
MOD_OBJS     ?= ${OBJS}
MOD_DBG_OBJS ?= ${DBG_OBJS}
APP_OBJS_     = $(addsuffix .o,${APP_OBJS})
APP_DBG_OBJS_ = $(addsuffix .od,${APP_DBG_OBJS})
MOD_OBJS_     = $(addsuffix .oz,${MOD_OBJS})
MOD_DBG_OBJS_ = $(addsuffix .odz,${MOD_DBG_OBJS})
97 98 99

EXPORTING_HDRS    = $(addsuffix .exphdr,${HDRS})
EXPORTING_ASMHDRS = $(addsuffix .expasm,${ASMHDRS})
100
EXPORTS          ?= ${EXPORTING_HDRS} ${EXPORTING_ASMHDRS}
101 102 103
EXPORTING_LIBS    = $(addsuffix .explib,${LIBRARIES})
TARGET_LIBS       = $(addsuffix .${LIBEXT},${LIBRARIES})

104 105 106 107 108 109
ifeq ($(filter install%,${MAKECMDGOALS}),)
EXPDIR       ?= ${LIBDIR}/${TARGET}
else
EXPDIR       ?= ${INSTDIR}/${TARGET}
endif

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

112 113 114 115
ifeq ("${INCLUDED_STDTOOLS}","")
include StdTools
endif

116 117 118 119 120
ifneq (objs,$(notdir ${CURDIR}))

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

121 122 123 124 125 126 127 128 129 130 131 132 133 134
ifeq (clean,${MAKECMDGOALS})
# With a double-colon rule which can have additional actions assigned from the
# master makefile, we'd normally need the master makefile to include the
# ${CURDIR} check to ensure that it's performed on the same invocation as us.
# However, there's no real benefit to performing clean from within the objs
# directory, and it adds an ordering problem between the different double-colon
# rules (the one that deletes the objs directory has to be last otherwise the
# cwd is invalid for the others) so to simplify things, we only ever do cleans
# from the same directory as the Makefile.
clean::
	@echo Cleaning...
	@rm -rf objs
	@echo ${COMPONENT}: cleaned
else
135
all_libs export export_hdrs export_libs links: ${SYMLINK_DEPEND}
136 137
	$(foreach linksource,${SOURCES_TO_SYMLINK}, \
		$(shell \
138 139 140
			linkdest=`echo ${linksource} | sed -e 's,\([^/]\+\)/\([^/]\+\)$$,\2.\1,' -e 's,^,objs/,'`; \
			linkdestdir=`echo $$linkdest | sed -e 's,/[^/]\+$$,,'`; \
			linkbackpath=`echo $$linkdestdir | sed -e 's,[^/]\+,..,g'`; \
Ben Avison's avatar
Ben Avison committed
141
			[ -d ${linksource} ] || [ -L $$linkdest ] || mkdir -p $$linkdestdir; \
142 143 144
			[ -d ${linksource} ] || [ -L $$linkdest ] || ln -s $$linkbackpath/${linksource} $$linkdest; \
		 ) \
	)
Ben Avison's avatar
Ben Avison committed
145
	@mkdir -p objs
146 147 148
ifneq (links,${MAKECMDGOALS})
	@${MAKE} -C objs -f ../$(firstword ${MAKEFILE_LIST}) ${MAKECMDGOALS}
endif
149
endif
150 151 152 153 154

else

# Makefile invoked from objs subdirectory

Ben Avison's avatar
Ben Avison committed
155 156 157 158 159 160 161
ifeq ("${INCLUDED_STDRULES}","")
include StdRules
endif
ifeq ("${INCLUDED_DBGRULES}","")
include DbgRules
endif

162 163 164
all_libs: ${TARGET_LIBS}
	@${ECHO} ${COMPONENT}: library built

165 166 167 168 169 170
# GNU make seems to treat any double-colon rule with no dependencies as
# always out-of-date, therefore always rebuilds it and anything which in turn
# depends on the target of the double-colon rule. So use a single-colon rule
# instead. If any cross builds need to create extra directories on a
# per-component basis, we'll cross that bridge when we get to it.
${DIRS}:
171 172 173
	${TOUCH} $@

export: export_${PHASE}
174
	@${NOP}
175

176 177
install export_: export_libs export_hdrs
	@${NOP}
178 179 180 181 182 183 184 185 186

create_exp_hdr_dirs:
	${MKDIR} ${EXPDIR}

create_exp_lib_dir:
	${MKDIR} ${EXPDIR}

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

190
export_hdrs: create_exp_hdr_dirs ${DIRS} ${EXPORTS}
191 192 193
	[ ! -f ../VersionNum ] || ${CP} ../VersionNum ${EXPDIR}/LibVersion ${CPFLAGS}
	@${ECHO} ${COMPONENT}: header export complete

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

198
${LIBRARY}${CUSTOMLIB}.${LIBEXT}: ${LIBDEPENDS} ${DIRS} ${APP_OBJS_}
199
	${AR} ${ARFLAGS} ${LIBRARY}.${LIBEXT} ${APP_OBJS_}
200

201
${LIBRARYZM}${CUSTOMLIBZM}.${LIBEXT}: ${LIBDEPENDS} ${DIRS} ${MOD_OBJS_}
202
	${AR} ${ARFLAGS} ${LIBRARYZM}.${LIBEXT} ${MOD_OBJS_}
203

204
${LIBRARYD}${CUSTOMLIBD}.${LIBEXT}: ${LIBDEPENDS} ${DIRS} ${APP_DBG_OBJS_}
205
	${AR} ${ARFLAGS} ${LIBRARYD}.${LIBEXT} ${APP_DBG_OBJS_}
206

207
${LIBRARYDZM}${CUSTOMLIBDZM}.${LIBEXT}: ${LIBDEPENDS} ${DIRS} ${MOD_DBG_OBJS_}
208
	${AR} ${ARFLAGS} ${LIBRARYDZM}.${LIBEXT} ${MOD_DBG_OBJS_}
209 210 211 212 213 214 215 216 217

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

endif

# EOF