From 927ba6407a6c67a887aaa03ed81daccb00f259ef Mon Sep 17 00:00:00 2001 From: John Ericson Date: Sat, 2 Sep 2023 17:10:28 -0400 Subject: [PATCH] Allow for putting Unix-only files in subdirs This will allow avoiding a lot of CPP. --- local.mk | 7 ++++++- src/libcmd/local.mk | 2 +- src/libexpr/local.mk | 2 +- src/libexpr/tests/local.mk | 2 +- src/libfetchers/local.mk | 2 +- src/libmain/local.mk | 2 +- src/libstore/local.mk | 19 +++++++++++++------ src/libstore/tests/local.mk | 2 +- src/libutil/local.mk | 10 ++++++++++ src/libutil/tests/local.mk | 2 +- src/nix/local.mk | 2 +- src/resolve-system-dependencies/local.mk | 2 +- tests/functional/plugins/local.mk | 2 +- .../functional/test-libstoreconsumer/local.mk | 2 +- 14 files changed, 40 insertions(+), 18 deletions(-) diff --git a/local.mk b/local.mk index 3f3abb9f0d69..cd45c1a659f2 100644 --- a/local.mk +++ b/local.mk @@ -5,6 +5,11 @@ ERROR_SWITCH_ENUM = -Werror=switch-enum $(foreach i, config.h $(wildcard src/lib*/*.hh), \ $(eval $(call install-file-in, $(i), $(includedir)/nix, 0644))) +ifdef HOST_UNIX + $(foreach i, config.h $(wildcard src/lib*/unix/*.hh), \ + $(eval $(call install-file-in, $(i), $(includedir)/nix, 0644))) +endif + $(GCH): src/libutil/util.hh config.h -GCH_CXXFLAGS = -I src/libutil +GCH_CXXFLAGS = $(INCLUDE_libutil) diff --git a/src/libcmd/local.mk b/src/libcmd/local.mk index 541a7d2bac71..81ff313f407c 100644 --- a/src/libcmd/local.mk +++ b/src/libcmd/local.mk @@ -6,7 +6,7 @@ libcmd_DIR := $(d) libcmd_SOURCES := $(wildcard $(d)/*.cc) -libcmd_CXXFLAGS += -I src/libutil -I src/libstore -I src/libexpr -I src/libmain -I src/libfetchers +libcmd_CXXFLAGS += $(INCLUDE_libutil) $(INCLUDE_libstore) -I src/libexpr -I src/libmain -I src/libfetchers libcmd_LDFLAGS = $(EDITLINE_LIBS) $(LOWDOWN_LIBS) -pthread diff --git a/src/libexpr/local.mk b/src/libexpr/local.mk index d243b9cec1d1..6579277ab943 100644 --- a/src/libexpr/local.mk +++ b/src/libexpr/local.mk @@ -12,7 +12,7 @@ libexpr_SOURCES := \ $(d)/lexer-tab.cc \ $(d)/parser-tab.cc -libexpr_CXXFLAGS += -I src/libutil -I src/libstore -I src/libfetchers -I src/libmain -I src/libexpr +libexpr_CXXFLAGS += $(INCLUDE_libutil) $(INCLUDE_libstore) -I src/libfetchers -I src/libmain -I src/libexpr libexpr_LIBS = libutil libstore libfetchers diff --git a/src/libexpr/tests/local.mk b/src/libexpr/tests/local.mk index 331a5ead60e4..5911607bbd9c 100644 --- a/src/libexpr/tests/local.mk +++ b/src/libexpr/tests/local.mk @@ -12,7 +12,7 @@ libexpr-tests_SOURCES := \ $(wildcard $(d)/*.cc) \ $(wildcard $(d)/value/*.cc) -libexpr-tests_CXXFLAGS += -I src/libexpr -I src/libutil -I src/libstore -I src/libexpr/tests -I src/libfetchers +libexpr-tests_CXXFLAGS += -I src/libexpr $(INCLUDE_libutil) $(INCLUDE_libstore) -I src/libexpr/tests -I src/libfetchers libexpr-tests_LIBS = libstore-tests libutils-tests libexpr libutil libstore libfetchers diff --git a/src/libfetchers/local.mk b/src/libfetchers/local.mk index 2e8869d83fa8..8319cac84c1e 100644 --- a/src/libfetchers/local.mk +++ b/src/libfetchers/local.mk @@ -6,7 +6,7 @@ libfetchers_DIR := $(d) libfetchers_SOURCES := $(wildcard $(d)/*.cc) -libfetchers_CXXFLAGS += -I src/libutil -I src/libstore +libfetchers_CXXFLAGS += $(INCLUDE_libutil) $(INCLUDE_libstore) libfetchers_LDFLAGS += -pthread diff --git a/src/libmain/local.mk b/src/libmain/local.mk index 99da95e27975..cc8fb78f4bb4 100644 --- a/src/libmain/local.mk +++ b/src/libmain/local.mk @@ -6,7 +6,7 @@ libmain_DIR := $(d) libmain_SOURCES := $(wildcard $(d)/*.cc) -libmain_CXXFLAGS += -I src/libutil -I src/libstore +libmain_CXXFLAGS += $(INCLUDE_libutil) $(INCLUDE_libstore) libmain_LDFLAGS += $(OPENSSL_LIBS) diff --git a/src/libstore/local.mk b/src/libstore/local.mk index 0be0bf310589..4eea8caa49ee 100644 --- a/src/libstore/local.mk +++ b/src/libstore/local.mk @@ -10,7 +10,7 @@ libstore_LIBS = libutil libstore_LDFLAGS += $(SQLITE3_LIBS) $(LIBCURL_LIBS) $(SODIUM_LIBS) -pthread ifdef HOST_LINUX - libstore_LDFLAGS += -ldl + libstore_LDFLAGS += -ldl endif $(foreach file,$(libstore_FILES),$(eval $(call install-data-in,$(d)/$(file),$(datadir)/nix/sandbox))) @@ -28,7 +28,7 @@ ifeq ($(HAVE_SECCOMP), 1) endif libstore_CXXFLAGS += \ - -I src/libutil -I src/libstore -I src/libstore/build \ + $(INCLUDE_libutil) $(INCLUDE_libstore) -I src/libstore/build \ -DNIX_PREFIX=\"$(prefix)\" \ -DNIX_STORE_DIR=\"$(storedir)\" \ -DNIX_DATA_DIR=\"$(datadir)\" \ @@ -55,8 +55,6 @@ endif $(d)/local-store.cc: $(d)/schema.sql.gen.hh $(d)/ca-specific-schema.sql.gen.hh -$(d)/build.cc: - clean-files += $(d)/schema.sql.gen.hh $(d)/ca-specific-schema.sql.gen.hh $(eval $(call install-file-in, $(d)/nix-store.pc, $(libdir)/pkgconfig, 0644)) @@ -64,5 +62,14 @@ $(eval $(call install-file-in, $(d)/nix-store.pc, $(libdir)/pkgconfig, 0644)) $(foreach i, $(wildcard src/libstore/builtins/*.hh), \ $(eval $(call install-file-in, $(i), $(includedir)/nix/builtins, 0644))) -$(foreach i, $(wildcard src/libstore/build/*.hh), \ - $(eval $(call install-file-in, $(i), $(includedir)/nix/build, 0644))) +ifdef HOST_UNIX + $(foreach i, $(wildcard src/libstore/unix/build/*.hh), \ + $(eval $(call install-file-in, $(i), $(includedir)/nix/build, 0644))) +endif + +# Not for libnixstore itself, but for downstream libraries using libnixstore + +INCLUDE_libstore := -I $(d) +ifdef HOST_UNIX + INCLUDE_libstore := -I $(d)/unix +endif diff --git a/src/libstore/tests/local.mk b/src/libstore/tests/local.mk index 03becc7d11b6..deb9a2809d2b 100644 --- a/src/libstore/tests/local.mk +++ b/src/libstore/tests/local.mk @@ -22,7 +22,7 @@ libstore-tests_INSTALL_DIR := libstore-tests_SOURCES := $(wildcard $(d)/*.cc) -libstore-tests_CXXFLAGS += -I src/libstore -I src/libutil +libstore-tests_CXXFLAGS += $(INCLUDE_libstore) $(INCLUDE_libutil) libstore-tests_LIBS = libutil-tests libstore libutil diff --git a/src/libutil/local.mk b/src/libutil/local.mk index 81efaafeca85..ee1fd3aed450 100644 --- a/src/libutil/local.mk +++ b/src/libutil/local.mk @@ -5,6 +5,9 @@ libutil_NAME = libnixutil libutil_DIR := $(d) libutil_SOURCES := $(wildcard $(d)/*.cc) +ifdef HOST_UNIX + libutil_SOURCES := $(wildcard $(d)/unix/*.cc) +endif libutil_CXXFLAGS += -I src/libutil @@ -16,3 +19,10 @@ $(foreach i, $(wildcard $(d)/args/*.hh), \ ifeq ($(HAVE_LIBCPUID), 1) libutil_LDFLAGS += -lcpuid endif + +# Not for libnixutil itself, but for downstream libraries using libnixutil + +INCLUDE_libutil := -I $(d) +ifdef HOST_UNIX + INCLUDE_libutil := -I $(d)/unix +endif diff --git a/src/libutil/tests/local.mk b/src/libutil/tests/local.mk index 167915439fd0..5202db98e4db 100644 --- a/src/libutil/tests/local.mk +++ b/src/libutil/tests/local.mk @@ -22,7 +22,7 @@ libutil-tests_INSTALL_DIR := libutil-tests_SOURCES := $(wildcard $(d)/*.cc) -libutil-tests_CXXFLAGS += -I src/libutil +libutil-tests_CXXFLAGS += $(INCLUDE_libutil) libutil-tests_LIBS = libutil diff --git a/src/nix/local.mk b/src/nix/local.mk index 57f8259c45ee..dfa468f4daa4 100644 --- a/src/nix/local.mk +++ b/src/nix/local.mk @@ -14,7 +14,7 @@ nix_SOURCES := \ $(wildcard src/nix-instantiate/*.cc) \ $(wildcard src/nix-store/*.cc) \ -nix_CXXFLAGS += -I src/libutil -I src/libstore -I src/libfetchers -I src/libexpr -I src/libmain -I src/libcmd -I doc/manual +nix_CXXFLAGS += $(INCLUDE_libutil) $(INCLUDE_libstore) -I src/libfetchers -I src/libexpr -I src/libmain -I src/libcmd -I doc/manual nix_LIBS = libexpr libmain libfetchers libstore libutil libcmd diff --git a/src/resolve-system-dependencies/local.mk b/src/resolve-system-dependencies/local.mk index fc48a8417964..f28fdab3b4d5 100644 --- a/src/resolve-system-dependencies/local.mk +++ b/src/resolve-system-dependencies/local.mk @@ -6,7 +6,7 @@ resolve-system-dependencies_DIR := $(d) resolve-system-dependencies_INSTALL_DIR := $(libexecdir)/nix -resolve-system-dependencies_CXXFLAGS += -I src/libutil -I src/libstore -I src/libmain +resolve-system-dependencies_CXXFLAGS += $(INCLUDE_libutil) $(INCLUDE_libstore) -I src/libmain resolve-system-dependencies_LIBS := libstore libmain libutil diff --git a/tests/functional/plugins/local.mk b/tests/functional/plugins/local.mk index 40350aa96ab8..ee04d693186c 100644 --- a/tests/functional/plugins/local.mk +++ b/tests/functional/plugins/local.mk @@ -8,4 +8,4 @@ libplugintest_ALLOW_UNDEFINED := 1 libplugintest_EXCLUDE_FROM_LIBRARY_LIST := 1 -libplugintest_CXXFLAGS := -I src/libutil -I src/libstore -I src/libexpr -I src/libfetchers +libplugintest_CXXFLAGS := $(INCLUDE_libutil) $(INCLUDE_libstore) -I src/libexpr -I src/libfetchers diff --git a/tests/functional/test-libstoreconsumer/local.mk b/tests/functional/test-libstoreconsumer/local.mk index edc14072305b..d5a610fab3e5 100644 --- a/tests/functional/test-libstoreconsumer/local.mk +++ b/tests/functional/test-libstoreconsumer/local.mk @@ -8,7 +8,7 @@ test-libstoreconsumer_INSTALL_DIR := test-libstoreconsumer_SOURCES := \ $(wildcard $(d)/*.cc) \ -test-libstoreconsumer_CXXFLAGS += -I src/libutil -I src/libstore +test-libstoreconsumer_CXXFLAGS += $(INCLUDE_libutil) $(INCLUDE_libstore) test-libstoreconsumer_LIBS = libstore libutil