lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


On 6 June 2011 18:30, Luiz Henrique de Figueiredo
<lhf@tecgraf.puc-rio.br> wrote:
>> I've just been building Lua 5.2 alpha and trying to change some
>> built-in symbol defaults using MYCFLAGS. This turns out to be
>> impossible, because each machine-specific target, e.g. linux,
>> redefines MYCFLAGS. Is this intentional?
>
> No, not intentional, but it's a known limitation.
> Anyone wishing to do anything more complicated should edit the Makefile,
> which is not too hard, is it?

That's what I tried, but I was immediately defeated. Here's why:

Under "# == CHANGE THE SETTINGS BELOW TO SUIT YOUR ENVIRONMENT
=======================" I found MYCFLAGS. So I changed it. But then
when I run "make linux", I find I'm executing:

linux:
	$(MAKE) $(ALL) MYCFLAGS="-DLUA_USE_LINUX" MYLIBS="-Wl,-E -ldl -lreadline"

Oops! MYCFLAGS is redefined. If on the other hand that line is changed to read:

linux:
	$(MAKE) $(ALL) MYCFLAGS="$MYCFLAGS -DLUA_USE_LINUX" MYLIBS="-Wl,-E
-ldl -lreadline"

then it works, and if I'm happy to use the command line I don't even
have to edit the makefile, I can do:

make linux MYCFLAGS="whatever"

> BTW, I never did get any final feedback on what platforms are common *today*,
> as opposed to the ones that were common in 2006, when Lua 5.1 was released:
>   aix ansi bsd freebsd generic linux macosx mingw posix solaris

I only ever use Linux, same as 2006.

One more suggestion: move the "generic" platform to the top or bottom,
rather than keeping it in alphabetic order, as one usually does with
"default" in a switch.

I attach a patch against lua-5.2.0-alpha/src/Makefile which implements
these changes, for MYCFLAGS, MYLIBS and MYLDFLAGS. Now, I can either
edit the Makefile or do:

make linux MYCFLAGS='-DLUA_INIT=\\\"LUA52_INIT\\\"
-DLUA_PATH=\\\"LUA52_PATH\\\" -DLUA_CPATH=\\\"LUA52_CPATH\\\"'

and I get the desired result. The same applies to MYLIBS and
MYLDFLAGS. If a user desires to override a variable, not just add to
it, then CFLAGS, LIBS and LDFLAGS can be used instead of the MY*
versions.

I would further suggest that you encourage use of command-line
variable settings rather than Makefile editing, as it preserves the
advantages of pristine source: diffs do not include per-user
configuration, and the user is encouraged to keep their changes
separate, which makes them easier to read and maintain.

-- 
http://rrt.sc3d.org
diff -Nur lua-5.2.0-alpha/src/Makefile lua-5.2.0-alpha-cflags//src/Makefile
--- lua-5.2.0-alpha/src/Makefile	2010-11-12 19:42:17.000000000 +0000
+++ lua-5.2.0-alpha-cflags/src/Makefile	2011-06-07 13:44:32.980134530 +0100
@@ -9,6 +9,7 @@
 CC= gcc
 CFLAGS= -O2 -Wall -DLUA_COMPAT_ALL $(MYCFLAGS)
 LIBS= -lm $(MYLIBS)
+LDFLAGS= $(MYLDFLAGS)
 
 AR= ar rcu
 RANLIB= ranlib
@@ -53,10 +54,10 @@
 	$(RANLIB) $@
 
 $(LUA_T): $(LUA_O) $(LUA_A)
-	$(CC) -o $@ $(MYLDFLAGS) $(LUA_O) $(LUA_A) $(LIBS)
+	$(CC) -o $@ $(LDFLAGS) $(LUA_O) $(LUA_A) $(LIBS)
 
 $(LUAC_T): $(LUAC_O) $(LUA_A)
-	$(CC) -o $@ $(MYLDFLAGS) $(LUAC_O) $(LUA_A) $(LIBS)
+	$(CC) -o $@ $(LDFLAGS) $(LUAC_O) $(LUA_A) $(LIBS)
 
 clean:
 	$(RM) $(ALL_T) $(ALL_O)
