build: support out of tree builds

Invoking make with builddir_name=/path/to/dir builds libuv in the
designated directory.
This commit is contained in:
Ben Noordhuis 2013-01-29 16:12:12 +01:00
parent 01fe4e73a6
commit 75dea933eb
5 changed files with 210 additions and 62 deletions

13
.gitignore vendored
View File

@ -7,6 +7,7 @@
*.suo *.suo
core core
vgcore.* vgcore.*
.buildstamp
/libuv.so /libuv.so
/libuv.dylib /libuv.dylib
@ -14,12 +15,12 @@ vgcore.*
/out/ /out/
/build/gyp /build/gyp
/test/run-tests /run-tests
/test/run-tests.exe /run-tests.exe
/test/run-tests.dSYM /run-tests.dSYM
/test/run-benchmarks /run-benchmarks
/test/run-benchmarks.exe /run-benchmarks.exe
/test/run-benchmarks.dSYM /run-benchmarks.dSYM
*.sln *.sln
*.vcproj *.vcproj

View File

@ -18,47 +18,36 @@
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
# IN THE SOFTWARE. # IN THE SOFTWARE.
OS ?= $(shell sh -c 'uname -s | tr "[A-Z]" "[a-z]"') SRCDIR ?= $(CURDIR)
CPPFLAGS += -Iinclude -Iinclude/uv-private ifeq (,$(builddir_name))
VPATH := $(SRCDIR)
include $(SRCDIR)/build.mk
else # Out of tree build.
# Drop all built-in rules.
.SUFFIXES:
.PHONY: $(builddir_name)
$(builddir_name): $(builddir_name)/.buildstamp
$(MAKE) -C $@ -f $(CURDIR)/Makefile $(MAKECMDGOALS) \
SRCDIR=$(CURDIR) builddir_name=
$(builddir_name)/.buildstamp:
mkdir -p $(dir $@)
touch $@
# Add no-op rules for Makefiles to stop make from trying to rebuild them.
Makefile:: ;
%.mk:: ;
# Turn everything else into a no-op rule that depends on the build directory.
%:: $(builddir_name) ;
.PHONY: clean
clean:
$(RM) -fr $(builddir_name)
ifeq (darwin,$(OS))
SOEXT = dylib
else
SOEXT = so
endif endif
ifneq (,$(findstring mingw,$(OS)))
include config-mingw.mk
else
include config-unix.mk
endif
TESTS=test/blackhole-server.c test/echo-server.c test/test-*.c
BENCHMARKS=test/blackhole-server.c test/echo-server.c test/dns-server.c test/benchmark-*.c
all: libuv.a
test/run-tests$(E): test/run-tests.c test/runner.c $(RUNNER_SRC) $(TESTS) libuv.$(SOEXT)
$(CC) $(CPPFLAGS) $(RUNNER_CFLAGS) -o $@ $^ $(RUNNER_LIBS) $(RUNNER_LDFLAGS)
test/run-benchmarks$(E): test/run-benchmarks.c test/runner.c $(RUNNER_SRC) $(BENCHMARKS) libuv.$(SOEXT)
$(CC) $(CPPFLAGS) $(RUNNER_CFLAGS) -o $@ $^ $(RUNNER_LIBS) $(RUNNER_LDFLAGS)
test/echo.o: test/echo.c test/echo.h
.PHONY: clean clean-platform distclean distclean-platform test bench
test: test/run-tests$(E)
$<
bench: test/run-benchmarks$(E)
$<
clean: clean-platform
$(RM) -f *.a *.so test/run-tests$(E) test/run-benchmarks$(E)
distclean: distclean-platform
$(RM) -f *.a *.so test/run-tests$(E) test/run-benchmarks$(E)

View File

@ -66,6 +66,10 @@ MinGW users should run this instead:
make OS=mingw make OS=mingw
Out-of-tree builds are supported:
make builddir_name=/path/to/builddir
To build with Visual Studio run the vcbuild.bat file which will To build with Visual Studio run the vcbuild.bat file which will
checkout the GYP code into build/gyp and generate the uv.sln and checkout the GYP code into build/gyp and generate the uv.sln and
related files. related files.

163
build.mk Normal file
View File

