lua-users home
lua-l archive

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


On Thu, Nov 10, 2011 at 05:37:14PM +0000, Robert Raschke wrote:
> On Thu, Nov 10, 2011 at 4:17 PM, Kevin T. Ryan <kevin.t.ryan@gmail.com>wrote:
> 
> > Hi there -
> >
> > I know this isn't really related to Lua per se, but I've seen people
> > comment on good v. bad makefiles (I thought it was somewhere in this
> > thread - http://lua-users.org/lists/lua-l/2011-10/msg01068.html, but I
> > can't find it now).  At some point, I thought someone had mentioned
> > that LuaJIT presented an excellent example of a good makefile, but I'm
> > not sure why (or, better said, how one would make that observation).
> > Thus, I'm wondering if there are any tutorials / books / etc. anyone
> > would recommend that would help me in that regard?  Most of the
> > tutorials I've come across only cover the basics and I don't feel like
> > they go into too much detail of what represents "good practices" vs
> > "bad" ...
> >
> > Thanks in advance, ktr
> >
> >
> Not a book or tutorial, but required reading for anyone using make:
> Recursive Make Considered Harmful, Peter Miller
> http://aegis.sourceforge.net/auug97.pdf
> 

If anyone is interested in what a non-recursive [GNU] makefile looks like
for Lua, here's something I threw together last night in a fit of
frustration. (So beware if you just copy+paste. For one thing using the
$(wildcard) and $(shell) macros aren't wise when included in huge build
trees because they can add substantial latency on every invocation.)

It follows the inclusion and namespace protocol described at

	http://evbergen.home.xs4all.nl/nonrecursive-make.html

At least, I think it does; it's been awhile since I've read that page and
my form may have evolved over the years.

include $(prologue)

CPPFLAGS_$(d) := -DLUA_COMPAT_ALL -D_GNU_SOURCE -D_DARWIN_C_SOURCE -D_BSD_SOURCE -I$(d)
DFLAGS_$(d) := -g -Wall -Wextra
CFLAGS_$(d) := -std=c99 -O3 -fPIC $(DFLAGS_$(d))

ifeq ($(shell uname -s),Linux)
CPPFLAGS_$(d) += -DLUA_USE_LINUX
LDFLAGS_$(d) := -lreadline -lncurses -ldl -lm
else
ifeq ($(shell uname -s),Darwin)
CPPFLAGS_$(d) += -DLUA_USE_MACOSX
LDFLAGS_$(d) := -lreadline
else
CPPFLAGS_$(d) += -DLUA_USE_POSIX
LDFLAGS_$(d) := 
endif
endif

ifeq ($(shell uname -s),Darwin)
SOFLAGS_$(d) = -dynamiclib
else
SOFLAGS_$(d) := -shared
endif

SRCS_$(d) := $(filter-out $(d)/lua.c $(d)/luac.c, $(wildcard $(d)/*.c))
OBJS_$(d) := $(SRCS_$(d):.c=.o)

$(OBJS_$(d)): %.o: %.c
	$(CC) $(CFLAGS_$(@D)) $(CPPFLAGS_$(@D)) -c -o $@ $^

$(d)/liblua.so: $(OBJS_$(d))
	$(CC) $(CFLAGS_$(@D)) $(CPPFLAGS_$(@D)) -o $@ $^ $(SOFLAGS_$(@D)) $(LDFLAGS_$(@D))

all: $(d)/liblua.so

.INTERMEDIATE: lua

lua: $(d)/liblua.so

.PHONY: cleanall cleanall~ $(d)/clean $(d)/clean~

$(d)/clean:
	rm -fr $(@D)/*.o $(@D)/*.so $(@D)/*.dSYM

$(d)/clean~: $(d)/clean
	rm -f $(@D)/*~

cleanall: $(d)/clean

cleanall~: $(d)/clean~

include $(epilogue)