Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use buildprefix in a few more places #9465

Merged
merged 1 commit into from
Nov 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
-include Makefile.config
clean-files += Makefile.config
include mk/build-dir.mk

-include $(buildprefix)Makefile.config
clean-files += $(buildprefix)Makefile.config
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems circular. E.g. prefix is set in Makefile.config and mk/directories.mk depends on the value of prefix, so Makefile.config needs to be included before mk/directories.mk.

Maybe only the setting of buildprefix should be moved to before -include $(buildprefix)Makefile.config?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it worked because the way non-:= definitions are "lazy", but I do prefer your way because it is easier to understand. Done!


ifeq ($(ENABLE_BUILD), yes)
makefiles = \
Expand Down
25 changes: 25 additions & 0 deletions doc/manual/src/contributing/hacking.md
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,31 @@ $ nix build .#packages.aarch64-linux.default
Cross-compiled builds are available for ARMv6 (`armv6l-linux`) and ARMv7 (`armv7l-linux`).
Add more [system types](#system-type) to `crossSystems` in `flake.nix` to bootstrap Nix on unsupported platforms.

### Building for multiple platforms at once

It is useful to perform multiple cross and native builds on the same source tree,
for example to ensure that better support for one platform doesn't break the build for another.
In order to facilitate this, Nix has some support for being built out of tree – that is, placing build artefacts in a different directory than the source code:

1. Create a directory for the build, e.g.

```bash
mkdir build
```

2. Run the configure script from that directory, e.g.

```bash
cd build
../configure <configure flags>
```

3. Run make from the source directory, but with the build directory specified, e.g.

```bash
make builddir=build <make flags>
```

## System type

Nix uses a string with he following format to identify the *system type* or *platform* it runs on:
Expand Down
10 changes: 10 additions & 0 deletions mk/build-dir.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Initialise support for build directories.
builddir ?=

ifdef builddir
buildprefix = $(builddir)/
buildprefixrel = $(builddir)
else
buildprefix =
buildprefixrel = .
endif
11 changes: 11 additions & 0 deletions mk/install-dirs.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Default installation paths.
prefix ?= /usr/local
libdir ?= $(prefix)/lib
bindir ?= $(prefix)/bin
libexecdir ?= $(prefix)/libexec
datadir ?= $(prefix)/share
localstatedir ?= $(prefix)/var
sysconfdir ?= $(prefix)/etc
mandir ?= $(prefix)/share/man

DESTDIR ?=
25 changes: 3 additions & 22 deletions mk/lib.mk
Original file line number Diff line number Diff line change
Expand Up @@ -43,27 +43,6 @@ define newline
endef


# Default installation paths.
prefix ?= /usr/local
libdir ?= $(prefix)/lib
bindir ?= $(prefix)/bin
libexecdir ?= $(prefix)/libexec
datadir ?= $(prefix)/share
localstatedir ?= $(prefix)/var
sysconfdir ?= $(prefix)/etc
mandir ?= $(prefix)/share/man


# Initialise support for build directories.
builddir ?=

ifdef builddir
buildprefix = $(builddir)/
else
buildprefix =
endif


# Pass -fPIC if we're building dynamic libraries.
BUILD_SHARED_LIBS ?= 1

Expand Down Expand Up @@ -94,6 +73,8 @@ ifeq ($(BUILD_DEBUG), 1)
endif


include mk/build-dir.mk
include mk/install-dirs.mk
include mk/functions.mk
include mk/tracing.mk
include mk/clean.mk
Expand All @@ -112,7 +93,7 @@ define include-sub-makefile
include $(1)
endef

$(foreach mf, $(makefiles), $(eval $(call include-sub-makefile, $(mf))))
$(foreach mf, $(makefiles), $(eval $(call include-sub-makefile,$(mf))))


# Instantiate stuff.
Expand Down
8 changes: 4 additions & 4 deletions mk/templates.mk
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ endef

ifneq ($(MAKECMDGOALS), clean)

%.h: %.h.in
$(trace-gen) rm -f $@ && ./config.status --quiet --header=$@
$(buildprefix)%.h: %.h.in
$(trace-gen) rm -f $@ && cd $(buildprefixrel) && ./config.status --quiet --header=$(@:$(buildprefix)%=%)

%: %.in
$(trace-gen) rm -f $@ && ./config.status --quiet --file=$@
$(buildprefix)%: %.in
$(trace-gen) rm -f $@ && cd $(buildprefixrel) && ./config.status --quiet --file=$(@:$(buildprefix)%=%)

endif
2 changes: 1 addition & 1 deletion src/libcmd/local.mk
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ libcmd_LDFLAGS = $(EDITLINE_LIBS) $(LOWDOWN_LIBS) -pthread

libcmd_LIBS = libstore libutil libexpr libmain libfetchers

$(eval $(call install-file-in, $(d)/nix-cmd.pc, $(libdir)/pkgconfig, 0644))
$(eval $(call install-file-in, $(buildprefix)$(d)/nix-cmd.pc, $(libdir)/pkgconfig, 0644))
4 changes: 2 additions & 2 deletions src/libexpr/local.mk
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ $(d)/lexer-tab.cc $(d)/lexer-tab.hh: $(d)/lexer.l

clean-files += $(d)/parser-tab.cc $(d)/parser-tab.hh $(d)/lexer-tab.cc $(d)/lexer-tab.hh

$(eval $(call install-file-in, $(d)/nix-expr.pc, $(libdir)/pkgconfig, 0644))
$(eval $(call install-file-in, $(buildprefix)$(d)/nix-expr.pc, $(libdir)/pkgconfig, 0644))

$(foreach i, $(wildcard src/libexpr/value/*.hh), \
$(eval $(call install-file-in, $(i), $(includedir)/nix/value, 0644)))
Expand All @@ -47,4 +47,4 @@ $(d)/primops.cc: $(d)/imported-drv-to-derivation.nix.gen.hh

$(d)/eval.cc: $(d)/primops/derivation.nix.gen.hh $(d)/fetchurl.nix.gen.hh $(d)/flake/call-flake.nix.gen.hh

src/libexpr/primops/fromTOML.o: ERROR_SWITCH_ENUM =
$(buildprefix)src/libexpr/primops/fromTOML.o: ERROR_SWITCH_ENUM =
2 changes: 1 addition & 1 deletion src/libmain/local.mk
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ libmain_LIBS = libstore libutil

libmain_ALLOW_UNDEFINED = 1

$(eval $(call install-file-in, $(d)/nix-main.pc, $(libdir)/pkgconfig, 0644))
$(eval $(call install-file-in, $(buildprefix)$(d)/nix-main.pc, $(libdir)/pkgconfig, 0644))
2 changes: 1 addition & 1 deletion src/libstore/local.mk
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ $(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))
$(eval $(call install-file-in, $(buildprefix)$(d)/nix-store.pc, $(libdir)/pkgconfig, 0644))

$(foreach i, $(wildcard src/libstore/builtins/*.hh), \
$(eval $(call install-file-in, $(i), $(includedir)/nix/builtins, 0644)))
Expand Down
4 changes: 2 additions & 2 deletions tests/functional/local.mk
Original file line number Diff line number Diff line change
Expand Up @@ -140,9 +140,9 @@ ifeq ($(ENABLE_BUILD), yes)
endif

$(d)/test-libstoreconsumer.sh.test $(d)/test-libstoreconsumer.sh.test-debug: \
$(d)/test-libstoreconsumer/test-libstoreconsumer
$(buildprefix)$(d)/test-libstoreconsumer/test-libstoreconsumer
$(d)/plugins.sh.test $(d)/plugins.sh.test-debug: \
$(d)/plugins/libplugintest.$(SO_EXT)
$(buildprefix)$(d)/plugins/libplugintest.$(SO_EXT)

install-tests += $(foreach x, $(nix_tests), $(d)/$(x))

Expand Down
Loading