c++tup

Tup variants not building correctly


I switched from make to tup and am trying to get it to build different variants (debug and production). My source tree looks like this:

| .tup
| bin
| build_debug
| | tup.config
| build_default
| | tup.config
| include (headers directory)
| src (source files directory)
| | runs (directory containing additional source files)
| Tupfile

And my Tupfile:

preload bin
preload src
preload src/runs

COMPILER = g++
ifeq (@(DEBUG),y)
FLAGS = -Wall -std=c++17 -O0 -g 
else
FLAGS = -Wall -std=c++17 -O3 -march=native -flto -pipe
endif

: foreach src/*.cc src/runs/*.cc |> $(COMPILER) -c %f -o %o $(FLAGS) |> %B.o
: src/*.o src/runs/*.o |> $(COMPILER) %f -o %o $(FLAGS) |> bin/a.out

I want this to create object files within the src directories and a binary within the bin directories inside the build* directories.

When I run tup, it will create object files directly inside the build* directories (so not inside the build*/src directories) and not create any binaries.

What am I doing wrong?

Edit: When building inside the base directory without any build* directories it will create a binary but also place the object files within the base directory and not inside src.


Solution

  • So I solved it with the help of the tup manual.

    %B only expands to the filename, not the filename including the relative path of the file to the basedir, which is why the object files were created in the base directory and the binary could not be generated (I thought it worked because I still had some old object files which had been generated using make).

    I rewrote my Tupfile to:

    preload src
    preload src/runs
    
    COMPILER = g++
    ifeq (@(DEBUG),y)
    FLAGS = -Wall -std=c++17 -O0 -g 
    else
    FLAGS = -Wall -std=c++17 -O3 -march=native -flto -pipe
    endif
    
    : foreach src/*.cc |> $(COMPILER) -c %f -o %o $(FLAGS) |> src/%B.o
    : foreach src/runs/*.cc |> $(COMPILER) -c %f -o %o $(FLAGS) |> src/runs/%B.o
    : src/*.o src/runs/*.o |> $(COMPILER) %f -o %o $(FLAGS) |> bin/a.out