CLibrary 6.57 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 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 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176
# Copyright 2008 Castle Technology Ltd
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# Makefile fragment for C and C++ libraries for applications and modules
#
# $Id$
#
# 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 o)
# EXPDIR       (opt) (the target directory - otherwise <Lib$Dir>.${TARGET})
# DIRS         (opt) (stamp object for directory creation - otherwise o._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})
# 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)
#
#
# 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        = <Lib$Dir>

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

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

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

${DIRS} ::
        ${MKDIR} o
        ${MKDIR} oz
        ${MKDIR} od
        ${MKDIR} odz
        ${MKDIR} ${LIBEXT}
        ${TOUCH} $@

clean ::
        @IfThere o         Then ${ECHO} ${WIPE} o ${WFLAGS}
        @IfThere o         Then ${WIPE} o ${WFLAGS}
        @IfThere oz        Then ${ECHO} ${WIPE} oz ${WFLAGS}
        @IfThere oz        Then ${WIPE} oz ${WFLAGS}
        @IfThere od        Then ${ECHO} ${WIPE} od ${WFLAGS}
        @IfThere od        Then ${WIPE} od ${WFLAGS}
        @IfThere odz       Then ${ECHO} ${WIPE} odz ${WFLAGS}
        @IfThere odz       Then ${WIPE} odz ${WFLAGS}
        @IfThere ${LIBEXT} Then ${ECHO} ${WIPE} ${LIBEXT} ${WFLAGS}
        @IfThere ${LIBEXT} Then ${WIPE} ${LIBEXT} ${WFLAGS}
        @${ECHO} ${COMPONENT}: cleaned

export: export_${PHASE}
        ${NOP}

export_: export_libs export_hdrs
        ${NOP}

create_exp_hdr_dirs:
        ${MKDIR} ${EXPDIR}.h
        ${MKDIR} ${EXPDIR}.Hdr

create_exp_lib_dir:
        ${MKDIR} ${EXPDIR}.${LIBEXT}

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

export_hdrs: ${EXPORTING_HDRS} ${DIRS} create_exp_hdr_dirs
        @IfThere VersionNum then ${ECHO} ${CP} VersionNum ${EXPDIR}.LibVersion ${CPFLAGS}
        @IfThere VersionNum then ${CP} VersionNum ${EXPDIR}.LibVersion ${CPFLAGS}
        @IfThere ${EXPDIR}.h.*   then else ${RM} ${EXPDIR}.h
        @IfThere ${EXPDIR}.Hdr.* then else ${RM} ${EXPDIR}.Hdr
        @${ECHO} ${COMPONENT}: header export complete

export_libs: ${EXPORTING_LIBS} ${TARGET_LIBS} ${DIRS} create_exp_lib_dir
        @IfThere VersionNum then ${ECHO} ${CP} VersionNum ${EXPDIR}.LibVersion ${CPFLAGS}
        @IfThere VersionNum then ${CP} VersionNum ${EXPDIR}.LibVersion ${CPFLAGS}
        @IfThere ${EXPDIR}.${LIBEXT}.* then else ${RM} ${EXPDIR}.${LIBEXT}
        @${ECHO} ${COMPONENT}: library export complete

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

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

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

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

# EOF