mirror of
https://review.haiku-os.org/haiku
synced 2025-02-20 20:50:05 +01:00
our build platforms should have sed support (it is built into Jambase at least.) I use these rules to do some code generation in my soon to be committed MarkAs Tracker add-ons. This works pretty nifty if I do say so myself. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@19481 a95241bf-73f2-0310-859d-f6bbb57e9c96
120 lines
3.0 KiB
Plaintext
120 lines
3.0 KiB
Plaintext
|
|
rule SetupObjectsDir
|
|
{
|
|
local relPath = [ FDirName $(SUBDIR_TOKENS[2-]) ] ;
|
|
COMMON_PLATFORM_LOCATE_TARGET =
|
|
[ FDirName $(HAIKU_COMMON_PLATFORM_OBJECT_DIR) $(relPath) ] ;
|
|
|
|
local var ;
|
|
for var in COMMON_ARCH COMMON_DEBUG DEBUG_$(HAIKU_DEBUG_LEVELS) {
|
|
HOST_$(var)_LOCATE_TARGET
|
|
= [ FDirName $(HOST_$(var)_OBJECT_DIR) $(relPath) ] ;
|
|
TARGET_$(var)_LOCATE_TARGET
|
|
= [ FDirName $(TARGET_$(var)_OBJECT_DIR) $(relPath) ] ;
|
|
}
|
|
|
|
LOCATE_TARGET = $(COMMON_PLATFORM_LOCATE_TARGET) ;
|
|
LOCATE_SOURCE = $(LOCATE_TARGET) ;
|
|
SEARCH_SOURCE = $(SUBDIR) $(LOCATE_SOURCE)
|
|
$(HOST_COMMON_DEBUG_LOCATE_TARGET) # Also add the standard output
|
|
$(TARGET_COMMON_DEBUG_LOCATE_TARGET) # dirs for generated sources.
|
|
;
|
|
}
|
|
|
|
rule SubIncludeGPL
|
|
{
|
|
# SubInclude rule that can be used to conditionally include GPL licensed
|
|
# add-ons
|
|
if $(INCLUDE_GPL_ADDONS) = 1 {
|
|
SubInclude $(1) ;
|
|
}
|
|
}
|
|
|
|
rule MakeLocateCommonPlatform
|
|
{
|
|
MakeLocate $(1) : $(COMMON_PLATFORM_LOCATE_TARGET) ;
|
|
}
|
|
|
|
rule MakeLocatePlatform
|
|
{
|
|
local files = $(1) ;
|
|
local file ;
|
|
for file in $(files) {
|
|
if [ on $(file) return $(PLATFORM) ] = host {
|
|
MakeLocate $(file) : $(HOST_COMMON_ARCH_LOCATE_TARGET) ;
|
|
} else {
|
|
MakeLocate $(file) : $(TARGET_COMMON_ARCH_LOCATE_TARGET) ;
|
|
}
|
|
}
|
|
}
|
|
|
|
rule MakeLocateArch
|
|
{
|
|
local files = $(1) ;
|
|
local file ;
|
|
for file in $(files) {
|
|
if [ on $(file) return $(PLATFORM) ] = host {
|
|
MakeLocate $(file) : $(HOST_COMMON_DEBUG_LOCATE_TARGET) ;
|
|
} else {
|
|
MakeLocate $(file) : $(TARGET_COMMON_DEBUG_LOCATE_TARGET) ;
|
|
}
|
|
}
|
|
}
|
|
|
|
rule MakeLocateDebug
|
|
{
|
|
local files = $(1) ;
|
|
local file ;
|
|
for file in $(files) {
|
|
on $(file) {
|
|
if $(PLATFORM) = host {
|
|
MakeLocate $(file) : $(HOST_DEBUG_$(DEBUG)_LOCATE_TARGET) ;
|
|
} else {
|
|
MakeLocate $(file) : $(TARGET_DEBUG_$(DEBUG)_LOCATE_TARGET) ;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
rule SearchAndReplace
|
|
{
|
|
# SearchAndReplace <newFile> : <sourceFile> : <stringToFind> : <stringToReplaceWith>
|
|
# A code generator that searches and replaces text in a source file to
|
|
# produce another.
|
|
# <newFile>: The file (a source file) being created by this
|
|
# search and replace code generation.
|
|
# <sourceFile>: The file being used to generate <newFile>.
|
|
# <stringToFind>: The string to search for in <sourceFile>.
|
|
# <stringToReplaceWith>: The string to replace with in the new file.
|
|
#
|
|
# For example usage see the MarkAs Tracker add-on code.
|
|
#
|
|
local _new_file = [ FGristSourceFiles $(1) ] ;
|
|
Depends all : $(_new_file) ;
|
|
Depends $(_new_file) : $(2) ;
|
|
MakeLocate $(_new_file) : $(LOCATE_SOURCE) ;
|
|
SEARCH on $(_new_file) = $(LOCATE_SOURCE) ;
|
|
Sed $(_new_file) : $(2) -e s/$(3)/$(4)/g ;
|
|
Clean clean : $(_new_file) ;
|
|
}
|
|
|
|
rule Sed
|
|
{
|
|
# Sed <newFile> : <parameters>
|
|
# <newFile>: The file (a source file) being created by this
|
|
# sed run.
|
|
# <parameters>: The parameters to sed in a list. The first item is
|
|
# the source file being searched through, the rest
|
|
# are standard sed parameters.
|
|
|
|
# We don't care about the parameters to sed
|
|
NoCare $(2[2-]) ;
|
|
NotFile $(2[2-]) ;
|
|
}
|
|
|
|
actions Sed
|
|
{
|
|
$(SED) $(2[2-]) $(2[1]) > $(1)
|
|
}
|
|
|