Golden Codes - armanexplorer planet

Practical code snippets for Django, Python, Bash, Git and All!

View on GitHub

check makefile is OK

cat -e -t -v makefile_name

vars

Docs Ref

Integrate with Bash

Docs

special variables

Docs

run bash script

Ref

temp var

Ref

run in one shell solution

out.tar:
   set -e ;\
   TMP=$$(mktemp -d) ;\
   echo hi $$TMP/hi.txt ;\
   tar -C $$TMP cf $@ . ;\
   rm -rf $$TMP ;\

use separate lines

get-backup-dir: TEMP = $(shell find "$(BACKUP_DIR)" -maxdepth 1 -type d -printf '%p\n' | sort -r | head -n1)
get-backup-dir: ## print that last backup dir
 @echo "The relative path is:\n $(TEMP)"

using eavl

out.tar :
    $(eval TMP := $(shell mktemp -d))
    @echo hi $(TMP)/hi.txt
    tar -C $(TMP) cf $@ .
    rm -rf $(TMP)

call another target with arg

.PHONY: callee
callee:
 @echo $(XYZ)

.PHONY: caller
caller: XYZ = 2
caller: a
caller:
 @echo 'test'

if empty

    ifeq ($(a),)
        b=2
    else
        b=$(a)
    endif

multiprocess jobs

Docs

You can also use MAKEFLAGS += 2 in the Makefile to be able to have two parallel processes To use all of cpus:

NPROCS = $(shell grep -c 'processor' /proc/cpuinfo)
MAKEFLAGS += -j$(NPROCS)