Chat-O-Matic/build/jam/MainBuildRules

381 lines
8.3 KiB
Plaintext

# MainBuildRules
#
# Rules that specify what to build and how to do it.
rule AddResources
{
# AddResources <name> : <resourcefiles> ;
#
# Adds resources to the application.
#
# <name>: Name of the application.
# <resourcefiles>: List of resource files. Grist will be set.
#
local resfiles ;
local file ;
for file in $(2) {
if ! $(file:G) {
file = [ FGristFiles $(file) ] ;
}
resfiles += $(file) ;
}
SEARCH on $(resfile) += $(SEARCH_SOURCE) ;
for file in $(resfiles) {
if $(file:S) = .rdef {
local rdef = $(file) ;
file = $(rdef:S=.rsrc) ;
ResComp $(file) : $(rdef) ;
}
RESFILES on $(1) += $(file) ;
}
}
rule Application
{
# Application <name> : <sources> : <libraries> : <res> ;
#
# Creates an application from sources.
#
# <name>: Name of the application. Grist is allowed.
# <sources>: List of source files. Grist will be set.
# <libraries>: List of libraries to link against.
# <res>: List of resource files. Grist will be set.
#
local app = $(1) ;
local sources = $(2) ;
local libs = $(3) ;
local res = $(4) ;
AddResources $(app) : $(res) ;
Main $(app) : $(sources) ;
MakeLocate $(app) : $(LOCATE_MAIN_TARGET) ;
LinkAgainst $(app) : $(libs) ;
}
actions Strip
{
strip "$(1)" ;
}
rule AddOn
{
# AddOn <name> : <sources> : <libraries> : <res> ;
#
# Creates an add-on from sources.
#
# <name>: Name of the add-on. Grist is allowed.
# <sources>: List of source files. Grist will be set.
# <libraries>: List of libraries to link against.
# <res>: List of resource files. Grist will be set.
#
SharedLibrary $(1) : $(2) : $(3) : $(4) ;
}
rule SharedLibrary
{
# SharedLibrary <name> : <sources> : <libraries> : <res> ;
#
# Creates a shared library from sources.
#
# <name>: Name of the shared library. Grist is allowed.
# <sources>: List of source files. Grist will be set.
# <libraries>: List of libraries to link against.
# <res>: List of resource files. Grist will be set.
#
local lib = $(1) ;
local sources = $(2) ;
local libs = $(3) ;
local res = $(4) ;
AddResources $(lib) : $(res) ;
Main $(lib) : $(sources) ;
MakeLocate $(lib) : $(LOCATE_MAIN_TARGET) ;
local linkFlags ;
if $(OSPLAT) = X86 {
linkFlags = -nostart -Xlinker -soname=\"$(lib)\" -Xlinker --no-undefined ;
} else {
linkFlags = -xms ;
}
LINKFLAGS on $(lib) = [ on $(lib) return $(LINKFLAGS) ] $(linkFlags) ;
LinkAgainst $(lib) : $(libs) ;
}
rule StaticLibrary
{
# StaticLibrary <name> : <sources> ;
#
# Creates a static library from sources.
#
# <name>: Name of the static library. Grist is allowed.
# <source>: List of source files. Grist will be set.
#
local lib = $(1) ;
Library $(lib) : $(2) ;
MakeLocate $(lib) : $(LOCATE_MAIN_TARGET) ;
# If KEEPOBJS is set, Library doesn't make the library depend on `lib'.
if $(KEEPOBJS) {
Depends lib : $(lib) ;
}
}
rule LinkAgainst
{
# LinkAgainst <name> : <libs> ;
#
# Adds libraries to the list of libraries a (Main) target shall be linked
# against.
#
# <name>: The name of the target for which to add libraries.
# <libs>: The libraries (actually arbitrary shared objects and static
# libraries) to be added. Valid elements are e.g. "be" or
# "libopenbeos.so" or "/boot/.../libfoo.so". If the basename starts
# with "lib" or the thingy has a dirname or grist, it is added to
# the NEEDLIBS variable (i.e. the file will be bound!), otherwise
# it is prefixed "-l" and added to LINKLIBS. If you want to specify
# a target that isn't a library and also has neither grist nor a
# dirname, you can prepend "<nogrist>" as grist; it will be
# stripped by this rule.
#
for i in $(>)
{
local isfile = ;
if $(i:D) || $(i:G) {
isfile = true ;
if $(i:G) = <nogrist> {
i = $(i:G=) ;
}
} else {
switch $(i:B)
{
# XXX: _APP_ and _KERNEL_ should not be needed for ELF.
case _APP_ : isfile = true ;
case _KERNEL_ : isfile = true ;
case lib* : isfile = true ;
case * : isfile = ;
}
if ! $(isfile) && ( $(i:S) = .so || $(i:S) = .o || $(i:S) = .a ) {
isfile = true ;
}
}
if $(isfile) {
NEEDLIBS on $(1) = [ on $(1) return $(NEEDLIBS) ] $(i) ;
Depends $(1) : $(i) ;
} else {
LINKLIBS on $(1) = [ on $(1) return $(LINKLIBS) ] -l$(i) ;
}
}
}
rule XRes
{
# XRes <target> : <resource files> ;
#
# Adds resources to a file.
#
# <target>: The files to which resources shall be added.
# <resource files>: The resource files.
#
if $(2)
{
Depends $(1) : $(2) ;
XRes1 $(1) : $(2) ;
}
}
rule ResComp
{
# ResComp <resource file> : <rdef file> ;
#
# Creates a binary resource file from a rdef script.
#
# <resource file>: The resource file. Grist is required.
# <rdef file>: The rdef script. Grist is required.
#
local defines ;
on $(1) {
defines = $(DEFINES) ;
}
DEFINES on $(1) = $(defines) ;
CCDEFS on $(1) = [ FDefines $(defines) ] ;
HDRS on $(1) = [ on $(1) FIncludes $(SEARCH_SOURCE) $(SUBDIRHDRS) $(HDRS) ]
$(HDRS_INCLUDES_SEPARATOR) ;
RCHDRS on $(1) = [ FRcIncludes $(SEARCH_SOURCE) $(SUBDIRHDRS) $(HDRS) ] ;
SEARCH on $(2) += $(SEARCH_SOURCE) ;
MakeLocate $(1) : $(LOCATE_TARGET) ;
Depends $(1) : $(2) $(RC) ;
LocalClean clean : $(1) ;
ResComp1 $(1) : $(RC) $(2) ;
}
# Note: We pipe the input files into the preprocessor, since *.rdef files are
# considered linker scripts, and thus we can use preprocessor features.
actions ResComp1
{
cat "$(2[2-])" | $(CC) -E $(CCDEFS) $(HDRS) - | egrep -v '^#' | $(2[1]) $(RCHDRS) --auto-names -o "$(1)" -
}
actions XRes1
{
xres -o "$(1)" "$(2)" ;
}
actions MimeSet
{
mimeset -f "$(1)" ;
}
rule LexC++
{
Depends $(1) : $(2) ;
MakeLocate $(1) : $(LOCATE_SOURCE) ;
Clean clean : $(1) ;
}
actions LexC++
{
$(LEX) -i -P$(<:B) -o$(1) $(2)
}
rule Bison
{
local _h ;
_h = $(1:S=.h) ;
MakeLocate $(<) $(_h) : $(LOCATE_SOURCE) ;
Depends $(<) : $(>) ;
BisonC++ $(<) : $(>) ;
Clean clean : $(<) $(_h) ;
# make sure someone includes $(_h) else it will be
# a deadly independent target
Includes $(<) : $(_h) ;
}
actions BisonC++
{
$(BISON) -v -d -p $(2:B) -o $(1) $(2)
}
rule Rez
{
Depends $(<) : $(>) ;
}
rule PreCompile
{
# PreCompile <hdr> : <src>
#
# precompiles the given src (a headerfile) into the specified header.
#
local _hdr = $(1) ;
local _src = $(2) ;
MakeLocate $(_hdr) : $(LOCATE_TARGET) ;
PreComp $(_hdr) : $(_src) ;
Clean clean : $(_hdr) ;
}
rule PreComp
{
Depends $(<) : $(>) ;
}
actions PreComp
{
mwcc -precompile $(<) -lang cplus "$(>)" ;
}
rule SubDirSysHdrs
{
# SubDirSysHdrs <dirs> ;
#
# Adds directories to the system include search paths for the current
# subdirectory. Counterpart of SubDirHdrs which adds non-system include
# search paths.
#
# <dirs>: The directories to be added to the current subdir's system
# include search paths.
#
SUBDIRSYSHDRS += [ FDirName $(1) ] ;
}
rule ObjectSysHdrs
{
# SubDirSysHdrs <sources or objects> : <dirs> ;
#
# Adds directories to the system include search paths for the given
# sources or objects. Counterpart of ObjectHdrs which adds non-system
# include search paths.
#
# NOTE: This rule must be invoked *after* the rule that generates the
# objects.
#
# <sources or objects>: The targets for which to add system include
# search paths.
# <dirs>: The directories to be added to the given objects' system
# include search paths.
#
local s ;
for s in [ FGristFiles $(<:S=$(SUFOBJ)) ] {
SYSHDRS on $(s) += $(>) ;
CCHDRS on $(s) = [ on $(s) FIncludes $(HDRS) ]
$(HDRS_INCLUDES_SEPARATOR) [ on $(s) FSysIncludes $(SYSHDRS) ] ;
}
}
# FSysIncludes <dirs> ;
#
# Counterpart of FIncludes for system include search paths.
#
if $(OSPLAT) = X86 {
rule FSysIncludes { return -I$(<) ; }
} else {
rule FSysIncludes { return "-i "$(<) ; }
}
# FRcIncludes <dirs> ;
#
# Counterpart of FIncludes for *.rdef scripts.
#
rule FRcIncludes
{
return "-I "$(<) ;
}
# Variable referring to the STL.
if $(OSPLAT) = X86 {
if $(IS_GCC4_PLATFORM) = 1 {
TARGET_LIBSTDC++ = stdc++ ;
} else {
TARGET_LIBSTDC++ = stdc++.r4 ;
}
} else {
TARGET_LIBSTDC++ = mslcpp_4_0 ;
}
rule CreateSVNRevisionFile file
{
# CreateSVNRevisionFile <file>
local svnEntries = <svn>entries ;
SEARCH on $(svnEntries) = [ FDirName $(TOP) .svn ] ;
Depends $(file) : $(svnEntries) ;
}
actions CreateSVNRevisionFile
{
(LANG=C svn info $(TOP) 2> /dev/null || echo Revision: 0) |
grep Revision | awk '{printf $2}' > $(1)
}