diff options
| author | Tobiasz Laskowski <tobil4sk@outlook.com> | 2026-02-15 14:53:13 +0000 |
|---|---|---|
| committer | Hisham Muhammad <hisham@gobolinux.org> | 2026-07-11 22:13:55 -0300 |
| commit | 0e90c184ef44dae80be747983e27c6940fbea3b9 (patch) | |
| tree | 23c9a94aa0941ff057084ddab16c6102d5c0a348 | |
| parent | 07f675b5373e0c88b4930e2459e665f5678c2e5e (diff) | |
| download | luarocks-0e90c184ef44dae80be747983e27c6940fbea3b9.tar.gz luarocks-0e90c184ef44dae80be747983e27c6940fbea3b9.tar.bz2 luarocks-0e90c184ef44dae80be747983e27c6940fbea3b9.zip | |
docs: Fix LUA_LIBDIR handling in example Makefile
See: #1257
On most platforms LUA_LIBDIR is empty, so you get:
Warning: unmatched variable LUA_LIBDIR
And the resulting empty -L flag in the example can cause issues like:
ld: warning: search path '-lpthread' not found
It's also not sufficient to pass the -L flag, you also have to provide the actual library to link.
I've updated the example to only set LUA_LIBDIR for windows where it is used by default. However, as noted in it is possible to do:
luarocks config link_lua_explicitly true
It would be better to respect this setting rather than hard-coding windows only, but I'm not sure the best way to check that config in the rockspec, I wonder if anyone else has any suggestions?
[docs] Use implicit rules in example makefile
See:
https://www.gnu.org/software/make/manual/html_node/Catalogue-of-Rules.html#index-C_002c-rule-to-compile
https://www.gnu.org/software/make/manual/html_node/Catalogue-of-Rules.html#index-linking_002c-predefined-rule-for
https://www.gnu.org/software/make/manual/html_node/Implicit-Variables.html#index-CPPFLAGS
https://www.gnu.org/software/make/manual/html_node/Implicit-Variables.html#index-LDFLAGS
[docs] Fix LUA_LIBDIR handling in makefile example
The example setup given here gives this warning on most systems:
```
Warning: unmatched variable LUA_LIBDIR
```
Also, you get an empty `-L` flag, which one some compilers will eat the
following flag, causing issues, e.g.
```
ld: warning: search path '-lpthread' not found
```
This is because most environments do not require explicit linking of
LUALIB, so it LUA_LIBDIR not set.
This patch fixes the sample by only setting `LUA_LIBDIR` when it
is actually needed, i.e. on windows.
[docs] Fix example makefile for windows
On windows, LUALIB is set to e.g. `lua51.dll`, which is the full name
and does not work with `-llua51.dll`. Passing the full path here allows
it to be linked properly.
Another option is `-l:$(LUALIB)` to specify the full file name, but some
linkers do not support that syntax.
[docs] Fix broken formatting due to unescaped $
[docs] Highlight makefile syntax
[docs] Use consistent whitespace
Fixes markdown warnings about hard tabs
| -rw-r--r-- | docs/creating_a_makefile_that_plays_nice_with_luarocks.md | 124 |
1 files changed, 68 insertions, 56 deletions
diff --git a/docs/creating_a_makefile_that_plays_nice_with_luarocks.md b/docs/creating_a_makefile_that_plays_nice_with_luarocks.md index 0caeeacb..cb7e57a0 100644 --- a/docs/creating_a_makefile_that_plays_nice_with_luarocks.md +++ b/docs/creating_a_makefile_that_plays_nice_with_luarocks.md | |||
| @@ -41,57 +41,65 @@ These variables are not readily available in the Makefile, you need to tell | |||
| 41 | LuaRocks to pass them to make. A simple rockspec that will do this looks | 41 | LuaRocks to pass them to make. A simple rockspec that will do this looks |
| 42 | like this: | 42 | like this: |
| 43 | 43 | ||
| 44 | ``` | 44 | ```lua |
| 45 | package = "lrtest" | 45 | package = "lrtest" |
| 46 | version = "1.0-1" | 46 | version = "1.0-1" |
| 47 | source = { | 47 | source = { |
| 48 | url = "http://..." | 48 | url = "http://..." |
| 49 | } | 49 | } |
| 50 | build = { | 50 | build = { |
| 51 | type = "make", | 51 | type = "make", |
| 52 | build_variables = { | 52 | build_variables = { |
| 53 | CFLAGS="$(CFLAGS)", | 53 | CFLAGS="$(CFLAGS)", |
| 54 | LIBFLAG="$(LIBFLAG)", | 54 | LIBFLAG="$(LIBFLAG)", |
| 55 | LUA_LIBDIR="$(LUA_LIBDIR)", | 55 | LUA_BINDIR="$(LUA_BINDIR)", |
| 56 | LUA_BINDIR="$(LUA_BINDIR)", | 56 | LUA_INCDIR="$(LUA_INCDIR)", |
| 57 | LUA_INCDIR="$(LUA_INCDIR)", | 57 | LUA="$(LUA)", |
| 58 | LUA="$(LUA)", | 58 | }, |
| 59 | }, | 59 | install_variables = { |
| 60 | install_variables = { | 60 | INST_PREFIX="$(PREFIX)", |
| 61 | INST_PREFIX="$(PREFIX)", | 61 | INST_BINDIR="$(BINDIR)", |
| 62 | INST_BINDIR="$(BINDIR)", | 62 | INST_LIBDIR="$(LIBDIR)", |
| 63 | INST_LIBDIR="$(LIBDIR)", | 63 | INST_LUADIR="$(LUADIR)", |
| 64 | INST_LUADIR="$(LUADIR)", | 64 | INST_CONFDIR="$(CONFDIR)", |
| 65 | INST_CONFDIR="$(CONFDIR)", | 65 | }, |
| 66 | }, | 66 | platforms = { |
| 67 | windows = { | ||
| 68 | build_variables = { | ||
| 69 | -- windows requires linking lua library explicitly | ||
| 70 | LUA_LIBDIR="$(LUA_LIBDIR)", | ||
| 71 | LUALIB="$(LUALIB)", | ||
| 72 | } | ||
| 73 | } | ||
| 74 | } | ||
| 67 | } | 75 | } |
| 68 | ``` | 76 | ``` |
| 69 | 77 | ||
| 70 | The corresponding Makefile looks like this: | 78 | The corresponding Makefile looks like this: |
| 71 | 79 | ||
| 72 | ``` | 80 | ```make |
| 73 | all: | 81 | all: |
| 74 | @echo --- build | 82 | @echo --- build |
| 75 | @echo CFLAGS: $(CFLAGS) | 83 | @echo CFLAGS: $(CFLAGS) |
| 76 | @echo LIBFLAG: $(LIBFLAG) | 84 | @echo LIBFLAG: $(LIBFLAG) |
| 77 | @echo LUA_LIBDIR: $(LUA_LIBDIR) | 85 | @echo LUA_LIBDIR: $(LUA_LIBDIR) |
| 78 | @echo LUA_BINDIR: $(LUA_BINDIR) | 86 | @echo LUA_BINDIR: $(LUA_BINDIR) |
| 79 | @echo LUA_INCDIR: $(LUA_INCDIR) | 87 | @echo LUA_INCDIR: $(LUA_INCDIR) |
| 80 | @echo LUA: $(LUA) | 88 | @echo LUA: $(LUA) |
| 81 | 89 | ||
| 82 | install: | 90 | install: |
| 83 | @echo --- install | 91 | @echo --- install |
| 84 | @echo INST_PREFIX: $(INST_PREFIX) | 92 | @echo INST_PREFIX: $(INST_PREFIX) |
| 85 | @echo INST_BINDIR: $(INST_BINDIR) | 93 | @echo INST_BINDIR: $(INST_BINDIR) |
| 86 | @echo INST_LIBDIR: $(INST_LIBDIR) | 94 | @echo INST_LIBDIR: $(INST_LIBDIR) |
| 87 | @echo INST_LUADIR: $(INST_LUADIR) | 95 | @echo INST_LUADIR: $(INST_LUADIR) |
| 88 | @echo INST_CONFDIR: $(INST_CONFDIR) | 96 | @echo INST_CONFDIR: $(INST_CONFDIR) |
| 89 | ``` | 97 | ``` |
| 90 | 98 | ||
| 91 | Now, if you call `luarocks make`, the output will look something | 99 | Now, if you call `luarocks make`, the output will look something |
| 92 | like this: | 100 | like this: |
| 93 | 101 | ||
| 94 | ``` | 102 | ```make |
| 95 | -- build | 103 | -- build |
| 96 | CFLAGS: -O2 -fPIC | 104 | CFLAGS: -O2 -fPIC |
| 97 | LIBFLAG: -shared | 105 | LIBFLAG: -shared |
| @@ -116,8 +124,8 @@ The `CONFDIR` and `PREFIX` variables point to locations | |||
| 116 | where you can store configuration or other data for your module. Your code | 124 | where you can store configuration or other data for your module. Your code |
| 117 | must be made aware of these paths in order to use them. If you use the | 125 | must be made aware of these paths in order to use them. If you use the |
| 118 | `copy_directories` entry in the build section of your rockspec, | 126 | `copy_directories` entry in the build section of your rockspec, |
| 119 | then what is mentioned there is copied to $(PREFIX) (i.e. a directory doc | 127 | then what is mentioned there is copied to `$(PREFIX)` (i.e. a directory doc |
| 120 | will be available under $(PREFIX)/doc). If you copy directories in your | 128 | will be available under `$(PREFIX)/doc`). If you copy directories in your |
| 121 | `install` Makefile rule, you should do the same. | 129 | `install` Makefile rule, you should do the same. |
| 122 | 130 | ||
| 123 | Now, if your Makefile is meant to be used standalone as well, which it | 131 | Now, if your Makefile is meant to be used standalone as well, which it |
| @@ -129,54 +137,60 @@ the Makefile. | |||
| 129 | With this, a Makefile that is usable both from LuaRocks and standalone | 137 | With this, a Makefile that is usable both from LuaRocks and standalone |
| 130 | might look like this: | 138 | might look like this: |
| 131 | 139 | ||
| 132 | ``` | 140 | ```make |
| 133 | CFLAGS = -fPIC -O2 | 141 | CFLAGS = -fPIC -O2 |
| 134 | LIBFLAG = -shared | 142 | LIBFLAG = -shared |
| 135 | LUA_LIBDIR = /usr/local/lib/lua/5.2 | 143 | LUA_LIBDIR = /usr/local/lib/lua/5.2 |
| 136 | LUA_BINDIR = /usr/local/bin | 144 | LUA_BINDIR = /usr/local/bin |
| 137 | LUA_INCDIR = /usr/local/include | 145 | LUA_INCDIR = /usr/local/include |
| 138 | LUA = lua | 146 | LUA = lua |
| 139 | 147 | ||
| 140 | INST_PREFIX = /usr/local | 148 | INST_PREFIX = /usr/local |
| 141 | INST_BINDIR = $(INST_PREFIX)/bin | 149 | INST_BINDIR = $(INST_PREFIX)/bin |
| 142 | INST_LIBDIR = $(INST_PREFIX)/lib/lua/5.2 | 150 | INST_LIBDIR = $(INST_PREFIX)/lib/lua/5.2 |
| 143 | INST_LUADIR = $(INST_PREFIX)/share/lua/5.2 | 151 | INST_LUADIR = $(INST_PREFIX)/share/lua/5.2 |
| 144 | INST_CONFDIR = $(INST_PREFIX)/etc | 152 | INST_CONFDIR = $(INST_PREFIX)/etc |
| 145 | 153 | ||
| 146 | all: | 154 | all: |
| 147 | @echo --- build | 155 | @echo --- build |
| 148 | @echo CFLAGS: $(CFLAGS) | 156 | @echo CFLAGS: $(CFLAGS) |
| 149 | @echo LIBFLAG: $(LIBFLAG) | 157 | @echo LIBFLAG: $(LIBFLAG) |
| 150 | @echo LUA_LIBDIR: $(LUA_LIBDIR) | 158 | @echo LUA_LIBDIR: $(LUA_LIBDIR) |
| 151 | @echo LUA_BINDIR: $(LUA_BINDIR) | 159 | @echo LUA_BINDIR: $(LUA_BINDIR) |
| 152 | @echo LUA_INCDIR: $(LUA_INCDIR) | 160 | @echo LUA_INCDIR: $(LUA_INCDIR) |
| 153 | 161 | ||
| 154 | install: | 162 | install: |
| 155 | @echo --- install | 163 | @echo --- install |
| 156 | @echo INST_PREFIX: $(INST_PREFIX) | 164 | @echo INST_PREFIX: $(INST_PREFIX) |
| 157 | @echo INST_BINDIR: $(INST_BINDIR) | 165 | @echo INST_BINDIR: $(INST_BINDIR) |
| 158 | @echo INST_LIBDIR: $(INST_LIBDIR) | 166 | @echo INST_LIBDIR: $(INST_LIBDIR) |
| 159 | @echo INST_LUADIR: $(INST_LUADIR) | 167 | @echo INST_LUADIR: $(INST_LUADIR) |
| 160 | @echo INST_CONFDIR: $(INST_CONFDIR) | 168 | @echo INST_CONFDIR: $(INST_CONFDIR) |
| 161 | ``` | 169 | ``` |
| 162 | 170 | ||
| 163 | You probably don't just want to echo stuff, so here's how to use the variables | 171 | You probably don't just want to echo stuff, so here's how to use the variables |
| 164 | when actually building or installing something: | 172 | when actually building or installing something: |
| 165 | 173 | ||
| 166 | ``` | 174 | ```make |
| 167 | ... | 175 | #... |
| 176 | |||
| 177 | CPPFLAGS = -I$(LUA_INCDIR) | ||
| 178 | LDFLAGS = $(LIBFLAG) | ||
| 179 | |||
| 180 | # handle platforms with explicit linking of lua | ||
| 181 | ifdef LUA_LIBDIR | ||
| 182 | LDLIBS += $(LUA_LIBDIR)/$(LUALIB) | ||
| 183 | endif | ||
| 168 | 184 | ||
| 169 | all: lrtest.so | 185 | all: lrtest.so |
| 170 | 186 | ||
| 171 | lrtest.so: lrtest.o | 187 | lrtest.so: lrtest.o |
| 172 | $(CC) $(LIBFLAG) -o $@ -L$(LUA_LIBDIR) $< | ||
| 173 | 188 | ||
| 174 | lrtest.o: lrtest.c | 189 | lrtest.o: lrtest.c |
| 175 | $(CC) -c $(CFLAGS) -I$(LUA_INCDIR) $< -o $@ | ||
| 176 | 190 | ||
| 177 | install: lrtest.so lrtest.lua | 191 | install: lrtest.so lrtest.lua |
| 178 | cp lrtest.so $(INST_LIBDIR) | 192 | cp lrtest.so $(INST_LIBDIR) |
| 179 | cp lrtest.lua $(INST_LUADIR) | 193 | cp lrtest.lua $(INST_LUADIR) |
| 180 | ``` | 194 | ``` |
| 181 | 195 | ||
| 182 | There is of course a lot more to a proper Makefile and rockspec, this is only | 196 | There is of course a lot more to a proper Makefile and rockspec, this is only |
| @@ -186,5 +200,3 @@ variables are created by LuaRocks, which have to be passed to the Makefile in | |||
| 186 | the same way. Check the other documentation, especially [Rockspec | 200 | the same way. Check the other documentation, especially [Rockspec |
| 187 | format](rockspec_format.md) and [Recommended practices for | 201 | format](rockspec_format.md) and [Recommended practices for |
| 188 | Makefiles](recommended_practices_for_makefiles.md), for details. | 202 | Makefiles](recommended_practices_for_makefiles.md), for details. |
| 189 | |||
| 190 | |||
