Restructure makefile and add install target

This commit is contained in:
Steven Fackler 2014-01-20 22:23:57 -08:00
parent e22ef497a7
commit c717aabe22
7 changed files with 127 additions and 52 deletions

2
.gitignore vendored
View File

@ -1,2 +1,4 @@
/doc/
/build/
/Makefile
/config.stamp

View File

@ -10,6 +10,7 @@ install:
- sudo apt-get install rust-nightly
before_script:
- ./travis/setup.sh
- ./configure
script:
- make all check doc
after_success:

View File

@ -1,50 +0,0 @@
export RUSTC = rustc
BUILDDIR = build
export RUSTFLAGS = -O -Z debug-info
POSTGRES_LIB = lib.rs
POSTGRES = $(BUILDDIR)/$(shell $(RUSTC) --crate-file-name $(POSTGRES_LIB))
POSTGRES_TEST = $(BUILDDIR)/$(shell $(RUSTC) --test --crate-file-name $(POSTGRES_LIB))
OPENSSL_DIR = submodules/rust-openssl
OPENSSL = $(OPENSSL_DIR)/$(shell $(MAKE) -s -C $(OPENSSL_DIR) print-target)
PHF_DIR = submodules/rust-phf
PHF = $(PHF_DIR)/$(shell $(MAKE) -s -C $(PHF_DIR) print-targets)
LINK_ARGS = -L $(dir $(OPENSSL)) $(foreach file,$(PHF),-L $(dir $(file)))
all: $(POSTGRES)
-include $(BUILDDIR)/postgres.d
-include $(BUILDDIR)/postgres_test.d
$(BUILDDIR):
mkdir -p $@
$(BUILDDIR)/submodule-trigger: submodules/submodule-trigger | $(BUILDDIR)
git submodule init
git submodule update
touch $@
$(OPENSSL): $(BUILDDIR)/submodule-trigger | $(BUILDDIR)
$(MAKE) -C $(OPENSSL_DIR)
$(PHF): $(BUILDDIR)/submodule-trigger | $(BUILDDIR)
$(MAKE) -C $(PHF_DIR)
$(POSTGRES): $(POSTGRES_LIB) $(OPENSSL) $(PHF) | $(BUILDDIR)
$(RUSTC) $(RUSTFLAGS) --dep-info $(@D)/postgres.d --out-dir $(@D) \
$(LINK_ARGS) $<
$(POSTGRES_TEST): $(POSTGRES_LIB) $(OPENSSL) $(PHF) | $(BUILDDIR)
$(RUSTC) $(RUSTFLAGS) --dep-info $(@D)/postgres_test.d --out-dir $(@D) \
$(LINK_ARGS) --test $<
check: $(POSTGRES_TEST)
$<
clean:
rm -rf $(BUILDDIR)
doc: $(OPENSSL) $(PHF)
rustdoc $(LINK_ARGS) $(POSTGRES_LIB)
.PHONY: all check clean

93
Makefile.in Normal file
View File

