هذا الجزء لم يُترجم بعد. أنت ترى النص الإنجليزي.
ماذا يفعل
make reads a Makefile with targets. Each target has a list of things it depends on and the shell lines (the recipe) that build it. make runs a recipe only when a file is missing or older than the files it depends on, so a big build only does the work that changed.
In DevOps teams a Makefile is often just a task runner: make build, make test, make up, make deploy. The same short commands work on every laptop and in every CI job. Such targets are marked .PHONY because they do not make a file.
Recipe lines must start with a Tab, not spaces.
طريقة الكتابة
make [OPTIONS] [TARGET ...] [VAR=value ...]الخيارات 13
الأكثر استخدامًا
Common options
لا يوجد شيء يطابق هذا الفلتر.
أمثلة 11
$ مستخدم عادي# بصلاحية root (أو مع sudo)
1Run the default target (the first one in the file)
make2A task-runner Makefile for a web service
cat Makefile .PHONY: build test lint up down IMAGE ?= shop TAG ?= $(shell git rev-parse --short HEAD) build: docker build -t $(IMAGE):$(TAG) . test: go test ./... lint: golangci-lint run up: docker compose up -d down: docker compose down make build testRecipe lines start with a Tab.
?=sets a default that the environment or the command line can change.3Set a variable from the command line
make build TAG=v1.4.04See what would run, without running it
make -n deploy5Build faster with 8 jobs at once
make -j86Run the Makefile of a sub-folder
make -C services/api test7A help target that lists all targets
cat Makefile help: ## Show this help @grep -E '^[a-zA-Z_-]+:.*## ' $(MAKEFILE_LIST) | awk -F':.*## ' '{printf "%-12s %s\n", $$1, $$2}' make help help Show this help@hides the command itself.$$is a single$for the shell.8Rebuild everything
make -B9Use make in CI (GitHub Actions)
cat .github/workflows/ci.yml jobs: test: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - run: make lint test10Find out why a target runs again
make --debug=b build11Check if a target is up to date (exit code)
make -q dist/app || echo "needs a build"
لا يوجد شيء يطابق هذا الفلتر.
انتبه
- "missing separator" means a recipe line starts with spaces instead of a Tab.
- Each recipe line runs in its own shell:
cd diron one line does not change the next line. Usecd dir && cmd. - Mark task targets
.PHONY, or a file with the same name (for example a folder calledtest) stops them.
الملفات
Makefile- The default file make reads (also
makefile,GNUmakefile).
نصائح للحفظ
- Keep the real logic in scripts and call them from make; the Makefile stays short.
make helpwith## commentsmakes a project easy for new team members.
رموز الخروج
0 | All targets done. |
1 | -q and a target is not up to date. |
2 | An error. |