# test pseudo targets NOTFILE obostests ; NOTFILE r5tests ; rule CommonTestLib { # CommonTestLib : : # : : : ; # Builds a unit test for both OBOS and R5 modules. # The name of the target. # The list of sources. # A list of link libraries for the OBOS tests (as passed # to LinkAgainst). # A list of link libraries for the R5 tests (as passed # to LinkAgainst). # A list of link libraries for both OBOS tests and R5 tests # that have a common name (i.e. specify libx.so and the OBOS tests will link # to libx.so and the R5 tests will link to libx_r5.so). # A list of public header dirs (as passed to # UsePublicHeaders). TestLib $(1) : $(2) : [ FDirName $(HAIKU_TEST_DIR) unittester lib ] : $(3) $(5) : $(6) ; R5TestLib $(1) : $(2) : [ FDirName $(HAIKU_TEST_DIR) unittester_r5 lib ] : $(4) [ R5SharedLibraryNames $(5) ] ; } rule TestLib { # TestLib : : : : # Builds a unit test library for an OBOS module. # The name of the target. # The list of sources. # The directory for the target (as passed to FDirName). # A list of link libraries (as passed to LinkAgainst). # A list of public header dirs (as passed to # UsePublicHeaders). local target = $(1) ; local sources = $(2) ; local dest = $(3) ; local libraries = $(4) ; local headerDirs = $(5) ; local objects = [ FGristFiles $(sources:S=$(SUFOBJ)) ] ; # Our Main replacement. MakeLocate $(target) : $(dest) ; MainFromObjects $(target) : $(objects) ; TestObjects $(sources) : $(headerDirs) ; Depends $(target) : libcppunit.so ; Depends obostests : $(target) ; LinkAgainst $(target) : libcppunit.so $(libraries) ; LINKFLAGS on $(target) = $(LINKFLAGS) -nostart -Xlinker -soname=\"$(target)\" ; } rule R5TestLib { # R5TestLib : : : # Builds a unit test for an R5 module. "_r5" is appended to the object # and the target name. # The name of the target. # The list of sources. # The directory for the target (as passed to FDirName). # A list of link libraries (as passed to LinkAgainst). local target = $(1:B)_r5$(1:S) ; local sources = $(2) ; local dest = $(3) ; local libraries = $(4) ; local objects = [ R5ObjectNames $(sources) ] ; # Our Main replacement. MakeLocate $(target) : $(dest) ; MainFromObjects $(target) : $(objects) ; TestObjects $(sources) : : true ; Depends $(target) : libcppunit.so ; Depends r5tests : $(target) ; LinkAgainst $(target) : libcppunit.so $(libraries) ; LINKFLAGS on $(target) = $(LINKFLAGS) -nostart -Xlinker -soname=\"$(target)\" ; } rule CommonUnitTest { # CommonUnitTest : : : # : : ; # Builds a unit test for both OBOS and R5 modules. # The name of the target. # The list of sources. # The directory for the target (as passed to FDirName). # A list of link libraries for the OBOS tests (as passed # to LinkAgainst). # A list of link libraries for the R5 tests (as passed # to LinkAgainst). # A list of public header dirs (as passed to # UsePublicHeaders). UnitTest $(1) : $(2) : $(3) : $(4) : $(6) ; R5UnitTest $(1) : $(2) : $(3) : $(5) ; } rule UnitTest { # UnitTest : : : : # Builds a unit test for an OBOS module. # The name of the target. # The list of sources. # The directory for the target (as passed to FDirName). # A list of link libraries (as passed to LinkAgainst). # A list of public header dirs (as passed to # UsePublicHeaders). local target = $(1) ; local sources = $(2) ; local dest = $(3) ; local libraries = $(4) ; local headerDirs = $(5) ; local objects = [ FGristFiles $(sources:S=$(SUFOBJ)) ] ; # Our Main replacement. MakeLocate $(target) : [ FDirName $(HAIKU_TEST_DIR) $(dest) ] ; MainFromObjects $(target) : $(objects) ; TestObjects $(sources) : $(headerDirs) ; Depends $(target) : libcppunit.so ; Depends obostests : $(target) ; LinkAgainst $(target) : libcppunit.so $(libraries) ; } rule R5UnitTest { # R5UnitTest : : : # Builds a unit test for an R5 module. "_r5" is appended to the object # and the target name. # The name of the target. # The list of sources. # The directory for the target (as passed to FDirName). # A list of link libraries (as passed to LinkAgainst). local target = $(1)_r5 ; local sources = $(2) ; local dest = $(3) ; local libraries = $(4) ; local objects = [ R5ObjectNames $(sources) ] ; # Our Main replacement. MakeLocate $(target) : [ FDirName $(HAIKU_TEST_DIR) $(dest) ] ; MainFromObjects $(target) : $(objects) ; TestObjects $(sources) : : true ; Depends $(target) : libcppunit.so ; Depends r5tests : $(target) ; LinkAgainst $(target) : libcppunit.so $(libraries) ; } rule R5ObjectNames { # R5ObjectNames ; # Returns a list of gristed object names given a list of source file names. # Moreover each object names gets "_r5" inserted before the object suffix. local objects = $(1:S=)_r5 ; return [ FGristFiles $(objects:S=$(SUFOBJ)) ] ; } rule R5Objects { # R5Objects # Similar to Objects, but appends "_r5" to the object file names and # removes `-nostdinc' from the CC and C++ flags to enable system headers. # The source files. # Remove `-nostdinc' from CCFLAGS and C++FLAGS. local oldCCFLAGS = $(CCFLAGS) ; local oldC++FLAGS = $(C++FLAGS) ; CCFLAGS = [ FFilter $(CCFLAGS) : -nostdinc ] ; C++FLAGS = [ FFilter $(C++FLAGS) : -nostdinc ] ; local sources = $(1) ; local source ; for source in [ FGristFiles $(sources) ] { local object = [ R5ObjectNames $(source) ] ; Object $(object) : $(source) ; LocalDepends obj : $(object) ; } # Reset CCFLAGS and C++FLAGS to original values. CCFLAGS = $(oldCCFLAGS) ; C++FLAGS = $(oldC++FLAGS) ; } rule TestObjects { # TestLib : : # Compiles objects for tests. # The list of sources. # A list of public header dirs (as passed to # UsePublicHeaders). # If set, "_r5" is appended to the object file names and # is ignored. Furthermore the pre-processor macro # TEST_R5 is defined, TEST_OBOS otherwise. local sources = $(1) ; local headerDirs = $(2) ; local r5 = $(3) ; local objects ; if $(r5) { objects = [ R5ObjectNames $(sources) ] ; } else { objects = [ FGristFiles $(sources:S=$(SUFOBJ)) ] ; } # Turn optimization off, if desired. if ! $(NO_TEST_DEBUG) { OPTIM on $(objects) = ; } # set headers/defines UseCppUnitObjectHeaders $(sources) : $(objects) ; if $(r5) { ObjectDefines $(sources) : TEST_R5 ; } else { UsePublicObjectHeaders $(sources) : $(headerDirs) : $(objects) ; ObjectDefines $(sources) : TEST_OBOS ; } if ! $(NO_TEST_DEBUG) { # Turn debugging on. That is usually desired for test code. ObjectCcFlags $(objects) : $(DEBUG_FLAGS) ; ObjectC++Flags $(objects) : $(DEBUG_FLAGS) ; } # compile if $(r5) { R5Objects $(sources) ; } else { Objects $(sources) ; } } rule R5SharedLibraryNames { # R5SharedLibraryNames ; # Returns a list of shared library names given a list of file names. NO # GRISTING IS PERFORMED :-) However, each library names gets "_r5" inserted # before the shared lib suffix. return $(1:S=)_r5.so ; } rule SimpleTest { # UnitTest : : # Builds a unit test for an OBOS module. # The name of the target. # The list of sources. # The directory for the target (as passed to FDirName). # A list of link libraries (as passed to LinkAgainst). # A list of public header dirs (as passed to # UsePublicHeaders). local target = $(1) ; local sources = $(2) ; local libraries = $(3) ; local relPath = [ FRelPath src tests : $(SUBDIR_TOKENS) ] ; # Turn optimization off. if ! $(NO_TEST_DEBUG) { local optim = $(OPTIM) ; OPTIM = ; } ObjectDefines $(sources) : TEST_OBOS ; MakeLocate $(target) : [ FDirName $(HAIKU_TEST_DIR) $(relPath) ] ; Main $(target) : $(sources) ; Depends obostests : $(target) ; LinkAgainst $(target) : $(libraries) ; if ! $(NO_TEST_DEBUG) { # Turn debugging on. That is usually desired for test code. ObjectCcFlags $(sources) : $(DEBUG_FLAGS) ; ObjectC++Flags $(sources) : $(DEBUG_FLAGS) ; # Turn optimization on again. OPTIM = $(optim) ; } } rule BuildPlatformTest { # Usage BuildPlatformTest : ; local target = $(1) ; local sources = $(2) ; local relPath ; if [ FIsPrefix src tests : $(SUBDIR_TOKENS) ] { relPath = $(SUBDIR_TOKENS[3-]) ; } else { relPath = $(SUBDIR_TOKENS[2-]) ; } MakeLocate $(target) : [ FDirName $(HAIKU_TEST_DIR) $(relPath) ] ; BuildPlatformMain $(target) : $(sources) ; }