Skip to content

Commit c717aab

Browse files
committed
Restructure makefile and add install target
1 parent e22ef49 commit c717aab

7 files changed

Lines changed: 127 additions & 52 deletions

File tree

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
/doc/
22
/build/
3+
/Makefile
4+
/config.stamp

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ install:
1010
- sudo apt-get install rust-nightly
1111
before_script:
1212
- ./travis/setup.sh
13+
- ./configure
1314
script:
1415
- make all check doc
1516
after_success:

Makefile

Lines changed: 0 additions & 50 deletions
This file was deleted.

Makefile.in

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
export RUSTC = rustc
2+
RUSTDOC = rustdoc
3+
export RUSTFLAGS = -O -Z debug-info
4+
BUILDDIR = build
5+
INSTALL_DIR = %PREFIX%
6+
7+
###############################################################################
8+
# Reconfiguration
9+
###############################################################################
10+
CONFIGURE_ARGS = %CONFIGURE_ARGS%
11+
12+
NEED_GIT_RECONFIG = $(shell git submodule status | grep -c '^\(+|-\)')
13+
14+
ifeq ($(NEED_GIT_RECONFIG),0)
15+
else
16+
.PHONY: config.stamp
17+
endif
18+
19+
Makefile: config.stamp
20+
21+
config.stamp: configure Makefile.in
22+
./configure $(CONFIGURE_ARGS)
23+
24+
###############################################################################
25+
# Dependencies
26+
###############################################################################
27+
PHF_DIR = submodules/rust-phf
28+
PHF = $(foreach file,$(shell $(MAKE) -s -C $(PHF_DIR) print-targets),$(PHF_DIR)/$(file))
29+
OPENSSL_DIR = submodules/rust-openssl
30+
OPENSSL = $(OPENSSL_DIR)/$(shell $(MAKE) -s -C $(OPENSSL_DIR) print-target)
31+
32+
$(PHF): config.stamp
33+
$(MAKE) -C $(PHF_DIR)
34+
touch $(PHF)
35+
36+
$(OPENSSL): config.stamp
37+
$(MAKE) -C $(OPENSSL_DIR)
38+
touch $(OPENSSL)
39+
40+
###############################################################################
41+
# Main targets
42+
###############################################################################
43+
POSTGRES_LIB_FILE = lib.rs
44+
POSTGRES_LIB = $(BUILDDIR)/$(shell $(RUSTC) --crate-file-name $(POSTGRES_LIB_FILE))
45+
POSTGRES_TEST = $(BUILDDIR)/$(shell $(RUSTC) --test --crate-file-name $(POSTGRES_LIB_FILE))
46+
47+
POSTGRES_LIB_DEPS = $(BUILDDIR)/postgres.d
48+
POSTGRES_TEST_DEPS = $(BUILDDIR)/postgres_test.d
49+
50+
LINK_ARGS = -L $(dir $(OPENSSL)) $(foreach file,$(PHF),-L $(dir $(file)))
51+
52+
-include $(POSTGRES_LIB_DEPS)
53+
-include $(POSTGRES_TEST_DEPS)
54+
55+
$(BUILDDIR):
56+
mkdir -p $@
57+
58+
$(POSTGRES_LIB): $(POSTGRES_LIB_FILE) $(PHF) $(OPENSSL) | $(BUILDDIR)
59+
$(RUSTC) $(RUSTFLAGS) $(LINK_ARGS) --dep-info $(POSTGRES_LIB_DEPS) \
60+
--out-dir $(@D) $<
61+
62+
$(POSTGRES_TEST): $(POSTGRES_LIB_FILE) $(PHF) $(OPENSSL) | $(BUILDDIR)
63+
$(RUSTC) $(RUSTFLAGS) $(LINK_ARGS) --dep-info $(POSTGRES_TEST_DEPS) \
64+
--out-dir $(@D) --test $<
65+
66+
all: $(POSTGRES_LIB)
67+
68+
.DEFAULT_GOAL := all
69+
.PHONY: all
70+
71+
###############################################################################
72+
# Utility
73+
###############################################################################
74+
75+
check: $(POSTGRES_TEST)
76+
$(POSTGRES_TEST)
77+
78+
clean:
79+
rm -rf $(BUILDDIR)
80+
81+
clean-deps:
82+
$(MAKE) -C $(PHF_DIR) clean
83+
$(MAKE) -C $(OPENSSL_DIR) clean
84+
85+
doc: $(OPENSSL) $(PHF)
86+
$(RUSTDOC) $(LINK_ARGS) $(POSTGRES_LIB_FILE)
87+
88+
install: $(POSTGRES_LIB)
89+
$(MAKE) -C $(PHF_DIR) install INSTALL_DIR=$(abspath $(INSTALL_DIR))
90+
$(MAKE) -C $(PHF_DIR) install INSTALL_DIR=$(abspath $(INSTALL_DIR))
91+
install $(POSTGRES_LIB) $(INSTALL_DIR)
92+
93+
.PHONY: check clean doc install

configure

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#!/bin/bash
2+
3+
set -e
4+
5+
TEMP=`getopt -o "" --long prefix: -n "$0" -- "$@"`
6+
CONFIGURE_ARGS=$@
7+
8+
if [ $? != 0 ]; then exit 1; fi
9+
10+
eval set -- "$TEMP"
11+
12+
PREFIX=/usr/lib
13+
14+
while true ; do
15+
case "$1" in
16+
--prefix) PREFIX=$2; shift 2;;
17+
--) shift; break;;
18+
esac
19+
done
20+
21+
git submodule update --init
22+
./submodules/rust-phf/configure
23+
./submodules/rust-openssl/configure
24+
25+
sed -e "s|%PREFIX%|$PREFIX|" \
26+
-e "s|%CONFIGURE_ARGS%|$CONFIGURE_ARGS|" \
27+
< Makefile.in > Makefile
28+
29+
touch config.stamp

submodules/rust-openssl

Submodule rust-openssl updated from 37240b5 to 22e687d

submodules/rust-phf

Submodule rust-phf updated from 5230821 to 5149d97

0 commit comments

Comments
 (0)