makefile - 如何在 Makefile 中有动态目标?

标签 makefile

看看下面的这个 Makefile。

compose:
    docker-compose up myapp

compose-shell:
    docker-compose run myapp /bin/bash

compose-shellplus:
    docker-compose run myapp make shell

compose-test:
    docker-compose run myapp make test

compose-migrate:
    docker-compose run myapp make migrate

compose-load:
    docker-compose run myapp make load

compose-export:
    docker-compose run myapp make export

compose-flush:
    docker-compose run myapp make flush

# run tests
test:
    python manage.py test --settings=$(PROJECT_SETTINGS)

# install depedencies (and virtualenv for linux)
install:
ifndef WIN
    -virtualenv -p python3 .venv
endif
    pip install -r requirements.txt

# handle django migrations
migrate:
    python manage.py makemigrations --settings=$(PROJECT_SETTINGS)
    python manage.py migrate --settings=$(PROJECT_SETTINGS)

# handle statics
static:
    python manage.py collectstatic --settings=$(PROJECT_SETTINGS)

shell:
    python manage.py shell_plus --settings=$(PROJECT_SETTINGS)

load:
    python manage.py loaddata db.json --settings=${PROJECT_SETTINGS}

export:
    python manage.py dumpdata --indent 2 --natural-foreign --natural-primary -e sessions -e admin -e contenttypes -e auth.Permission  > db.json --settings=${PROJECT_SETTINGS}

flush:
    python manage.py sqlflush --settings=${PROJECT_SETTINGS}

有没有更有效的方法来做到这一点?

例如:
compose-${target_name_after_dash}:
    docker-compose run myapp make ${target_name_after_dash}

最佳答案

在发布到 SO 之前,最好尝试在 the documentation 中找到答案。这是您可以使用 GNU make 做的最基本的事情之一。

使用 pattern rule :

compose-%:
        docker-compose run myapp make $*

关于makefile - 如何在 Makefile 中有动态目标?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49451148/

相关文章:

c++ - 编译/链接 C 和 C++ 文件时遇到问题

c++ - 使用 linux g++ 编译器在 makefile 中创建静态库

makefile - 替换 Makefile 中的文件名

windows - D9024 制作无法识别的源文件类型

c++ - 类函数的多定义错误

c++ - 从其他 C++ 源调用函数不起作用

c++ - 如何在 macOS Sierra 上执行图形 C++ 程序

c++ - 在 makefile 中编写依赖项,使用 makefile

c++ - 如何更改makefile中g++的版本

linux - gcc '-c'和gcc '-o'是什么意思?