【问题标题】:Tricks for porting a large software project to tup build system将大型软件项目移植到 tup 构建系统的技巧
【发布时间】:2012-11-04 15:22:26
【问题描述】:

将具有数千个 .cpp 文件和相关标头的软件项目移植到 tup 构建系统的最佳方式是什么?

如果树看起来像:

colors/                                                                            
 primaries/
  red.cpp 
  green.cpp
  blue.cpp
 fruity/
  orange.cpp
  grape.cpp
 grayscale/
  white.cpp
  gray.cpp
  black.cpp
some/annoying/nesting/animals/
    horse.cpp
    bear.cpp

对于每个类别中包含数十个目标文件的数十个类别,编写一次性使用 shell 脚本来转储每个目录中的 Tupfile 似乎是一个相当不雅的解决方案,即使它们大多相似,这要归功于共享一个Tuprules.tup。什么是正确的、“最佳实践”、希望可移植的方式来使用 tup 构建这样的项目?

【问题讨论】:

  • 我意识到使用命令式配置文件构建系统,即 scons 和 CMake 擅长此类任务,但由于它有很多优点,所以我非常喜欢 tup。

标签: build-system tup


【解决方案1】:

通过最近添加的(仍然没有很好地记录)LUA 解析器,您可以避免每个目录只有一个 Tupfile。看看这里 http://gittup.org/tup/lua_parser.html 了解 Tupdefault.lua

此外 - 通过最近的更改,允许在不同文件夹中输出文件,您可以进一步简化它。您可以在“某处”编译文件,将它们添加到全局组中,然后 - 当您需要时,将它们全部链接/归档。

简单的 Tuprules.tup:

TOP = $(TUP_CWD)
!cc = |> gcc $(CFLAGS) -c %f -o %o |> %B.o $(TOP)/<objects>

仅用于编译的简单Tupfile(通用的,无需修改标志或某事):

include_rules

: foreach *.c |> !cc |>

用于编译和最终链接的简单 Tupfile(注释同上):

include_rules

: foreach *.c |> !cc |>
: $(TOP)/<objects> |> gcc %<objects> -o %o |> application.exe

不幸的是,我(还)不知道如何将这个特定功能(全局组)与 LUA 解析器一起使用。我什至在 tup-users 邮件列表上问过这个问题。

【讨论】:

    【解决方案2】:

    从 tup 手册页来看,tup 支持运行外部 shell 脚本:

          run ./script args
              Runs an external script with the given arguments to generate
              :-rules. This is an advanced feature that can be used when the
              standard Tupfile syntax is too simplistic for a complex program.
              The script is expected to write the :-rules to stdout. No other
              Tupfile commands are allowed - for example, the script cannot
              create $-variables or !-macros, but it can output :-rules that use
              those features. As a simple example, consider if a command must be
              executed 5 times, but there are no input files to use tup's
              foreach keyword. An external script called 'build.sh' could be
              written as follows:
    

    您可以触发一个脚本来生成必要的 tup 规则,但我认为这是不可移植的,因为您依赖于 shell。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-08-03
      • 1970-01-01
      • 2010-10-07
      • 2010-09-11
      • 2011-04-15
      • 2019-02-11
      • 1970-01-01
      相关资源
      最近更新 更多