Advertisement
Alex11223

Untitled

Dec 8th, 2011
28
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 9.94 KB | None | 0 0
  1. # MainBuildRules
  2. #
  3. # Rules that specify what to build and how to do it.
  4.  
  5. rule Application
  6. {
  7.     # Application <name> : <sources> : <libraries> ;
  8.     #
  9.     # Creates an application from sources.
  10.     #
  11.     # <name>: Name of the application. Grist is allowed.
  12.     # <sources>: List of source files. Grist will be set.
  13.     # <libraries>: List of libraries to link against.
  14.     #
  15.     local app = $(1) ;
  16.     local sources = $(2) ;
  17.     local libs = $(3) ;
  18.  
  19.     Main $(app) : $(sources) ;
  20.     MakeLocate $(app) : $(LOCATE_MAIN_TARGET) ;
  21.     local linkFlags ;
  22.     if $(OSPLAT) = X86 {
  23.         linkFlags = -Xlinker -soname=\"_APP_\" ;
  24.     } else {
  25.         linkFlags = ;
  26.     }
  27.     LINKFLAGS on $(app) = [ on $(app) return $(LINKFLAGS) ] $(linkFlags) ;
  28.     LinkAgainst $(app) : $(libs) ;
  29. }
  30.  
  31. actions Strip
  32. {
  33.     strip "$(1)" ;
  34. }
  35.  
  36. rule AddOn
  37. {
  38.     # AddOn <name> : <sources> : <libraries> ;
  39.     #
  40.     # Creates an add-on from sources.
  41.     #
  42.     # <name>: Name of the add-on. Grist is allowed.
  43.     # <sources>: List of source files. Grist will be set.
  44.     # <libraries>: List of libraries to link against.
  45.     #
  46.     SharedLibrary $(1) : $(2) : $(3) ;
  47. }
  48.  
  49. rule SharedLibrary
  50. {
  51.     # SharedLibrary <name> : <sources> : <libraries> ;
  52.     #
  53.     # Creates a shared library from sources.
  54.     #
  55.     # <name>: Name of the shared library. Grist is allowed.
  56.     # <sources>: List of source files. Grist will be set.
  57.     # <libraries>: List of libraries to link against.
  58.     #
  59.     local lib = $(1) ;
  60.     local sources = $(2) ;
  61.     local libs = $(3) ;
  62.  
  63.     Main $(lib) : $(sources) ;
  64.     MakeLocate $(lib) : $(LOCATE_MAIN_TARGET) ;
  65.     local linkFlags ;
  66.     if $(OSPLAT) = X86 {
  67.         linkFlags = -nostart -Xlinker -soname=\"$(lib)\"
  68.             -Xlinker --no-undefined ;
  69.     } else {
  70.         linkFlags = -xms ;
  71.     }
  72.     LINKFLAGS on $(lib) = [ on $(lib) return $(LINKFLAGS) ] $(linkFlags) ;
  73.     LinkAgainst $(lib) : $(libs) ;
  74. }
  75.  
  76. rule StaticLibrary
  77. {
  78.     # StaticLibrary <name> : <sources> ;
  79.     #
  80.     # Creates a static library from sources.
  81.     #
  82.     # <name>: Name of the static library. Grist is allowed.
  83.     # <source>: List of source files. Grist will be set.
  84.     #
  85.     local lib = $(1) ;
  86.     Library $(lib) : $(2) ;
  87.     MakeLocate $(lib) : $(LOCATE_MAIN_TARGET) ;
  88.  
  89.     # If KEEPOBJS is set, Library doesn't make the library depend on `lib'.
  90.     if $(KEEPOBJS) {
  91.         Depends lib : $(lib) ;
  92.     }
  93. }
  94.  
  95. rule LinkAgainst
  96. {
  97.     # LinkAgainst <name> : <libs> ;
  98.     #
  99.     # Adds libraries to the list of libraries a (Main) target shall be linked
  100.     # against.
  101.     #
  102.     # <name>: The name of the target for which to add libraries.
  103.     # <libs>: The libraries (actually arbitrary shared objects and static
  104.     #         libraries) to be added. Valid elements are e.g. "be" or
  105.     #         "libopenbeos.so" or "/boot/.../libfoo.so". If the basename starts
  106.     #         with "lib" or the thingy has a dirname or grist, it is added to
  107.     #         the NEEDLIBS variable (i.e. the file will be bound!), otherwise
  108.     #         it is prefixed "-l" and added to LINKLIBS. If you want to specify
  109.     #         a target that isn't a library and also has neither grist nor a
  110.     #         dirname, you can prepend "<nogrist>" as grist; it will be
  111.     #         stripped by this rule.
  112.     #
  113.     for i in $(>)
  114.     {
  115.         local isfile = ;
  116.         if $(i:D) || $(i:G) {
  117.             isfile = true ;
  118.             if $(i:G) = <nogrist> {
  119.                 i = $(i:G=) ;
  120.             }
  121.         } else {
  122.             switch $(i:B)
  123.             {
  124.                 # XXX: _APP_ and _KERNEL_ should not be needed for ELF.
  125.                 case _APP_ : isfile = true ;
  126.                 case _KERNEL_ : isfile = true ;
  127.                 case lib*   : isfile = true ;
  128.                 case *  : isfile = ;
  129.             }
  130.             if ! $(isfile) && ( $(i:S) = .so || $(i:S) = .a ) {
  131.                 isfile = true ;
  132.             }
  133.         }
  134.         if $(isfile) {
  135.             NEEDLIBS on $(1) = [ on $(1) return $(NEEDLIBS) ] $(i) ;
  136.             Depends $(1) : $(i) ;
  137.         } else {
  138.             LINKLIBS on $(1) = [ on $(1) return $(LINKLIBS) ] -l$(i) ;
  139.         }
  140.     }
  141. }
  142.  
  143. rule XRes
  144. {
  145.     # XRes <target> : <resource files> ;
  146.     #
  147.     # Adds resources to a file.
  148.     #
  149.     # <target>: The files to which resources shall be added.
  150.     # <resource files>: The resource files.
  151.     #
  152.     if $(2)
  153.     {
  154.         Depends $(1) : $(2) ;
  155.         XRes1 $(1) : $(2) ;
  156.     }
  157. }
  158.  
  159. actions XRes1
  160. {
  161.     xres -o "$(1)" "$(2)" ;
  162. }
  163.  
  164. actions MimeSet
  165. {
  166.     mimeset -f "$(1)" ;
  167. }
  168.  
  169. rule LexC++
  170. {
  171.     Depends $(1) : $(2) ;
  172.     MakeLocate $(1) : $(LOCATE_SOURCE) ;
  173.     Clean clean : $(1) ;
  174. }
  175.  
  176. actions LexC++
  177. {
  178.     $(LEX) -i -o$(1) $(2)
  179. }
  180.  
  181. rule Bison
  182. {
  183.     local _h ;
  184.  
  185.     _h = $(1).h ;
  186.  
  187.     MakeLocate $(<) $(_h) : $(LOCATE_SOURCE) ;
  188.  
  189.    Depends $(<) $(_h) : $(>) ;
  190.    BisonC++ $(<) $(_h) : $(>) ;
  191.    Clean clean : $(<) $(_h) ;
  192.  
  193.     # make sure someone includes $(_h) else it will be
  194.     # a deadly independent target
  195.  
  196.     Includes $(<) : $(_h) ;
  197. }
  198.  
  199. actions BisonC++
  200. {
  201.     # TODO: this ignores $(YACCFLAGS)
  202.     $(BISON) --defines=$(1[1]).h -o $(1[1]) $(2) || $(BISON) $(YACCFLAGS) -o $(1[1]) $(2)
  203. }
  204.  
  205. rule Rez
  206. {
  207.     # Rez <output> : <rezFile> [ : <flags> ] ;
  208.     #
  209.     local output = $(1) ;
  210.     local rezFile = $(2) ;
  211.     local flags = $(3) ;
  212.    
  213.     REZHDRS on $(output) = [ on $(output) return "-I"$(HDRS) ] ;
  214.     REZFLAGS on $(output) = [ on $(output) return $(REZFLAGS) ] $(flags) ;
  215.     Depends $(output) : rez $(rezFile) ;
  216.     Rez1 $(output) : rez $(rezFile) ;
  217. }
  218.  
  219. actions Rez1
  220. {
  221.     $(2[1]) $(REZFLAGS) $(REZHDRS) -o "$(1)" "$(2[2-])" ;
  222. }
  223.  
  224. rule RezObjects
  225. {
  226.     local rezFiles = $(1) ;
  227.     local rezFile ;
  228.     for rezFile in $(rezFiles) {
  229.         local rsrcFile = $(rezFile:BS=.rsrc) ;
  230.         RezObject $(rsrcFile) : [ FGristFiles $(rezFile) ] ;
  231.     }
  232. }
  233.  
  234. rule RezObject
  235. {
  236.     # RezObject <resource file> : <rez file> ;
  237.     #
  238.     local _rsrc = $(1) ;
  239.     local _r = $(2) ;
  240.  
  241.     local tmp = [ FGristFiles $(_rsrc)_tmp ] ;
  242.  
  243.     SEARCH on $(_r) = $(SEARCH_SOURCE) ;
  244.  
  245.     # include directories to be used
  246.     HDRS on $(_rsrc) $(tmp) = $(SEARCH_SOURCE) $(SUBDIRHDRS) $(HDRS) ;
  247.  
  248.     # preprocess the rez file
  249.     PreProcess $(tmp) : $(_r) ;
  250.  
  251.     # generate the resource file from the preprocessed rez file
  252.     MakeLocate $(_rsrc) : $(LOCATE_TARGET) ;
  253.     Rez $(_rsrc) : $(tmp) : -t ;
  254. }
  255.  
  256. rule PreProcess
  257. {
  258.     # PreProcess <target> : <source> ;
  259.     #
  260.     local target = $(1) ;
  261.     local source = $(2) ;
  262.  
  263.     Depends $(target) : $(source) ;
  264.  
  265.     CPPHDRS on $(target) = [ on $(target) FIncludes $(HDRS) ] ;
  266.  
  267.     MakeLocate $(target) : $(LOCATE_SOURCE) ;
  268. }
  269.  
  270. if $(OSPLAT) = PPC {
  271.     actions PreProcess
  272.     {
  273.         mwcc -preprocess $(CPPHDRS) -o "$(1)" $(2)
  274.     }
  275. } else {
  276.     actions PreProcess
  277.     {
  278.         gcc -E -x c $(CPPHDRS) -o "$(1)" $(2)
  279.     }
  280. }
  281.  
  282. rule RezHeader
  283. {
  284.     # RezHeader : <hdr> : <rsrc>
  285.     #
  286.     # generates a header from a given resource file.
  287.     #
  288.     local _hdr = $(1) ;
  289.     local _rsrc = $(2) ;
  290.  
  291.     SEARCH on $(_rsrc) = $(SEARCH_SOURCE) ;
  292.     HDRS on $(_hdr) = $(SEARCH_SOURCE) $(SUBDIRHDRS) $(HDRS) ;
  293.     MakeLocate $(_hdr) : $(LOCATE_SOURCE) ;
  294.     Clean clean : $(_hdr) ;
  295.  
  296.     Rez $(_hdr) : $(_rsrc) : -h ;
  297. }
  298.  
  299. rule PreCompile
  300. {
  301.     # PreCompile <hdr> : <src>
  302.     #
  303.     # precompiles the given src (a headerfile) into the specified header.
  304.     #
  305.     local _hdr = $(1) ;
  306.     local _src = $(2) ;
  307.     MakeLocate $(_hdr) : $(LOCATE_TARGET) ;
  308.     PreComp $(_hdr) : $(_src) ;
  309.     Clean clean : $(_hdr) ;
  310. }
  311.  
  312. rule PreComp
  313. {
  314.     Depends $(<) : $(>) ;
  315. }
  316.  
  317. actions PreComp
  318. {
  319.     mwcc -precompile $(<) -lang cplus "$(>)" ;
  320. }
  321.  
  322. rule PeLanguage
  323. {
  324.     # PeLanguage <language> : <srcs> : <libs> : <rsrc>
  325.     #
  326.     # generates a SharedLib which extends Pe with syntax-highlighting for
  327.     # that specific language.
  328.     #
  329.     local lang = $(1) ;
  330.     local srcs = $(2) ;
  331.     local libs = $(3) ;
  332.     local rsrc = $(4) ;     # contains keywords
  333.  
  334.     SharedLibrary $(lang) : $(srcs) : $(libs) ;
  335.     XRes $(lang) : $(rsrc) ;
  336. }
  337.  
  338. rule PeExtension
  339. {
  340.     # PeExtension <extension> : <srcs> : <libs> : <rsrcs>
  341.     #
  342.     # generates a SharedLib which extends Pe with a specific feature.
  343.     #
  344.     local ext = $(1) ;
  345.     local srcs = [ FGristFiles $(2) ] ;
  346.     local libs = $(3) ;
  347.     local rsrc = [ FGristFiles $(4) ] ;     # optional resource file
  348.  
  349.     if $(rsrc) {
  350.         local header = $(rsrc:BS=.r.h) ;
  351.  
  352.         Includes $(srcs) : $(header) ;
  353.         RezHeader $(header) : $(rsrc) ;
  354.     }
  355.     SharedLibrary $(ext) : $(srcs) : $(libs) ;
  356.  
  357.     SymlinkDistroExtensionsLibDir $(ext) ;
  358. }
  359.  
  360. rule SymlinkDistroExtensionsLibDir
  361. {
  362.     # SymlinkDistroExtensionsLibDir <extension> ;
  363.     #
  364.     local extension = $(1) ;
  365.  
  366.     Depends $(extension) : <distro_extensions_dir_symlink>lib ;
  367.     NoUpdate <distro_extensions_dir_symlink>lib ;
  368.     MakeLocate <distro_extensions_dir_symlink>lib : $(DISTRO_DIR)/Extensions ;
  369.  
  370.     SymlinkDistroExtensionsLibDir1 <distro_extensions_dir_symlink>lib ;
  371. }
  372.  
  373. actions together SymlinkDistroExtensionsLibDir1
  374. {   # create a link to the folder where libhekkel.so lives
  375.     ln -sfn ../lib $(1) ;
  376. }
  377.  
  378. rule SubDirSysHdrs
  379. {
  380.     # SubDirSysHdrs <dirs> ;
  381.     #
  382.     # Adds directories to the system include search paths for the current
  383.     # subdirectory. Counterpart of SubDirHdrs which adds non-system include
  384.     # search paths.
  385.     #
  386.     # <dirs>: The directories to be added to the current subdir's system
  387.     #         include search paths.
  388.     #
  389.     SUBDIRSYSHDRS += [ FDirName $(1) ] ;
  390. }
  391.  
  392. rule ObjectSysHdrs
  393. {
  394.     # SubDirSysHdrs <sources or objects> : <dirs> ;
  395.     #
  396.     # Adds directories to the system include search paths for the given
  397.     # sources or objects. Counterpart of ObjectHdrs which adds non-system
  398.     # include search paths.
  399.     #
  400.     # NOTE: This rule must be invoked *after* the rule that generates the
  401.     # objects.
  402.     #
  403.     # <sources or objects>: The targets for which to add system include
  404.     #                       search paths.
  405.     # <dirs>: The directories to be added to the given objects' system
  406.     #         include search paths.
  407.     #
  408.  
  409.     local s ;
  410.     for s in [ FGristFiles $(<:S=$(SUFOBJ)) ] {
  411.         SYSHDRS on $(s) += $(>) ;
  412.         CCHDRS on $(s) = [ on $(s) FIncludes $(HDRS) ]
  413.             $(HDRS_INCLUDES_SEPARATOR) [ on $(s) FSysIncludes $(SYSHDRS) ] ;
  414.     }
  415. }
  416.  
  417. # FSysIncludes <dirs> ;
  418. #
  419. # Counterpart of FIncludes for system include search paths.
  420. #
  421. if $(IS_GCC_4_PLATFORM) {
  422.     rule FSysIncludes { return -I$(<) ; }
  423. } else {
  424.     if $(OSPLAT) = X86 {
  425.         rule FSysIncludes { return -I$(<) ; }
  426.     } else {
  427.         rule FSysIncludes { return "-i "$(<) ; }
  428.     }
  429. }
  430.  
  431. # Variable referring to the STL.
  432. if $(IS_GCC_4_PLATFORM) {
  433.     # gcc 4 Haiku
  434.     STDC++LIB = stdc++ ;
  435. } else {
  436.     # BeOS or BeOS compatible Haiku
  437.     if $(OSPLAT) = X86 {
  438.         STDC++LIB = stdc++.r4 ;
  439.     } else {
  440.         STDC++LIB = mslcpp_4_0 ;
  441.     }
  442. }
  443.  
  444.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement