diff --git a/.gitignore b/.gitignore index 21285183..cff0f4c0 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,4 @@ /doc/ /build/ +/Makefile +/config.stamp diff --git a/.travis.yml b/.travis.yml index 4bad3895..737a55c2 100644 --- a/.travis.yml +++ b/.travis.yml @@ -10,6 +10,7 @@ install: - sudo apt-get install rust-nightly before_script: - ./travis/setup.sh + - ./configure script: - make all check doc after_success: diff --git a/Makefile b/Makefile deleted file mode 100644 index b6abf7ac..00000000 --- a/Makefile +++ /dev/null @@ -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 diff --git a/Makefile.in b/Makefile.in new file mode 100644 index 00000000..18c08195 --- /dev/null +++ b/Makefile.in @@ -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 diff --git a/configure b/configure new file mode 100755 index 00000000..472ffec4 --- /dev/null +++ b/configure @@ -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 diff --git a/submodules/rust-openssl b/submodules/rust-openssl index 37240b51..22e687d8 160000 --- a/submodules/rust-openssl +++ b/submodules/rust-openssl @@ -1 +1 @@ -Subproject commit 37240b51f5c45f6d585b6ae0406eff6802dd6c17 +Subproject commit 22e687d80163def8a7cec28a9fd23a522105272a diff --git a/submodules/rust-phf b/submodules/rust-phf index 52308219..5149d97e 160000 --- a/submodules/rust-phf +++ b/submodules/rust-phf @@ -1 +1 @@ -Subproject commit 52308219d41adc8fb8a8326b03bffda8f0a20ba3 +Subproject commit 5149d97ea8859449edff5bd0248cddc5edbdc5a1