Skip to content

Commit 548cbfa

Browse files
committed
💥 Update all variables to respect autotools
1 parent 54240d5 commit 548cbfa

File tree

14 files changed

+143
-88
lines changed

14 files changed

+143
-88
lines changed

README.md

Lines changed: 63 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ This project is also like meson-python. You must add code to `xmake.lua`:
111111
```lua
112112
target("example")
113113
set_kind("phony")
114-
add_installfiles("src/example/*.py", {prefixdir= "$(xmake-platlib)/example"})
114+
add_installfiles("src/example/*.py", {prefixdir= "$(pythondir)/example"})
115115
```
116116

117117
Note, xmake supports glob expression which meson doesn't support.
@@ -142,33 +142,43 @@ optionally contains these files, and they will be installed to:
142142

143143
- python module, can be pure python files or dynamic linked library
144144
- `example.py`: `/usr/lib/python3.13/site-packages/example.py`
145-
- `example/__init__.py`: `/usr/lib/python3.13/site-packages/example/__init__.py`
146-
- `example.cpython-313-x86_64-linux-gnu.so`: `/usr/lib/python3.13/site-packages/example.cpython-313-x86_64-linux-gnu.so`
147-
- `example/_C.cpython-313-x86_64-linux-gnu.so`: `/usr/lib/python3.13/site-packages/example/_C.cpython-313-x86_64-linux-gnu.so`
145+
- `example/__init__.py`:
146+
`/usr/lib/python3.13/site-packages/example/__init__.py`
147+
- `example.cpython-313-x86_64-linux-gnu.so`:
148+
`/usr/lib/python3.13/site-packages/example.cpython-313-x86_64-linux-gnu.so`
149+
- `example/_C.cpython-313-x86_64-linux-gnu.so`:
150+
`/usr/lib/python3.13/site-packages/example/_C.cpython-313-x86_64-linux-gnu.so`
148151
- attached data
149152
- `example-0.0.1.data/scripts/example`: `/usr/bin/example`
150-
- `example-0.0.1.data/headers/example.h`: `/usr/include/python3.13/example/example.h`
153+
- `example-0.0.1.data/headers/example.h`:
154+
`/usr/include/python3.13/example/example.h`
151155
- `example-0.0.1.data/data/other/data.txt`: `/usr/other/data.txt`
152156
- metadata
153-
- `example-0.0.1.dist-info/WHEEL`: `/usr/lib/python3.13/site-packages/example-0.0.1.dist-info/WHEEL`
154-
- `example-0.0.1.dist-info/METADATA`: `/usr/lib/python3.13/site-packages/example-0.0.1.dist-info/METADATA`
155-
- `example-0.0.1.dist-info/RECORD`: `/usr/lib/python3.13/site-packages/example-0.0.1.dist-info/RECORD`
156-
- `example-0.0.1.dist-info/licenses/LICENSE`: `/usr/lib/python3.13/site-packages/example-0.0.1.dist-info/licenses/LICENSE`
157+
- `example-0.0.1.dist-info/WHEEL`:
158+
`/usr/lib/python3.13/site-packages/example-0.0.1.dist-info/WHEEL`
159+
- `example-0.0.1.dist-info/METADATA`:
160+
`/usr/lib/python3.13/site-packages/example-0.0.1.dist-info/METADATA`
161+
- `example-0.0.1.dist-info/RECORD`:
162+
`/usr/lib/python3.13/site-packages/example-0.0.1.dist-info/RECORD`
163+
- `example-0.0.1.dist-info/licenses/LICENSE`:
164+
`/usr/lib/python3.13/site-packages/example-0.0.1.dist-info/licenses/LICENSE`
157165

158166
So we create a [xmake.lua](src/xmake_python/templates/xmake.lua), which defines
159167
some variables, and when `xmake install -o/tmp/tmpXXXXXXXX`, they will be
160168
some paths prefixed with `/tmp/tmpXXXXXXXX`, and finally packaged to:
161169

