Skip to content

Commit

Permalink
Merge pull request NixOS#9736 from obsidiansystems/mingw-makefiles
Browse files Browse the repository at this point in the history
Some small Makefile improvements to prepare for Windows support
  • Loading branch information
Ericson2314 authored Jan 11, 2024
2 parents 113499d + 423484a commit 8450267
Show file tree
Hide file tree
Showing 13 changed files with 43 additions and 23 deletions.
14 changes: 14 additions & 0 deletions mk/lib.mk
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,34 @@ install-tests-groups :=

ifdef HOST_OS
HOST_KERNEL = $(firstword $(subst -, ,$(HOST_OS)))
ifeq ($(patsubst mingw%,,$(HOST_KERNEL)),)
HOST_MINGW = 1
HOST_WINDOWS = 1
endif
ifeq ($(HOST_KERNEL), cygwin)
HOST_CYGWIN = 1
HOST_WINDOWS = 1
HOST_UNIX = 1
endif
ifeq ($(patsubst darwin%,,$(HOST_KERNEL)),)
HOST_DARWIN = 1
HOST_UNIX = 1
endif
ifeq ($(patsubst freebsd%,,$(HOST_KERNEL)),)
HOST_FREEBSD = 1
HOST_UNIX = 1
endif
ifeq ($(patsubst netbsd%,,$(HOST_KERNEL)),)
HOST_NETBSD = 1
HOST_UNIX = 1
endif
ifeq ($(HOST_KERNEL), linux)
HOST_LINUX = 1
HOST_UNIX = 1
endif
ifeq ($(patsubst solaris%,,$(HOST_KERNEL)),)
HOST_SOLARIS = 1
HOST_UNIX = 1
endif
endif

Expand Down
6 changes: 6 additions & 0 deletions mk/libraries.mk
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@ else
endif
endif

ifdef HOST_UNIX
THREAD_LDFLAGS = -pthread
else
THREAD_LDFLAGS =
endif

