# MainBuildRules # # Rules that specify what to build and how to do it. rule AddResources { # AddResources : ; # # Adds resources to the application. # # : Name of the application. # : 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 : : : ; # # Creates an application from sources. # # : Name of the application. Grist is allowed. # : List of source files. Grist will be set. # : List of libraries to link against. # : 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 : : : ; # # Creates an add-on from sources. # # : Name of the add-on. Grist is allowed. # : List of source files. Grist will be set. # : List of libraries to link against. # : List of resource files. Grist will be set. # SharedLibrary $(1) : $(2) : $(3) : $(4) ; } rule SharedLibrary { # SharedLibrary : : : ; # # Creates a shared library from sources. # # : Name of the shared library. Grist is allowed. # : List of source files. Grist will be set. # : List of libraries to link against. # : 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 { if $(IS_GCC4_PLATFORM) = 1 { linkFlags = -shared ; } else { linkFlags = -nostart ; } linkFlags += -Xlinker -soname=\"$(lib)\" -Xlinker --no-undefined ; } else { linkFlags = -xms ; } LINKFLAGS on $(lib) = [ on $(lib) return $(LINKFLAGS) ] $(linkFlags) ; LinkAgainst $(lib) : $(libs) ; } rule StaticLibrary { # StaticLibrary : ; # # Creates a static library from sources. # # : Name of the static library. Grist is allowed. # : 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 : ; # # Adds libraries to the list of libraries a (Main) target shall be linked # against. # # : The name of the target for which to add libraries. # : 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 "" as grist; it will be # stripped by this rule. # for i in $(>) { local isfile = ; if $(i:D) || $(i:G) { isfile = true ; if $(i:G) = { 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 : ; # # Adds resources to a file. # # : The files to which resources shall be added. # : The resource files. # if $(2) { Depends $(1) : $(2) ; XRes1 $(1) : $(2) ; } } rule ResComp { # ResComp : ; # # Creates a binary resource file from a rdef script. # # : The resource file. Grist is required. # : 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 -va '^#' | $(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 : # # 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 ; # # Adds directories to the system include search paths for the current # subdirectory. Counterpart of SubDirHdrs which adds non-system include # search paths. # # : The directories to be added to the current subdir's system # include search paths. # SUBDIRSYSHDRS += [ FDirName $(1) ] ; } rule ObjectSysHdrs { # SubDirSysHdrs : ; # # 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. # # : The targets for which to add system include # search paths. # : 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 ; # # Counterpart of FIncludes for system include search paths. # if $(OSPLAT) = X86 { rule FSysIncludes { return -I$(<) ; } } else { rule FSysIncludes { return "-i "$(<) ; } } # FRcIncludes ; # # 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 #local svnEntries = entries ; #SEARCH on $(svnEntries) = [ FDirName $(TOP) .git ] ; #Depends $(file) : $(svnEntries) ; } actions CreateSVNRevisionFile { (LANG=C svn info $(TOP) 2> /dev/null || echo Revision: 0) | grep Revision | awk '{printf $2}' > $(1) }