162-
- xmake-platlib: `/platlib` -> `/tmp/tmpXXXXXXXX/platlib` -> `/`
163-
- xmake-scripts: `/data/bin` -> `/tmp/tmpXXXXXXXX/data/bin` ->
164-
`example-0.0.1.data/scripts/`
165-
- xmake-headers: `/data/include` -> `/tmp/tmpXXXXXXXX/data/include` ->
166-
`example-0.0.1.data/headers/`
167-
- xmake-data: `/data` -> `/tmp/tmpXXXXXXXX/data` ->
168-
`example-0.0.1.data/data/`
169-
- xmake-metadata: `/metadata` -> `/tmp/tmpXXXXXXXX/metadata` ->
170-
`example-0.0.1.dist-info/`
171-
- xmake-null: `/null` -> `/tmp/tmpXXXXXXXX/null` -> will not be packaged
170+
- pythondir: `/platlib` -> `/tmp/tmpXXXXXXXX/platlib` -> `/`, like
171+
scikit-build-core's `SKBUILD_PLATLIB`
172+
- bindir: `/data/bin` -> `/tmp/tmpXXXXXXXX/data/bin` ->
173+
`example-0.0.1.data/scripts/`, like scikit-build-core's `SKBUILD_SCRIPTS`
174+
- includedir: `/data/include` -> `/tmp/tmpXXXXXXXX/data/include` ->
175+
`example-0.0.1.data/headers/`, like scikit-build-core's `SKBUILD_HEADERS`
176+
- prefix: `/data` -> `/tmp/tmpXXXXXXXX/data` ->
177+
`example-0.0.1.data/data/`, like scikit-build-core's `SKBUILD_DATA`
178+
- metadatadir: `/metadata` -> `/tmp/tmpXXXXXXXX/metadata` ->
179+
`example-0.0.1.dist-info/`, like scikit-build-core's `SKBUILD_METADATA`
180+
- nulldir: `/null` -> `/tmp/tmpXXXXXXXX/null` -> will not be packaged, like
181+
scikit-build-core's `SKBUILD_NULL`
172182

173183
So you can create 3 kinds of wheels:
174184

@@ -186,7 +196,8 @@ We use the following method to judge the kind:
186196

187197
1. If all target's kinds are `phony` and don't use any package, the wheel
188198
is a pure python wheel.
189-
2. Else if all targets don't use rule `python.*`, the wheel is a binary program wheel.
199+
2. Else if all targets don't use rule `python.*`, the wheel is a binary program
200+
wheel.
190201
3. Else the wheel is a dynamic linked python module wheel.
191202

192203
### Cross Compilation
@@ -208,3 +219,35 @@ toolchains respect many environment variables:
208219
- `VSCMD_ARG_TARGET_ARCH`: for Visual Studio's MSVC.
209220