@ -0,0 +1,93 @@
export RUSTC = rustc
RUSTDOC = rustdoc
export RUSTFLAGS = -O -Z debug-info
BUILDDIR = build
INSTALL_DIR = %PREFIX%
###############################################################################
# Reconfiguration
###############################################################################
CONFIGURE_ARGS = %CONFIGURE_ARGS%
NEED_GIT_RECONFIG = $(shell git submodule status | grep -c '^\(+|-\)')
ifeq ($(NEED_GIT_RECONFIG),0)
else
.PHONY: config.stamp
endif
Makefile: config.stamp
config.stamp: configure Makefile.in
./configure $(CONFIGURE_ARGS)
###############################################################################
# Dependencies
###############################################################################
PHF_DIR = submodules/rust-phf
PHF = $(foreach file,$(shell $(MAKE) -s -C $(PHF_DIR) print-targets),$(PHF_DIR)/$(file))
OPENSSL_DIR = submodules/rust-openssl
OPENSSL = $(OPENSSL_DIR)/$(shell $(MAKE) -s -C $(OPENSSL_DIR) print-target)
$(PHF): config.stamp
$(MAKE) -C $(PHF_DIR)
touch $(PHF)
$(OPENSSL): config.stamp
$(MAKE) -C $(OPENSSL_DIR)
touch $(OPENSSL)
###############################################################################
# Main targets
###############################################################################
POSTGRES_LIB_FILE = lib.rs
POSTGRES_LIB = $(BUILDDIR)/$(shell $(RUSTC) --crate-file-name $(POSTGRES_LIB_FILE))
POSTGRES_TEST = $(BUILDDIR)/$(shell $(RUSTC) --test --crate-file-name $(POSTGRES_LIB_FILE))
POSTGRES_LIB_DEPS = $(BUILDDIR)/postgres.d
POSTGRES_TEST_DEPS = $(BUILDDIR)/postgres_test.d
LINK_ARGS = -L $(dir $(OPENSSL)) $(foreach file,$(PHF),-L $(dir $(file)))
-include $(POSTGRES_LIB_DEPS)
-include $(POSTGRES_TEST_DEPS)
$(BUILDDIR):
mkdir -p $@
$(POSTGRES_LIB): $(POSTGRES_LIB_FILE) $(PHF) $(OPENSSL) | $(BUILDDIR)
$(RUSTC) $(RUSTFLAGS) $(LINK_ARGS) --dep-info $(POSTGRES_LIB_DEPS) \
--out-dir $(@D) $<
$(POSTGRES_TEST): $(POSTGRES_LIB_FILE) $(PHF) $(OPENSSL) | $(BUILDDIR)
$(RUSTC) $(RUSTFLAGS) $(LINK_ARGS) --dep-info $(POSTGRES_TEST_DEPS) \
--out-dir $(@D) --test $<
all: $(POSTGRES_LIB)
.DEFAULT_GOAL := all
.PHONY: all
###############################################################################
# Utility
###############################################################################
check: $(POSTGRES_TEST)
$(POSTGRES_TEST)
clean:
rm -rf $(BUILDDIR)
clean-deps:
$(MAKE) -C $(PHF_DIR) clean
$(MAKE) -C $(OPENSSL_DIR) clean
doc: $(OPENSSL) $(PHF)
$(RUSTDOC) $(LINK_ARGS) $(POSTGRES_LIB_FILE)
install: $(POSTGRES_LIB)
$(MAKE) -C $(PHF_DIR) install INSTALL_DIR=$(abspath $(INSTALL_DIR))
$(MAKE) -C $(PHF_DIR) install INSTALL_DIR=$(abspath $(INSTALL_DIR))
install $(POSTGRES_LIB) $(INSTALL_DIR)
.PHONY: check clean doc install

29
configure vendored Executable file
View File

@ -0,0 +1,29 @@
#!/bin/bash
set -e
TEMP=`getopt -o "" --long prefix: -n "$0" -- "$@"`
CONFIGURE_ARGS=$@
if [ $? != 0 ]; then exit 1; fi
eval set -- "$TEMP"
PREFIX=/usr/lib
while true ; do
case "$1" in
--prefix) PREFIX=$2; shift 2;;
--) shift; break;;
esac
done
git submodule update --init
./submodules/rust-phf/configure
./submodules/rust-openssl/configure
sed -e "s|%PREFIX%|$PREFIX|" \
-e "s|%CONFIGURE_ARGS%|$CONFIGURE_ARGS|" \
< Makefile.in > Makefile
touch config.stamp

@ -1 +1 @@
Subproject commit 37240b51f5c45f6d585b6ae0406eff6802dd6c17
Subproject commit 22e687d80163def8a7cec28a9fd23a522105272a

@ -1 +1 @@
Subproject commit 52308219d41adc8fb8a8326b03bffda8f0a20ba3
Subproject commit 5149d97ea8859449edff5bd0248cddc5edbdc5a1