On Tue, Jun 9, 2020 at 9:12 AM Lars Conrad <[email protected]> wrote:
> Hello, :-)
>
> I'm a "tup first timer”. I decided to give it a try, after I got fed up
> with cmake taking more time than gcc in many daily tasks.
>
Hi Lars, welcome! I found a few potential issues that may be causing you
problems. Please give them a shot, and if it's still not doing what you
expect then feel free to write back and give another tar.gz of what you're
working on (that is very helpful, thanks!)
> I would like to have three build configurations, which are the same for
> the directories containing the "test_config", as well as the "src"
> directory:
> debug.config: CONFIG_BUILD_TYPE=debug
> release.config: CONFIG_BUILD_TYPE=release
> static.config: CONFIG_BUILD_TYPE=static
>
To use tup's variants, you should just have the build configurations at one
level at the top where you run 'tup init'. The symlinks you had for the
top-level build configurations were broken, so I moved the tup-configs in
src to the top-level to fix them (and remove them in src, since we just
want them in the top-level):
$ mv src/tup-configs .
$ rm -rf src/build-*
> Then I have my universal build rules in a file ("Tuprules.tup") in the
> "src" directory, which is to be included where it's needed:
>
> # Tuprules.tup in config_module/src
>
> ifeq (@(BUILD_TYPE),debug)
> # debug build:
> CPPFLAGS += -march=native
> CPPFLAGS += -ggdb3
> CPPFLAGS += -D_GLIBCXX_DEBUG
> else
> ifeq (@(BUILD_TYPE),release)
> CPPFLAGS += -march=native
> CPPFLAGS += -O2
> LDFLAGS += --as-needed -flto
> else
> ifeq (@(BUILD_TYPE),static)
> CPPFLAGS += -static -Os
> LDFLAGS += --as-needed -flto
> else
> error "Build type not set or wrong!"
> endif
> endif
> endif
>
In LDFLAGS here you are mixing flags for ld (--as-needed) and flags for gcc
(-flto). In your build rules you then use -Wl,$(LDFLAGS) which won't work
if LDFLAGS isn't set (as is the case for the debug build). So I'd recommend
doing LDFLAGS += -Wl,--as-needed -flto and just use $(LDFLAGS) in your
linker rules.
I did put a "Tupfile" in the "src" directory, which contained this:
>
> # Tupfile in config_module/src
>
> CPPFLAGS += -std=c++17
> CPPFLAGS += -Wall
> LDFLAGS += -lstdc++fs
>
> include_rules
>
> : foreach *.cpp |> g++ $(CPPFLAGS) -c %f -o %o |> %B.o
>
Looks good!
In the top directory (for building the unit test executable) I have this in
> a Tupfile:
>
> # Tupfile in config_module
>
> PROG_NAME = test_config
> MY_CONFIG_FOLDER = $(TUP_CWD)/debug_config_folder
>
> CPPFLAGS += -std=c++17
> CPPFLAGS += -Wall
> CPPFLAGS += -Isrc
>
> include_rules
>
Note that include_rules includes Tuprules.tup files in the current
directory, and all directories up to the root (where .tup is created).
Since your main Tuprules.tup file is in the src directory, it won't get
included in this top-level Tupfile. I think you should move
src/Tuprules.tup to the config_module directory (or higher, if you intend
it to be shared by multiple modules).
> : foreach *.cpp |> g++ $(CPPFLAGS) -D$(MY_CONFIG_FOLDER) -c %f -o %o |>
> %B.o
>
What are you intending to do with the -D$(MY_CONFIG_FOLDER)? This is a path
name, which gets expanded to something like -D./debug_config_folder, which
is probably not what you want. This made the compilation fail for me, and
I'm not sure what it's trying to do, so I removed the -D flag.
> # doesn't work : *.o |> gcc %f -o %o -Wl,$(LDFLAGS) |> $(PROG_NAME)
> : *.o |> gcc %f -o %o -Wl,$(LDFLAGS) |> test_config
>
As mentioned above, change -Wl,$(LDFLAGS) into just $(LDFLAGS) after making
the adjustments in setting LDFLAGS to Tuprules.tup
> When I remove the ".tup" from the "src" directory and instead "init" the
> top directory, neither work.
> To be clear: When running "tup build-debug" in the "src" directory, I want
> it to compile "config.cpp" and "platform_folders.cpp" into ".o" files
> within the "build-debug" directory under the "src" directory.
>
With tup's variants, you get a build-debug directory at the top-level, with
the directory structure duplicated underneath. So instead of build-debug in
config_module and build_debug in src, you'd have one build_debug/ at the
top, and src underneath (which gets created by tup as part of the build).
So if you just want to build stuff in src for debug, run 'tup
build_debug/src' at the top-level. To do the whole module as debug, 'tup
build_debug', and to build all variants just do 'tup'.
> When running "tup build-debug" in the top directory, it should compile
> "test_config.cpp" into "test_config.o" and then link it to "test_config",
> both into the top-level "build-debug" directory.
> In case the dependencies from the sub-module/project (in "src") aren't
> compiled, it should do that first.
>
The good news is if you can get it to compile cleanly once, the
dependencies part should work automatically :)
This patch applied to your example builds for me when running 'tup init'
inside config_module, which includes the changes discussed above. Though
again, if you plan to have multiple modules alongside config_module, you
may want to run init & have your Tuprules.tup one level higher.
diff --git a/Tupfile b/Tupfile
index 3d46419..d7be7e4 100644
--- a/Tupfile
+++ b/Tupfile
@@ -9,5 +9,5 @@ CPPFLAGS += -Isrc
include_rules
-: foreach *.cpp |> g++ $(CPPFLAGS) -D$(MY_CONFIG_FOLDER) -c %f -o %o |>
%B.o
-: *.o |> gcc %f -o %o -Wl,$(LDFLAGS) |> $(PROG_NAME)
+: foreach *.cpp |> g++ $(CPPFLAGS) -c %f -o %o |> %B.o
+: *.o |> gcc %f -o %o $(LDFLAGS) |> $(PROG_NAME)
diff --git a/src/Tuprules.tup b/Tuprules.tup
similarity index 83%
rename from src/Tuprules.tup
rename to Tuprules.tup
index cea6f37..34acd3d 100644
--- a/src/Tuprules.tup
+++ b/Tuprules.tup
@@ -9,11 +9,11 @@ else
ifeq (@(BUILD_TYPE),release)
CPPFLAGS += -march=native
CPPFLAGS += -O2
- LDFLAGS += --as-needed -flto
+ LDFLAGS += -Wl,--as-needed -flto
else
ifeq (@(BUILD_TYPE),static)
CPPFLAGS += -static -Os
- LDFLAGS += --as-needed -flto
+ LDFLAGS += -Wl,--as-needed -flto
else
error "Build type not set or wrong!"
endif
diff --git a/src/build-debug/tup.config b/src/build-debug/tup.config
deleted file mode 120000
index 84c56af..0000000
--- a/src/build-debug/tup.config
+++ /dev/null
@@ -1 +0,0 @@
-../tup-configs/debug.config
\ No newline at end of file
diff --git a/src/build-release/tup.config b/src/build-release/tup.config
deleted file mode 120000
index 98b9f34..0000000
--- a/src/build-release/tup.config
+++ /dev/null
@@ -1 +0,0 @@
-../tup-configs/release.config
\ No newline at end of file
diff --git a/src/build-static/tup.config b/src/build-static/tup.config
deleted file mode 120000
index 6bdbdf7..0000000
--- a/src/build-static/tup.config
+++ /dev/null
@@ -1 +0,0 @@
-../tup-configs/static.config
\ No newline at end of file
diff --git a/test_config.cpp b/test_config.cpp
index e69de29..b552c8e 100644
--- a/test_config.cpp
+++ b/test_config.cpp
@@ -0,0 +1 @@
+int main(void) {}
diff --git a/src/tup-configs/debug.config b/tup-configs/debug.config
similarity index 100%
rename from src/tup-configs/debug.config
rename to tup-configs/debug.config
diff --git a/src/tup-configs/release.config b/tup-configs/release.config
similarity index 100%
rename from src/tup-configs/release.config
rename to tup-configs/release.config
diff --git a/src/tup-configs/static.config b/tup-configs/static.config
similarity index 100%
rename from src/tup-configs/static.config
rename to tup-configs/static.config
-Mike
--
--
tup-users mailing list
email: [email protected]
unsubscribe: [email protected]
options: http://groups.google.com/group/tup-users?hl=en
---
You received this message because you are subscribed to the Google Groups
"tup-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/tup-users/CA%2B6x0LX34Do6U4jc_QhRGQ6gOPRAFKqCqvHrm9B-_JKD9FhW2g%40mail.gmail.com.