210221
This project also detect them.
222+
223+
### Variables
224+
225+
All variables suffixed `dir` are kept, like autotools. Except above mentioned
226+
`bindir`, `includedir`, `pythondir`, etc, the following variables are kept.
227+
228+
- version: xmake version
229+
- prefixdir: string `data`, used to combine `prefix`: `/tmp/tmpXXXXXXXXX/data`
230+
- root: temporary working directory like `/tmp/tmpXXXXXXXXX`
231+
- datadir: `$(prefix)/share`, because it is usual.
232+
233+
### Autotools/Makefile
234+
235+
Except xmake, we also support classic GNU/Linux software build procedures:
236+
237+
```sh
238+
autoreconf -vif
239+
./configure
240+
make
241+
make install
242+
```
243+
244+
The following build systems respect it:
245+
246+
- [make](https://www.gnu.org/software/make/)/
247+
[kati](https://github.com/google/kati/)
248+
- [xmake.sh](https://github.com/xmake-io/xmake.sh/)
249+
- [autotools](https://www.gnu.org/software/autoconf/)
250+
251+
For autotools, you must include
252+
[`variables.mak`](tests/examples/autotools/program/variables.mak) in your
253+
`Makefile.am`.

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ build-backend = "xmake_python"
66
# https://setuptools.pypa.io/en/latest/userguide/pyproject_config.html
77
[project]
88
name = "xmake-python"
9-
version = "0.0.13"
9+
version = "0.1.0"
1010
description = "xmake Python build system (PEP 517)"
1111
readme = "README.md"
1212
# from typing import Self

src/xmake_python/templates/Makefile

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
1-
XMAKE_ROOT := {root}
2-
XMAKE_PLATLIB := $(XMAKE_ROOT)/platlib
3-
XMAKE_SCRIPTS := $(XMAKE_ROOT)/data/bin
4-
XMAKE_HEADERS := $(XMAKE_ROOT)/data/include
5-
XMAKE_DATA := $(XMAKE_ROOT)/data
6-
XMAKE_METADATA := $(XMAKE_ROOT)/metadata
7-
XMAKE_NULL := $(XMAKE_ROOT)/null
8-
XMAKE_VERSION := {version}
9-
DESTDIR := $(XMAKE_DATA)
1+
version := {version}
2+
prefixdir := data
3+
root := {root}
4+
5+
prefix := $(root)/$(prefixdir)
6+
bindir := $(prefix)/bin
7+
includedir := $(prefix)/include
8+
pythondir := $(root)/platlib
9+
metadatadir := $(root)/metadata
10+
nulldir := $(root)/null
11+
12+
datadir := $(prefix)/share
13+
1014
include {project}/{makefile}

src/xmake_python/templates/xmake.lua

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,43 @@
1-
option("xmake-platlib")
1+
option("version")
2+
do
3+
set_default("{version}")
4+
end
5+
option("prefixdir")
6+
do
7+
set_default("data")
8+
end
9+
option("root")
10+
do
11+
set_default("{root}")
12+
end
13+
14+
option("pythondir")
215
do
316
set_default("../platlib")
417
end
5-
option("xmake-scripts")
18+
option("bindir")
619
do
720
set_default("../data/bin")
821
end
9-
option("xmake-headers")
22+
option("includedir")
1023
do
1124
set_default("../data/include")
1225
end
13-
option("xmake-data")
26+
option("prefix")
1427
do
1528
set_default("../data")
1629
end
17-
option("xmake-metadata")
30+
option("metadatadir")
1831
do
1932
set_default("../metadata")
2033
end
21-
option("xmake-null")
34+
option("nulldir")
2235
do
2336
set_default("../null")
2437
end
25-
option("xmake-root")
26-
do
27-
set_default("{root}")
28-
end
29-
option("xmake-version")
38+
option("datadir")
3039
do
31-
set_default("{version}")
32-
end
33-
option("xmake-prefix")
34-
do
35-
set_default("data")
40+
set_default("../data/share")
3641
end
3742
option_end()
3843
set_prefixdir("data", {{bindir = "bin", libdir = "lib", includedir = "include"}})
Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,15 @@
1+
include variables.mak
2+
13
bin_PROGRAMS = main
24
main_SOURCES = main.c
35
bin_SCRIPTS = main.py
46

57
include_HEADERS = main.h
68

7-
# or
8-
# docdir = $(prefix)/share/doc
99
docdir = $(datadir)/doc
1010
doc_DATA = README.md
1111

1212
PYTHON = python
13-
pythondir = $(prefix)/../platlib
1413
python_PYTHON = example.py
1514

16-
metadatadir = $(prefix)/../metadata
1715
metadata_DATA = pyproject.toml
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
root = $(prefix)/..
2+
3+
pythondir = $(root)/platlib
4+
metadatadir = $(root)/metadata
5+
nulldir = $(root)/null

tests/examples/make/cython/Makefile

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ c.$(PYD_EXT): c.c
88
$(CC) $(shell pkg-config --cflags python3) -c -o $@ $^
99

1010
install:
11-
install -Dm644 c.$(PYD_EXT) -t $(XMAKE_PLATLIB)/example
12-
install -Dm644 src/example/py.py -t $(XMAKE_PLATLIB)/example
13-
install -Dm644 README.md -t $(XMAKE_DATA)/share/doc
14-
install -Dm644 pyproject.toml -t $(XMAKE_METADATA)
15-
install -Dm644 Makefile -t $(XMAKE_NULL)
11+
install -Dm644 c.$(PYD_EXT) -t $(pythondir)/example
12+
install -Dm644 src/example/py.py -t $(pythondir)/example
13+
install -Dm644 README.md -t $(prefix)/share/doc
14+
install -Dm644 pyproject.toml -t $(metadatadir)
15+
install -Dm644 Makefile -t $(nulldir)

tests/examples/make/our-first-project/Makefile

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ our_first_module.$(PYD_EXT): our_first_module.c
66
$(CC) $(shell pkg-config --cflags python3) -c -o $@ $^
77

88
install:
9-
install -Dm644 our_first_module.$(PYD_EXT) -t $(XMAKE_PLATLIB)
10-
install -Dm644 README.md -t $(XMAKE_DATA)/share/doc
11-
install -Dm644 pyproject.toml -t $(XMAKE_METADATA)
12-
install -Dm644 Makefile -t $(XMAKE_NULL)
9+
install -Dm644 our_first_module.$(PYD_EXT) -t $(pythondir)/our_first_project
10+
install -Dm644 README.md -t $(prefix)/share/doc
11+
install -Dm644 pyproject.toml -t $(metadatadir)
12+
install -Dm644 Makefile -t $(nulldir)

tests/examples/make/program/Makefile

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ main.h:
55
echo '#define VERSION "$(XMAKE_VERSION)"' > $@
66

77
install:
8-
install -D main -t $(XMAKE_SCRIPTS)
9-
install -D main.py -t $(XMAKE_SCRIPTS)
10-
install -Dm644 main.h -t $(XMAKE_HEADERS)
11-
install -Dm644 README.md -t $(XMAKE_DATA)/share/doc
12-
install -Dm644 example.py -t $(XMAKE_PLATLIB)
13-
install -Dm644 pyproject.toml -t $(XMAKE_METADATA)
14-
install -Dm644 Makefile -t $(XMAKE_NULL)
8+
install -D main -t $(bindir)
9+
install -D main.py -t $(bindir)
10+
install -Dm644 main.h -t $(includedir)
11+
install -Dm644 README.md -t $(prefix)/share/doc
12+
install -Dm644 example.py -t $(pythondir)
13+
install -Dm644 pyproject.toml -t $(metadatadir)
14+
install -Dm644 Makefile -t $(nulldir)

tests/examples/make/pybind/Makefile

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ example.$(PYD_EXT): example.cpp
66
$(CC) $(shell pkg-config --cflags python3 pybind11) -c -o $@ $^
77

88
install:
9-
install -Dm644 example.$(PYD_EXT) -t $(XMAKE_PLATLIB)
10-
install -Dm644 README.md -t $(XMAKE_DATA)/share/doc
11-
install -Dm644 pyproject.toml -t $(XMAKE_METADATA)
12-
install -Dm644 Makefile -t $(XMAKE_NULL)
9+
install -Dm644 example.$(PYD_EXT) -t $(pythondir)
10+
install -Dm644 README.md -t $(prefix)/share/doc
11+
install -Dm644 pyproject.toml -t $(metadatadir)
12+
install -Dm644 Makefile -t $(nulldir)

tests/examples/xmake/cython/xmake.lua

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@ includes("src")
55

66
target("c")
77
do
8-
set_prefixdir("$(xmake-prefix)/$(xmake-platlib)", {libdir = "example"})
8+
set_prefixdir("$(prefixdir)/$(pythondir)", {libdir = "example"})
99
add_rules("python.library", "python.cython", { soabi = true })
1010
add_files("*.py")
1111
add_packages("python")
1212

1313
add_installfiles("src/(example/*.py)")
14-
add_installfiles("README.md", {prefixdir= "$(xmake-data)/share/doc"})
15-
add_installfiles("pyproject.toml", {prefixdir= "$(xmake-metadata)"})
16-
add_installfiles("xmake.lua", {prefixdir= "$(xmake-null)"})
14+
add_installfiles("README.md", {prefixdir= "$(prefix)/share/doc"})
15+
add_installfiles("pyproject.toml", {prefixdir= "$(metadatadir)"})
16+
add_installfiles("xmake.lua", {prefixdir= "$(nulldir)"})
1717
end

tests/examples/xmake/our-first-project/xmake.lua

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@ add_requires("python 3.x")
33

44
target("our_first_module")
55
do
6-
set_prefixdir("$(xmake-prefix)/$(xmake-platlib)", { libdir = "our_first_project" })
6+
set_prefixdir("$(prefixdir)/$(pythondir)", { libdir = "our_first_project" })
77
add_rules("python.library", { soabi = true })
88
add_files("*.c")
99
add_packages("python")
1010

11-
add_installfiles("README.md", {prefixdir= "$(xmake-data)/share/doc"})
12-
add_installfiles("pyproject.toml", {prefixdir= "$(xmake-metadata)"})
13-
add_installfiles("xmake.lua", {prefixdir= "$(xmake-null)"})
11+
add_installfiles("README.md", {prefixdir= "$(prefix)/share/doc"})
12+
add_installfiles("pyproject.toml", {prefixdir= "$(metadatadir)"})
13+
add_installfiles("xmake.lua", {prefixdir= "$(nulldir)"})
1414
end

tests/examples/xmake/program/xmake.lua

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,16 @@ do
55
set_kind("binary")
66
add_files("*.c")
77

8-
add_installfiles("main.py", { prefixdir = "$(xmake-scripts)" })
9-
-- by default, prefixdir is $(xmake-data)
8+
add_installfiles("main.py", { prefixdir = "$(bindir)" })
9+
-- by default, prefixdir is $(prefix)
1010
-- so it can be ignored except you call set_prefixdir()
1111
add_installfiles("README.md", { prefixdir = "share/doc" })
12-
add_installfiles("example.py", { prefixdir = "$(xmake-platlib)" })
13-
add_installfiles("pyproject.toml", { prefixdir = "$(xmake-metadata)" })
14-
add_installfiles("xmake.lua", { prefixdir = "$(xmake-null)" })
12+
add_installfiles("example.py", { prefixdir = "$(pythondir)" })
13+
add_installfiles("pyproject.toml", { prefixdir = "$(metadatadir)" })
14+
add_installfiles("xmake.lua", { prefixdir = "$(nulldir)" })
1515

1616
set_configvar("version", "$(xmake-version)")
1717
add_configfiles("main.h.in")
1818
add_includedirs("$(buildir)")
19-
add_installfiles("$(buildir)/main.h", { prefixdir = "$(xmake-headers)" })
19+
add_installfiles("$(buildir)/main.h", { prefixdir = "$(includedir)" })
2020
end

tests/examples/xmake/pybind/xmake.lua

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@ add_requires("pybind11")
33

44
target("example")
55
do
6-
set_prefixdir("$(xmake-prefix)/$(xmake-platlib)", { libdir = "" })
6+
set_prefixdir("$(prefixdir)/$(pythondir)", { libdir = "" })
77
add_rules("python.library", { soabi = true })
88
add_files("*.cpp")
99
add_packages("pybind11")
1010
set_languages("c++11")
1111

12-
add_installfiles("README.md", {prefixdir= "$(xmake-data)/share/doc"})
13-
add_installfiles("pyproject.toml", {prefixdir= "$(xmake-metadata)"})
14-
add_installfiles("xmake.lua", {prefixdir= "$(xmake-null)"})
12+
add_installfiles("README.md", {prefixdir= "$(prefix)/share/doc"})
13+
add_installfiles("pyproject.toml", {prefixdir= "$(metadatadir)"})
14+
add_installfiles("xmake.lua", {prefixdir= "$(nulldir)"})
1515
end

0 commit comments

Comments
 (0)