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 <>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 -, 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

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

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)

DFLAGS_$(d) := -g -Wall -Wextra
CFLAGS_$(d) := -std=c99 -O3 -fPIC $(DFLAGS_$(d))

ifeq ($(shell uname -s),Linux)
LDFLAGS_$(d) := -lreadline -lncurses -ldl -lm
ifeq ($(shell uname -s),Darwin)
LDFLAGS_$(d) := -lreadline
LDFLAGS_$(d) := 

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

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)/ $(OBJS_$(d))
	$(CC) $(CFLAGS_$(@D)) $(CPPFLAGS_$(@D)) -o $@ $^ $(SOFLAGS_$(@D)) $(LDFLAGS_$(@D))

all: $(d)/


lua: $(d)/

.PHONY: cleanall cleanall~ $(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)