aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTobiasz Laskowski <tobil4sk@outlook.com>2026-02-15 14:53:13 +0000
committerHisham Muhammad <hisham@gobolinux.org>2026-07-11 22:13:55 -0300
commit0e90c184ef44dae80be747983e27c6940fbea3b9 (patch)
tree23c9a94aa0941ff057084ddab16c6102d5c0a348
parent07f675b5373e0c88b4930e2459e665f5678c2e5e (diff)
downloadluarocks-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.md124
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
41LuaRocks to pass them to make. A simple rockspec that will do this looks 41LuaRocks to pass them to make. A simple rockspec that will do this looks
42like this: 42like this:
43 43
44``` 44```lua
45package = "lrtest" 45package = "lrtest"
46version = "1.0-1" 46version = "1.0-1"
47source = { 47source = {
48 url = "http://..." 48 url = "http://..."
49} 49}
50build = { 50build = {
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
70The corresponding Makefile looks like this: 78The corresponding Makefile looks like this:
71 79
72``` 80```make
73all: 81all:
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
82install: 90install:
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
91Now, if you call `luarocks make`, the output will look something 99Now, if you call `luarocks make`, the output will look something
92like this: 100like this:
93 101
94``` 102```make
95-- build 103-- build
96CFLAGS: -O2 -fPIC 104CFLAGS: -O2 -fPIC
97LIBFLAG: -shared 105LIBFLAG: -shared
@@ -116,8 +124,8 @@ The `CONFDIR` and `PREFIX` variables point to locations
116where you can store configuration or other data for your module. Your code 124where you can store configuration or other data for your module. Your code
117must be made aware of these paths in order to use them. If you use the 125must 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,
119then what is mentioned there is copied to $(PREFIX) (i.e. a directory doc 127then what is mentioned there is copied to `$(PREFIX)` (i.e. a directory doc
120will be available under $(PREFIX)/doc). If you copy directories in your 128will 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
123Now, if your Makefile is meant to be used standalone as well, which it 131Now, if your Makefile is meant to be used standalone as well, which it
@@ -129,54 +137,60 @@ the Makefile.
129With this, a Makefile that is usable both from LuaRocks and standalone 137With this, a Makefile that is usable both from LuaRocks and standalone
130might look like this: 138might look like this:
131 139
132``` 140```make
133CFLAGS = -fPIC -O2 141CFLAGS = -fPIC -O2
134LIBFLAG = -shared 142LIBFLAG = -shared
135LUA_LIBDIR = /usr/local/lib/lua/5.2 143LUA_LIBDIR = /usr/local/lib/lua/5.2
136LUA_BINDIR = /usr/local/bin 144LUA_BINDIR = /usr/local/bin
137LUA_INCDIR = /usr/local/include 145LUA_INCDIR = /usr/local/include
138LUA = lua 146LUA = lua
139 147
140INST_PREFIX = /usr/local 148INST_PREFIX = /usr/local
141INST_BINDIR = $(INST_PREFIX)/bin 149INST_BINDIR = $(INST_PREFIX)/bin
142INST_LIBDIR = $(INST_PREFIX)/lib/lua/5.2 150INST_LIBDIR = $(INST_PREFIX)/lib/lua/5.2
143INST_LUADIR = $(INST_PREFIX)/share/lua/5.2 151INST_LUADIR = $(INST_PREFIX)/share/lua/5.2
144INST_CONFDIR = $(INST_PREFIX)/etc 152INST_CONFDIR = $(INST_PREFIX)/etc
145 153
146all: 154all:
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
154install: 162install:
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
163You probably don't just want to echo stuff, so here's how to use the variables 171You probably don't just want to echo stuff, so here's how to use the variables
164when actually building or installing something: 172when actually building or installing something:
165 173
166``` 174```make
167... 175#...
176
177CPPFLAGS = -I$(LUA_INCDIR)
178LDFLAGS = $(LIBFLAG)
179
180# handle platforms with explicit linking of lua
181ifdef LUA_LIBDIR
182LDLIBS += $(LUA_LIBDIR)/$(LUALIB)
183endif
168 184
169all: lrtest.so 185all: lrtest.so
170 186
171lrtest.so: lrtest.o 187lrtest.so: lrtest.o
172 $(CC) $(LIBFLAG) -o $@ -L$(LUA_LIBDIR) $<
173 188
174lrtest.o: lrtest.c 189lrtest.o: lrtest.c
175 $(CC) -c $(CFLAGS) -I$(LUA_INCDIR) $< -o $@
176 190
177install: lrtest.so lrtest.lua 191install: 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
182There is of course a lot more to a proper Makefile and rockspec, this is only 196There 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
186the same way. Check the other documentation, especially [Rockspec 200the same way. Check the other documentation, especially [Rockspec
187format](rockspec_format.md) and [Recommended practices for 201format](rockspec_format.md) and [Recommended practices for
188Makefiles](recommended_practices_for_makefiles.md), for details. 202Makefiles](recommended_practices_for_makefiles.md), for details.
189
190