Portable (Linux, Cygwin,...) Makefile for my own Shell OpenSSL file en-/decryption scripts Let it be clear that in this question I ask for further guidance with my current version of Makefile used for my own Shell OpenSSL file en-/decryption scripts, not those scripts themselves.

I did my best, but this is my own first Makefile, so I better give it to you for review. I may only think the work is done, there may be many issues I don't know about.

Requirements:


The implicit destination path must be easily overridden without having to edit the Makefile
The implicit target must check for integrity (hashsum) stored in the file SHA512SUMS
The file must account for non-standard Linux environments like Cygwin
I myself tested it under normal circumstances in Linux Mint 18.3 and Cygwin
All files can be simply acquired from GitHub page of this little project




The Makefile follows:

DESTDIR?=/usr/local/bin
install_path=$(DESTDIR)

script_name_1=encrypt-file-aes256
script_name_2=decrypt-file-aes256

user_id=$(shell whoami)
group_id=$(shell id -gn)

.PHONY: check
.PHONY: install
.PHONY: uninstall

check:
    [ -f $(script_name_1) ] &amp;&amp; [ -f $(script_name_2) ] &amp;&amp; sha512sum --check SHA512SUMS --status &amp;&amp; echo "OK: Files are prepared. You may use make install command now." || echo "ERROR: Files are missing and / or hashsum mismatch!"

install:
    install --verbose --mode=0755 --owner=$(user_id) --group=$(group_id) --target-directory=$(install_path) $(script_name_1) $(script_name_2)

uninstall:
    rm $(install_path)/$(script_name_1) $(install_path)/$(script_name_2)
The check target always succeeds (because the last command in the pipeline is echo).  We'd like it to fail if any of the tests fail, so we should just write them one per line.  Instead of testing for the existence of the files, we should make the check target depend on them:
check: $(script_name_1)  $(script_name_2)
    sha512sum --check SHA512SUMS
    @echo &quot;OK: Files are prepared. You may use make install command now.&quot;

BTW, script_name_1 and script_name_2 are completely unhelpful variable names.  How about encrypt and decrypt, for example?

I think the install target should depend on check - we really don't want to install if the check fails:
install: check


I'm not convinced that this is a good thing:
user_id=$(shell whoami)
group_id=$(shell id -gn)

When we install software, we normally make it owned by an appropriate user on the system, not the person doing the installing.  In most cases, programs are owned by root, so that no ordinary user can accidentally overwrite them (or any other harmful action).

Make provides a $(RM) definition to give you a more portable command for deleting files.

It's great that you've thought about install location and about overridability of such parameters.  You probably ought to know the conventional variables that are used for these:

DESTDIR specifies where the root directory is.  This is usually empty, but packaging tools set this to a suitable working directory to build a (partial) filesystem image that can be archived.
PREFIX works somewhat like your DESTDIR or install_path (I'm not sure why you have two names for the same thing).


This is a rare Makefile that doesn't need .DELETE_ON_ERROR: (since it contains no non-PHONY targets).

Modified code
This is what I ended up with:
PREFIX = /usr/local

install_path = $(DESTDIR)$(PREFIX)/bin

encrypt = encrypt-file-aes256
decrypt = decrypt-file-aes256

check: $(encrypt)  $(decrypt)
    sha512sum --check SHA512SUMS
    @echo &quot;OK: Files are prepared. You may use make install command now.&quot;

install: check
    install --d -D $(install_path)
    install -m 0755 -t $(install_path) $(encrypt) $(decrypt)

uninstall:
    $(RM) $(install_path)/$(encrypt) $(install_path)/$(decrypt)


.PHONY: check install uninstall

Note that Make variables specified on the command line will override those in the Makefile, so you can write
make install PREFIX=&quot;$(HOME)/testing&quot;

to install to your test directory, for example.