@ -0,0 +1,163 @@
# Copyright Joyent, Inc. and other Node contributors. All rights reserved.
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to
# deal in the Software without restriction, including without limitation the
# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
# sell copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
# IN THE SOFTWARE.
OS ?= $(shell sh -c 'uname -s | tr "[A-Z]" "[a-z]"')
CPPFLAGS += -I$(SRCDIR)/include -I$(SRCDIR)/include/uv-private
ifeq (darwin,$(OS))
SOEXT = dylib
else
SOEXT = so
endif
ifneq (,$(findstring mingw,$(OS)))
include $(SRCDIR)/config-mingw.mk
else
include $(SRCDIR)/config-unix.mk
endif
BENCHMARKS= \
test/benchmark-async-pummel.o \
test/benchmark-async.o \
test/benchmark-fs-stat.o \
test/benchmark-getaddrinfo.o \
test/benchmark-loop-count.o \
test/benchmark-million-async.o \
test/benchmark-million-timers.o \
test/benchmark-multi-accept.o \
test/benchmark-ping-pongs.o \
test/benchmark-pound.o \
test/benchmark-pump.o \
test/benchmark-sizes.o \
test/benchmark-spawn.o \
test/benchmark-tcp-write-batch.o \
test/benchmark-thread.o \
test/benchmark-udp-pummel.o \
test/blackhole-server.o \
test/dns-server.o \
test/echo-server.o \
TESTS= \
test/blackhole-server.o \
test/dns-server.o \
test/echo-server.o \
test/test-active.o \
test/test-async.o \
test/test-barrier.o \
test/test-callback-order.o \
test/test-callback-stack.o \
test/test-condvar.o \
test/test-connection-fail.o \
test/test-cwd-and-chdir.o \
test/test-delayed-accept.o \
test/test-dlerror.o \
test/test-embed.o \
test/test-error.o \
test/test-fail-always.o \
test/test-fs.o \
test/test-fs-event.o \
test/test-fs-poll.o \
test/test-getaddrinfo.o \
test/test-get-currentexe.o \
test/test-get-loadavg.o \
test/test-get-memory.o \
test/test-getsockname.o \
test/test-hrtime.o \
test/test-idle.o \
test/test-ipc.o \
test/test-ipc-send-recv.o \
test/test-loop-handles.o \
test/test-multiple-listen.o \
test/test-mutexes.o \
test/test-pass-always.o \
test/test-ping-pong.o \
test/test-pipe-bind-error.o \
test/test-pipe-connect-error.o \
test/test-platform-output.o \
test/test-poll.o \
test/test-poll-close.o \
test/test-process-title.o \
test/test-ref.o \
test/test-run-nowait.o \
test/test-run-once.o \
test/test-semaphore.o \
test/test-shutdown-close.o \
test/test-shutdown-eof.o \
test/test-signal.o \
test/test-signal-multiple-loops.o \
test/test-spawn.o \
test/test-stdio-over-pipes.o \
test/test-tcp-bind6-error.o \
test/test-tcp-bind-error.o \
test/test-tcp-close.o \
test/test-tcp-close-while-connecting.o \
test/test-tcp-connect6-error.o \
test/test-tcp-connect-error-after-write.o \
test/test-tcp-connect-error.o \
test/test-tcp-connect-timeout.o \
test/test-tcp-flags.o \
test/test-tcp-open.o \
test/test-tcp-read-stop.o \
test/test-tcp-shutdown-after-write.o \
test/test-tcp-unexpected-read.o \
test/test-tcp-writealot.o \
test/test-tcp-write-to-half-open-connection.o \
test/test-thread.o \
test/test-threadpool.o \
test/test-threadpool-cancel.o \
test/test-timer-again.o \
test/test-timer.o \
test/test-tty.o \
test/test-udp-dgram-too-big.o \
test/test-udp-ipv6.o \
test/test-udp-multicast-join.o \
test/test-udp-multicast-ttl.o \
test/test-udp-open.o \
test/test-udp-options.o \
test/test-udp-send-and-recv.o \
test/test-util.o \
test/test-walk-handles.o \
all: libuv.a
run-tests$(E): test/run-tests.o test/runner.o $(RUNNER_SRC) $(TESTS) libuv.$(SOEXT)
$(CC) $(CPPFLAGS) $(RUNNER_CFLAGS) -o $@ $^ $(RUNNER_LIBS) $(RUNNER_LDFLAGS)
run-benchmarks$(E): test/run-benchmarks.o test/runner.o $(RUNNER_SRC) $(BENCHMARKS) libuv.$(SOEXT)
$(CC) $(CPPFLAGS) $(RUNNER_CFLAGS) -o $@ $^ $(RUNNER_LIBS) $(RUNNER_LDFLAGS)
test/echo.o: test/echo.c test/echo.h
.PHONY: clean clean-platform distclean distclean-platform test bench
test: run-tests$(E)
$(CURDIR)/$<
bench: run-benchmarks$(E)
$(CURDIR)/$<
clean: clean-platform
$(RM) -f *.a *.so test/run-tests$(E) test/run-benchmarks$(E)
distclean: distclean-platform
$(RM) -f *.a *.so test/run-tests$(E) test/run-benchmarks$(E)