# Build a library with symbolic name $(1). The library is defined by
# various variables prefixed by ‘$(1)_’:
#
Expand Down
2 changes: 1 addition & 1 deletion src/libcmd/local.mk
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ libcmd_SOURCES := $(wildcard $(d)/*.cc)

libcmd_CXXFLAGS += -I src/libutil -I src/libstore -I src/libexpr -I src/libmain -I src/libfetchers

libcmd_LDFLAGS = $(EDITLINE_LIBS) $(LOWDOWN_LIBS) -pthread
libcmd_LDFLAGS = $(EDITLINE_LIBS) $(LOWDOWN_LIBS) $(THREAD_LDFLAGS)

libcmd_LIBS = libstore libutil libexpr libmain libfetchers

Expand Down
4 changes: 2 additions & 2 deletions src/libexpr/local.mk
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ libexpr_CXXFLAGS += -I src/libutil -I src/libstore -I src/libfetchers -I src/lib

libexpr_LIBS = libutil libstore libfetchers

libexpr_LDFLAGS += -lboost_context -pthread
libexpr_LDFLAGS += -lboost_context $(THREAD_LDFLAGS)
ifdef HOST_LINUX
libexpr_LDFLAGS += -ldl
libexpr_LDFLAGS += -ldl
endif

# The dependency on libgc must be propagated (i.e. meaning that
Expand Down
2 changes: 1 addition & 1 deletion src/libfetchers/local.mk
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ libfetchers_SOURCES := $(wildcard $(d)/*.cc)

libfetchers_CXXFLAGS += -I src/libutil -I src/libstore

libfetchers_LDFLAGS += -pthread $(LIBGIT2_LIBS) -larchive
libfetchers_LDFLAGS += $(THREAD_LDFLAGS) $(LIBGIT2_LIBS) -larchive

libfetchers_LIBS = libutil libstore
14 changes: 7 additions & 7 deletions src/libstore/local.mk
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,23 @@ libstore_SOURCES := $(wildcard $(d)/*.cc $(d)/builtins/*.cc $(d)/build/*.cc)

libstore_LIBS = libutil

libstore_LDFLAGS += $(SQLITE3_LIBS) $(LIBCURL_LIBS) -pthread
libstore_LDFLAGS += $(SQLITE3_LIBS) $(LIBCURL_LIBS) $(THREAD_LDFLAGS)
ifdef HOST_LINUX
libstore_LDFLAGS += -ldl
endif

$(foreach file,$(libstore_FILES),$(eval $(call install-data-in,$(d)/$(file),$(datadir)/nix/sandbox)))

ifeq ($(ENABLE_S3), 1)
libstore_LDFLAGS += -laws-cpp-sdk-transfer -laws-cpp-sdk-s3 -laws-cpp-sdk-core -laws-crt-cpp
libstore_LDFLAGS += -laws-cpp-sdk-transfer -laws-cpp-sdk-s3 -laws-cpp-sdk-core -laws-crt-cpp
endif

ifdef HOST_SOLARIS
libstore_LDFLAGS += -lsocket
libstore_LDFLAGS += -lsocket
endif

ifeq ($(HAVE_SECCOMP), 1)
libstore_LDFLAGS += $(LIBSECCOMP_LIBS)
libstore_LDFLAGS += $(LIBSECCOMP_LIBS)
endif

libstore_CXXFLAGS += \
Expand All @@ -48,9 +48,9 @@ $(d)/embedded-sandbox-shell.gen.hh: $(sandbox_shell)
$(trace-gen) hexdump -v -e '1/1 "0x%x," "\n"' < $< > $@.tmp
@mv $@.tmp $@
else
ifneq ($(sandbox_shell),)
libstore_CXXFLAGS += -DSANDBOX_SHELL="\"$(sandbox_shell)\""
endif
ifneq ($(sandbox_shell),)
libstore_CXXFLAGS += -DSANDBOX_SHELL="\"$(sandbox_shell)\""
endif
endif

$(d)/local-store.cc: $(d)/schema.sql.gen.hh $(d)/ca-specific-schema.sql.gen.hh
Expand Down
4 changes: 2 additions & 2 deletions src/libutil/local.mk
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ libutil_SOURCES := $(wildcard $(d)/*.cc $(d)/signature/*.cc)

libutil_CXXFLAGS += -I src/libutil

libutil_LDFLAGS += -pthread $(LIBCURL_LIBS) $(SODIUM_LIBS) $(OPENSSL_LIBS) $(LIBBROTLI_LIBS) $(LIBARCHIVE_LIBS) $(BOOST_LDFLAGS) -lboost_context
libutil_LDFLAGS += $(THREAD_LDFLAGS) $(LIBCURL_LIBS) $(SODIUM_LIBS) $(OPENSSL_LIBS) $(LIBBROTLI_LIBS) $(LIBARCHIVE_LIBS) $(BOOST_LDFLAGS) -lboost_context

$(foreach i, $(wildcard $(d)/args/*.hh), \
$(eval $(call install-file-in, $(i), $(includedir)/nix/args, 0644)))
Expand All @@ -17,5 +17,5 @@ $(foreach i, $(wildcard $(d)/signature/*.hh), \


ifeq ($(HAVE_LIBCPUID), 1)
libutil_LDFLAGS += -lcpuid
libutil_LDFLAGS += -lcpuid
endif
2 changes: 1 addition & 1 deletion src/nix/local.mk
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ nix_CXXFLAGS += -I src/libutil -I src/libstore -I src/libfetchers -I src/libexpr

nix_LIBS = libexpr libmain libfetchers libstore libutil libcmd

nix_LDFLAGS = -pthread $(SODIUM_LIBS) $(EDITLINE_LIBS) $(BOOST_LDFLAGS) $(LOWDOWN_LIBS)
nix_LDFLAGS = $(THREAD_LDFLAGS) $(SODIUM_LIBS) $(EDITLINE_LIBS) $(BOOST_LDFLAGS) $(LOWDOWN_LIBS)

$(foreach name, \
nix-build nix-channel nix-collect-garbage nix-copy-closure nix-daemon nix-env nix-hash nix-instantiate nix-prefetch-url nix-shell nix-store, \
Expand Down
10 changes: 5 additions & 5 deletions tests/functional/local.mk
Original file line number Diff line number Diff line change
Expand Up @@ -129,15 +129,15 @@ nix_tests = \
impure-env.sh

ifeq ($(HAVE_LIBCPUID), 1)
nix_tests += compute-levels.sh
nix_tests += compute-levels.sh
endif

ifeq ($(ENABLE_BUILD), yes)
nix_tests += test-libstoreconsumer.sh
nix_tests += test-libstoreconsumer.sh

ifeq ($(BUILD_SHARED_LIBS), 1)
nix_tests += plugins.sh
endif
ifeq ($(BUILD_SHARED_LIBS), 1)
nix_tests += plugins.sh
endif
endif

$(d)/test-libstoreconsumer.sh.test $(d)/test-libstoreconsumer.sh.test-debug: \
Expand Down
2 changes: 1 addition & 1 deletion tests/functional/test-libstoreconsumer/local.mk
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ test-libstoreconsumer_CXXFLAGS += -I src/libutil -I src/libstore

test-libstoreconsumer_LIBS = libstore libutil

test-libstoreconsumer_LDFLAGS = -pthread $(SODIUM_LIBS) $(EDITLINE_LIBS) $(BOOST_LDFLAGS) $(LOWDOWN_LIBS)
test-libstoreconsumer_LDFLAGS = $(THREAD_LDFLAGS) $(SODIUM_LIBS) $(EDITLINE_LIBS) $(BOOST_LDFLAGS) $(LOWDOWN_LIBS)
2 changes: 1 addition & 1 deletion tests/unit/libexpr-support/local.mk
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@ libexpr-test-support_LIBS = \
libstore-test-support libutil-test-support \
libexpr libstore libutil

libexpr-test-support_LDFLAGS := -pthread -lrapidcheck
libexpr-test-support_LDFLAGS := $(THREAD_LDFLAGS) -lrapidcheck
2 changes: 1 addition & 1 deletion tests/unit/libstore-support/local.mk
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ libstore-test-support_LIBS = \
libutil-test-support \
libstore libutil

libstore-test-support_LDFLAGS := -pthread -lrapidcheck
libstore-test-support_LDFLAGS := $(THREAD_LDFLAGS) -lrapidcheck
2 changes: 1 addition & 1 deletion tests/unit/libutil-support/local.mk
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ libutil-test-support_CXXFLAGS += $(libutil-tests_EXTRA_INCLUDES)

libutil-test-support_LIBS = libutil

libutil-test-support_LDFLAGS := -pthread -lrapidcheck
libutil-test-support_LDFLAGS := $(THREAD_LDFLAGS) -lrapidcheck

0 comments on commit 8450267

Please sign in to comment.