A make equivalent in Python
Project description
make.py
make.py is like make but with its build configuration written in Python.
Example
For the following Makefile:
CC=gcc
OUTPUT=build
all: $(OUTPUT)/main
$(OUTPUT)/%.o: %.c
mkdir -p $(dir $@)
$(CC) -MMD -c $< -o $@
$(OUTPUT)/main: $(OUTPUT)/hello.o $(OUTPUT)/main.o
$(CC) $^ -o $@
clean:
rm -rf $(OUTPUT)
.PHONY: clean
-include $(OUTPUT)/*.d
The equivalent Makefile.py is:
from pathlib import Path
from shutil import rmtree
from subprocess import check_call
from make_py import task, rule, phony_task
CC = "gcc"
OUTPUT = "build"
phony_task("all", f"{OUTPUT}/main")
def collect_c_dependencies(target, target_regex_groups):
dep_file = Path(target).with_suffix(".d")
if dep_file.exists():
return dep_file.read_text().split(":")[1].strip().split(" ")
# missing parent directories will be made automatically
@rule(f"{OUTPUT}/%.o", ["%.c", collect_c_dependencies])
def compile_c(ctx):
check_call([CC, "-MMD", "-c", ctx.source, "-o", ctx.target])
@rule(f"{OUTPUT}/main", [f"{OUTPUT}/{o}" for o in ["hello.o", "main.o"]])
def link(ctx):
check_call([CC, *ctx.sources, "-o", ctx.target])
@task()
def clean(ctx):
rmtree(OUTPUT, ignore_errors=True)
The commands can be executed by make.py the same way as executing make
For more examples, refer to the examples folder in project root.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
make_py-0.1.1.tar.gz
(6.6 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file make_py-0.1.1.tar.gz.
File metadata
- Download URL: make_py-0.1.1.tar.gz
- Upload date:
- Size: 6.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.1 importlib_metadata/3.7.2 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.59.0 CPython/3.9.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8d273b2859d771d0a8f9db1d778d3ee57fc6e54cb996dd4c1e19062a2c961254
|
|
| MD5 |
6d86675a108dee99b99a39d6ba94df92
|
|
| BLAKE2b-256 |
8edb5de04b503743abe9667acffe5467e7a38ff1a32b515f15905fd8e1736a03
|
File details
Details for the file make_py-0.1.1-py3-none-any.whl.
File metadata
- Download URL: make_py-0.1.1-py3-none-any.whl
- Upload date:
- Size: 8.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.1 importlib_metadata/3.7.2 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.59.0 CPython/3.9.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f69df8405403348310c2fd6aed17cbbdfe063fa8919ac80d80288b418161be0b
|
|
| MD5 |
5ce658a5c092fe2d36e728cbffeb8940
|
|
| BLAKE2b-256 |
ad6cd7925e0d3857e1ce99983227ea6a45e7fa85d345d3f5bd3c68fe9f16083d
|