Add Make article
This commit is contained in:
parent
8c01059550
commit
133536f665
2 changed files with 557 additions and 0 deletions
81
content/articles/2023/fonctionnement_makefile/files/Makefile
Normal file
81
content/articles/2023/fonctionnement_makefile/files/Makefile
Normal file
|
@ -0,0 +1,81 @@
|
|||
build: text_1 text_2
|
||||
cat text_1 text_2 > build
|
||||
|
||||
text_1:
|
||||
echo "Hello" > text_1
|
||||
|
||||
text_2:
|
||||
echo "World" > text_2
|
||||
|
||||
.PHONY: view clean
|
||||
view:
|
||||
$(shell [ -f build ] && cat build)
|
||||
|
||||
clean:
|
||||
rm -f build text_1 text_2
|
||||
|
||||
.PHONY: echo
|
||||
echo:
|
||||
echo "La commande sera affichée"
|
||||
@echo "seul le résuiltat est affiché"
|
||||
|
||||
VAR = "Hello"
|
||||
REF = $(VAR)
|
||||
EXP := $(VAR)
|
||||
.PHONY: assign
|
||||
assign:
|
||||
@echo "initial value: $(VAR)"
|
||||
$(eval override VAR = Bonjour)
|
||||
@echo "new value: $(VAR)"
|
||||
@echo "assign by reference \`VAR_2 = value\`: $(REF)"
|
||||
@echo "assign by expansion \`VAR_2 := value\`: $(EXP)"
|
||||
|
||||
.PHONY: specific
|
||||
specific: text_1 text_2 build
|
||||
@echo "target.....$@"
|
||||
@echo "First dep..$<"
|
||||
@echo "All deps...$^"
|
||||
|
||||
TEXT = hello world
|
||||
NEW_TEXT = $(subst hello, bonjour, $(TEXT))
|
||||
.PHONY: subst
|
||||
subst:
|
||||
@echo $(NEW_TEXT)
|
||||
|
||||
FILES = $(patsubst text_%,my_text_%, $(wildcard text*))
|
||||
.PHONY: textfiles
|
||||
textfiles: build
|
||||
@echo "origin: $(wildcard text*)"
|
||||
@echo "files: $(FILES)"
|
||||
|
||||
.PHONY: messages
|
||||
messages:
|
||||
$(info Message d'information)
|
||||
$(warning Message d'alerte)
|
||||
$(error Message d'erreur)
|
||||
$(info Ce message ne s'affichera pas!)
|
||||
|
||||
EXP_FILES := $(wildcard text*)
|
||||
REF_FILES = $(wildcard text*)
|
||||
.PHONY: macro
|
||||
macro: clean
|
||||
@echo "EXP: $(EXP_FILES)"
|
||||
@echo "REF: $(REF_FILES)"
|
||||
|
||||
TEST = bonjour
|
||||
DIST := $(shell lsb_release -i | awk -F ':\t' '{print $$2}')
|
||||
ifeq ($(DIST), Arch)
|
||||
MY_MESS := "By the Way"
|
||||
endif
|
||||
.PHONY: condition
|
||||
condition:
|
||||
ifndef MY_MESS
|
||||
@echo "Vous n'utilisez pas ArchLinux : $(DIST)"
|
||||
else
|
||||
@echo $(MY_MESS)
|
||||
endif
|
||||
ifeq ($(TEST), bonjour)
|
||||
@echo "TEST n'a pas été modifiée"
|
||||
else
|
||||
@echo 'TEST a été modifiée'
|
||||
endif
|
Loading…
Add table
Add a link
Reference in a new issue