From 9da1cc8208a282283a3d83e22b2b7e901b6d517d Mon Sep 17 00:00:00 2001 From: Attila Kovacs Date: Tue, 12 Nov 2024 20:24:55 +0100 Subject: [PATCH] Add make install with support for prefix and GNU standard locations --- .github/workflows/install.yml | 77 ++++++++++++++++++++++++++++ Makefile | 94 ++++++++++++++++++++++------------- README.md | 13 +++++ 3 files changed, 149 insertions(+), 35 deletions(-) create mode 100644 .github/workflows/install.yml diff --git a/.github/workflows/install.yml b/.github/workflows/install.yml new file mode 100644 index 0000000..4295035 --- /dev/null +++ b/.github/workflows/install.yml @@ -0,0 +1,77 @@ +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 PostgreSQL + run: sudo apt-get install libpq-dev + + - name: install systemd development files + run: sudo apt-get install libsystemd-dev + + - name: install popt development files + run: sudo apt-get install libpopt-dev + + - 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 diff --git a/Makefile b/Makefile index d0d5b40..6961cb9 100644 --- a/Makefile +++ b/Makefile @@ -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 @@ -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 @@ -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= install')" @echo " install-sma Install at the SMA (with sudo)" @echo " clean Removes intermediate products." @echo " distclean Deletes all generated files." @@ -148,4 +172,4 @@ Makefile: config.mk build.mk include build.mk - + diff --git a/README.md b/README.md index 7789ce6..f971dfd 100644 --- a/README.md +++ b/README.md @@ -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 +``` + ----------------------------------------------------------------------------------------------------------------------