View File

@ -21,15 +21,15 @@
E= E=
CSTDFLAG=--std=c89 -pedantic -Wall -Wextra -Wno-unused-parameter CSTDFLAG=--std=c89 -pedantic -Wall -Wextra -Wno-unused-parameter
CFLAGS += -g CFLAGS += -g
CPPFLAGS += -Isrc CPPFLAGS += -I$(SRCDIR)/src
LDFLAGS=-lm LDFLAGS=-lm
CPPFLAGS += -D_LARGEFILE_SOURCE CPPFLAGS += -D_LARGEFILE_SOURCE
CPPFLAGS += -D_FILE_OFFSET_BITS=64 CPPFLAGS += -D_FILE_OFFSET_BITS=64
RUNNER_SRC=test/runner-unix.c RUNNER_SRC=test/runner-unix.c
RUNNER_CFLAGS=$(CFLAGS) -Itest RUNNER_CFLAGS=$(CFLAGS) -I$(SRCDIR)/test
RUNNER_LDFLAGS=-L"$(PWD)" -luv -Xlinker -rpath -Xlinker "$(PWD)" RUNNER_LDFLAGS=-L"$(CURDIR)" -luv -Xlinker -rpath -Xlinker "$(CURDIR)"
OBJS += src/unix/async.o OBJS += src/unix/async.o
OBJS += src/unix/core.o OBJS += src/unix/core.o
@ -63,7 +63,7 @@ OBJS += src/unix/sunos.o
endif endif
ifeq (aix,$(OS)) ifeq (aix,$(OS))
CPPFLAGS += -Isrc/ares/config_aix -D_ALL_SOURCE -D_XOPEN_SOURCE=500 CPPFLAGS += -D_ALL_SOURCE -D_XOPEN_SOURCE=500
LDFLAGS+= -lperfstat LDFLAGS+= -lperfstat
OBJS += src/unix/aix.o OBJS += src/unix/aix.o
endif endif
@ -123,13 +123,6 @@ else
RUNNER_LDFLAGS += -pthread RUNNER_LDFLAGS += -pthread
endif endif
OBJDIR := out
ifeq ($(MAKECMDGOALS), test)
OBJDIR := $(OBJDIR)/test
endif
OBJS := $(addprefix $(OBJDIR)/,$(OBJS))
libuv.a: $(OBJS) libuv.a: $(OBJS)
$(AR) rcs $@ $^ $(AR) rcs $@ $^
@ -137,18 +130,16 @@ libuv.$(SOEXT): override CFLAGS += -fPIC
libuv.$(SOEXT): $(OBJS) libuv.$(SOEXT): $(OBJS)
$(CC) -shared -o $@ $^ $(LDFLAGS) $(CC) -shared -o $@ $^ $(LDFLAGS)
$(OBJDIR)/src/unix/%.o: src/unix/%.c include/uv.h include/uv-private/uv-unix.h src/unix/internal.h src/unix/%.o: src/unix/%.c include/uv.h include/uv-private/uv-unix.h src/unix/internal.h
@mkdir -p $(dir $@) @mkdir -p $(dir $@)
$(CC) $(CSTDFLAG) $(CPPFLAGS) $(CFLAGS) -c $< -o $@ $(CC) $(CSTDFLAG) $(CPPFLAGS) $(CFLAGS) -c $< -o $@
$(OBJDIR)/src/%.o: src/%.c include/uv.h include/uv-private/uv-unix.h src/%.o: src/%.c include/uv.h include/uv-private/uv-unix.h
@mkdir -p $(dir $@) @mkdir -p $(dir $@)
$(CC) $(CSTDFLAG) $(CPPFLAGS) $(CFLAGS) -c $< -o $@ $(CC) $(CSTDFLAG) $(CPPFLAGS) $(CFLAGS) -c $< -o $@
clean-platform: clean-platform:
-rm -rf $(OBJDIR)
-rm -f libuv.a libuv.$(SOEXT) test/run-{tests,benchmarks}.dSYM -rm -f libuv.a libuv.$(SOEXT) test/run-{tests,benchmarks}.dSYM
distclean-platform: distclean-platform:
-rm -rf $(OBJDIR)
-rm -f libuv.a libuv.$(SOEXT) test/run-{tests,benchmarks}.dSYM -rm -f libuv.a libuv.$(SOEXT) test/run-{tests,benchmarks}.dSYM