From 2a24a58029a7e08a97619ada219cd8c36a0caded Mon Sep 17 00:00:00 2001 From: Attila Kovacs Date: Tue, 12 Nov 2024 20:22:10 +0100 Subject: [PATCH] Add make install with support for prefix and GNU standard locations --- .github/workflows/install.yml | 60 +++++++++++++++++++++++++++++++++++ Makefile | 44 +++++++++++++++++++++++++ README.md | 12 +++++++ 3 files changed, 116 insertions(+) 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..b25a973 --- /dev/null +++ b/.github/workflows/install.yml @@ -0,0 +1,60 @@ +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 + steps: + - name: install doxygen + run: sudo apt-get install doxygen + + - 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: Build xchange dependency + run: | + make -C xchange shared + sudo make -C xchange install + + - name: Build RedisX dependency + run: | + make -C redisx shared + sudo make -C redisx install + + - name: Build smax-clib distro + run: make distro + + - name: Install smax-clib in default location + run: sudo make install diff --git a/Makefile b/Makefile index 91891c7..19dc569 100644 --- a/Makefile +++ b/Makefile @@ -34,6 +34,10 @@ export .PHONY: all all: shared static tools $(DOC_TARGETS) check +# Build for distribution +.PHONY: distro +distro: shared $(DOC_TARGETS) + # Shared libraries (versioned and unversioned) .PHONY: shared shared: $(LIB)/libsmax.so @@ -99,6 +103,45 @@ Doxyfile.local: Doxyfile Makefile local-dox: README-smax.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) +libdir ?= $(exec_prefix)/lib +includedir ?= $(prefix)/include +datarootdir ?= $(prefix)/share +datadir ?= $(datarootdir) +mydatadir ?= $(datadir)/smax-clib +docdir ?= $(datarootdir)/doc/smax-clib +htmldir ?= $(docdir)/html + +.PHONY: install +install: install-libs install-headers install-apidoc + +.PHONY: install-libs +install-libs: shared + @echo "installing libraries to $(libdir)" + install -d $(libdir) + install -m 755 -D $(LIB)/lib*.so* $(libdir)/ + +.PHONY: install-headers +install-headers: + @echo "installing headers to $(includedir)" + install -d $(includedir) + install -m 644 -D include/* $(includedir)/ + +.PHONY: install-apidoc +install-apidoc: local-dox + @echo "installing API documentation to $(htmldir)" + install -d $(htmldir)/search + install -m 644 -D apidoc/html/search/* $(htmldir)/search/ + install -m 644 -D apidoc/html/*.* $(htmldir)/ + @echo "installing Doxygen tag file to $(docdir)" + install -d $(docdir) + install -m 644 -D apidoc/*.tag $(docdir)/ + + # Built-in help screen for `make help` .PHONY: help help: @@ -113,6 +156,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 components (e.g. 'make prefix= install')" @echo " clean Removes intermediate products." @echo " distclean Deletes all generated files." @echo diff --git a/README.md b/README.md index e73e0a4..658d0e7 100644 --- a/README.md +++ b/README.md @@ -128,6 +128,18 @@ After configuring, you can simply run `make`, which will build the `shared` (`li analysis via the `check` target. Or, you may build just the components you are interested in, by specifying the desired `make` target(s). (You can use `make help` to get a summary of the available `make` targets). +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 +``` -----------------------------------------------------------------------------