@@ -82,36 +83,37 @@
 	@echo "Please do 'make PLATFORM' where PLATFORM is one of these:"
 	@echo "   $(PLATS)"
 
+generic:
+	$(MAKE) $(ALL)
+
 aix:
-	$(MAKE) $(ALL) CC="xlc" CFLAGS="-O2 -DLUA_USE_POSIX -DLUA_USE_DLOPEN" MYLIBS="-ldl" MYLDFLAGS="-brtl -bexpall"
+	$(MAKE) $(ALL) CC="xlc" MYCFLAGS="$(MYCFLAGS) -O2 -DLUA_USE_POSIX -DLUA_USE_DLOPEN" MYLIBS="$(MYLIBS) -ldl" LDFLAGS="$(LDFLAGS) -brtl -bexpall"
 
 ansi:
-	$(MAKE) $(ALL) MYCFLAGS="-DLUA_ANSI"
+	$(MAKE) $(ALL) MYCFLAGS="$(MYCFLAGS) -DLUA_ANSI"
 
 bsd:
-	$(MAKE) $(ALL) MYCFLAGS="-DLUA_USE_POSIX -DLUA_USE_DLOPEN" MYLIBS="-Wl,-E"
+	$(MAKE) $(ALL) MYCFLAGS="$(MYCFLAGS) -DLUA_USE_POSIX -DLUA_USE_DLOPEN" MYLIBS="$(MYLIBS) -Wl,-E"
 
 freebsd:
-	$(MAKE) $(ALL) MYCFLAGS="-DLUA_USE_LINUX" MYLIBS="-Wl,-E -lreadline"
-
-generic: $(ALL)
+	$(MAKE) $(ALL) MYCFLAGS="$(MYCFLAGS) -DLUA_USE_LINUX" MYLIBS="$(MYLIBS) -Wl,-E -lreadline"
 
 linux:
-	$(MAKE) $(ALL) MYCFLAGS="-DLUA_USE_LINUX" MYLIBS="-Wl,-E -ldl -lreadline"
+	$(MAKE) $(ALL) MYCFLAGS="$(MYCFLAGS) -DLUA_USE_LINUX" MYLIBS="$(MYLIBS) -Wl,-E -ldl -lreadline"
 
 macosx:
-	$(MAKE) $(ALL) MYCFLAGS="-DLUA_USE_MACOSX" MYLIBS="-lreadline"
+	$(MAKE) $(ALL) MYCFLAGS="$(MYCFLAGS) -DLUA_USE_MACOSX" MYLIBS="$(MYLIBS) -lreadline"
 
 mingw:
 	$(MAKE) "LUA_A=lua52.dll" "LUA_T=lua.exe" \
 	"AR=$(CC) -shared -o" "RANLIB=strip --strip-unneeded" \
-	"MYCFLAGS=-DLUA_BUILD_AS_DLL" "MYLIBS=" "MYLDFLAGS=-s" lua.exe
+	"MYCFLAGS=$(MYCFLAGS) -DLUA_BUILD_AS_DLL" "MYLIBS=$(MYLIBS)" "MYLDFLAGS=$(MYLDFLAGS) -s" lua.exe
 
 posix:
-	$(MAKE) $(ALL) MYCFLAGS="-DLUA_USE_POSIX"
+	$(MAKE) $(ALL) MYCFLAGS="$(MYCFLAGS) -DLUA_USE_POSIX"
 
 solaris:
-	$(MAKE) $(ALL) MYCFLAGS="-DLUA_USE_POSIX -DLUA_USE_DLOPEN" MYLIBS="-ldl"
+	$(MAKE) $(ALL) MYCFLAGS="$(MYCFLAGS) -DLUA_USE_POSIX -DLUA_USE_DLOPEN" MYLIBS="$(MYLIBS) -ldl"
 
 # list targets that do not create files (but not all makes understand .PHONY)
 .PHONY: all $(PLATS) default o a clean depend echo none