Skip to content

Commit

Permalink
Add make install with support for prefix and GNU standard locations
Browse files Browse the repository at this point in the history
  • Loading branch information
attipaci committed Nov 12, 2024
1 parent f9c1158 commit c471209
Show file tree
Hide file tree
Showing 3 changed files with 140 additions and 35 deletions.
68 changes: 68 additions & 0 deletions .github/workflows/install.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
name: Test install

on:
push:
branches:
- main
paths:
- 'src/**'
- 'include/**'
- 'tools/src/**'
- 'Makefile'
- '*.mk'
- '.github/workflows/install.yml'

pull_request:
paths:
- 'src/**'
- 'include/**'
- 'tools/src/**'
- 'Makefile'
- '*.mk'
- '.github/workflows/install.yml'

jobs:

install:
runs-on: ubuntu-latest
env:
CC: gcc
XCHANGE: ../xchange
REDISX: ../redisx
SMAXLIB: ../smax-clib
steps:
- name: install doxygen
run: sudo apt-get install doxygen

- name: Check out smax-clib
uses: actions/checkout@v4

- name: Check out xchange
uses: actions/checkout@v4
with:
repository: Smithsonian/xchange
path: xchange

- name: Check out RedisX
uses: actions/checkout@v4
with:
repository: Smithsonian/redisx
path: redisx

- name: Check out smax-clib
uses: actions/checkout@v4
with:
repository: Smithsonian/smax-clib
path: smax-clib

- name: Install xchange dependency
run: sudo make -C xchange install

- name: Install RedisX dependency
run: sudo make -C redisx install

- name: Install smax-clib dependency
run: sudo make -C smax-clib shared

- name: Install smax-postgres in default location
run: sudo make install
94 changes: 59 additions & 35 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,9 @@ else
$(info WARNING! Doxygen is not available. Will skip 'dox' target)
endif

ifdef PREFIX
STAGE=$(PREFIX)/$(DESTDIR)
else
STAGE=$(DESTDIR)
endif

# For deployment, the app and documentation
.PHONY: deploy
deploy: app $(DOC_TARGETS)
.PHONY: distro
distro: app $(DOC_TARGETS)

# Build just the app
.PHONY: app
Expand Down Expand Up @@ -86,40 +80,70 @@ Doxyfile.local: Doxyfile Makefile
local-dox: README-smax-postgres.md Doxyfile.local
doxygen Doxyfile.local


# Default values for install locations
# See https://www.gnu.org/prep/standards/html_node/Directory-Variables.html
prefix ?= /usr
exec_prefix ?= $(prefix)
bindir ?= $(exec_prefix)/bin
sysconfdir ?= $(prefix)/etc
systemddir ?= $(sysconfdir)/systemd/system
datarootdir ?= $(prefix)/share
datadir ?= $(datarootdir)
mydatadir ?= $(datadir)/smax-postgres
docdir ?= $(datarootdir)/doc/smax-postgres
htmldir ?= $(docdir)/html


CONFIG := "cfg/smax-postgres.cfg"

.PHONY: install-sma
install-sma: CONFIG := "cfg/smax-postgres.cfg.sma"
install-sma: install


.PHONY: install
install: deploy
@echo "Installing under $(STAGE)."

@mkdir -p $(STAGE)/bin
@install -m 755 $(BIN)/smax-postgres $(STAGE)/bin/

@mkdir -p $(STAGE)/etc
@if [ ! -e $(PREFIX)/etc/smax-postgres.cfg ] ; then \
install -m 644 cfg/smax-postgres.cfg $(PREFIX)/etc/smax-postgres.cfg ; \
install: install-bin install-cfg install-systemd install-doc

.PHONY: install-bin
install-bin: app
@echo "installing executable under $(bindir)."
@install -d $(bindir)
@install -m 755 $(BIN)/smax-postgres $(bindir)/

.PHONY: install-cfg
@if [ ! -e $(sysconfdir)/smax-postgres.cfg ] ; then \
echo "installing configuration file under $(sysconfdir)." ; \
install -d $(sysconfdir) ; \
install -m 644 cfg/smax-postgres.cfg $(sysconfdir)/smax-postgres.cfg ; \
fi


.PHONY: install-systemd
install-systemd:
@if [ $(SYSTEMD) -ne 0 ] ; then \
mkdir -p $(STAGE)/etc/systemd/system ; \
install -m 644 smax-postgres.service $(STAGE)/etc/systemd/system/ ; \
sed -i "s:/usr/:$(STAGE):g" $(STAGE)/etc/systemd/system/smax-postgres.service ; \
echo "installing systemd unit file under $(systemddir)." ; \
mkdir -p $(systemddir) ; \
install -m 644 smax-postgres.service $(systemddir) ; \
sed -i "s:/usr/:$(prefix):g" $(systemddir)/smax-postgres.service ; \
fi

@mkdir -p $(STAGE)/share/doc/smax-postgres
@install -m 644 LICENSE $(STAGE)/share/doc/smax-postgres/
@install -m 644 README-smax-postgres.md $(STAGE)/share/doc/smax-postgres/README.md
@install -m 644 CHANGELOG.md $(STAGE)/share/doc/smax-postgres/


.PHONY: install-doc
install-doc: install-apidoc $(DOC_TARGETS)
@echo "installing docs under $(docdir)."
@install -d $(docdir)
@install -m 644 LICENSE $(docdir)
@install -m 644 README-smax-postgres.md $(docdir)/README.md
@install -m 644 CHANGELOG.md $(docdir)

.PHONY: install-apidoc
install-apidoc: $(DOC_TARGETS)
@if [ -e apidoc/html/index.html ] ; then \
mkdir -p $(STAGE)/share/doc/smax-postgres/html/search ; \
install -m 644 -D apidoc/html/* $(STAGE)/share/doc/html/smax-postgres/ ; \
install -m 644 -D apidoc/html/search/* $(STAGE)/share/doc/smax-postgres/html/search/ ; \
echo "installing API docs under $(htmldir)." ; \
install -d $(htmldir)/search ; \
install -m 644 -D apidoc/html/* $(htmldir)/smax-postgres/ ; \
install -m 644 -D apidoc/html/search/* $(htmldir)/search/ ; \
fi

.PHONY: install-sma
install-sma: CONFIG := "cfg/smax-postgres.cfg.sma"
install-sma: install

# Built-in help screen for `make help`
.PHONY: help
Expand All @@ -133,7 +157,7 @@ help:
@echo " local-dox Compiles local HTML API documentation using 'doxygen'."
@echo " check Performs static analysis with 'cppcheck'."
@echo " all All of the above."
@echo " install Install (may require sudo)"
@echo " install Install components (e.g. 'make prefix=<path> install')"
@echo " install-sma Install at the SMA (with sudo)"
@echo " clean Removes intermediate products."
@echo " distclean Deletes all generated files."
Expand All @@ -148,4 +172,4 @@ Makefile: config.mk build.mk

include build.mk


13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,19 @@ Now you may compile `smax-postgres`:
$ make
```

After building the library you can install the above components to the desired locations on your system. For a
system-wide install you may simply run:

```bash
$ sudo make install
```

Or, to install in some other locations, you may set a prefix. For example to install under `/opt` instead, you can:

```bash
$ sudo make prefix=/opt install
```

----------------------------------------------------------------------------------------------------------------------

<a name="installation"></a>
Expand Down

0 comments on commit c471209

Please sign in to comment.