Permalink
Browse files

Merged Makefiles

As described in [1], a single Makefile is much faster and conveniet
than executing make on every single sub-directory. In the future the
Makefile could be split up into several Makefiles which are included
from the main Makefile, if the main Makefile gets too complex.

[1] http://aegis.sourceforge.net/auug97.pdf
  • Loading branch information...
1 parent ccb0dc7 commit 5c49bca2ca163bb75286718ff6a01de8be62aa85 @ott ott committed with Joshua Haberman Mar 17, 2010
Showing with 86 additions and 139 deletions.
  1. +86 −39 Makefile
  2. +0 −14 docs/Makefile
  3. +0 −9 lang_ext/Makefile
  4. +0 −36 lang_ext/lua/Makefile
  5. +0 −17 runtime/Makefile
  6. +0 −24 utilities/Makefile
View
125 Makefile
@@ -1,58 +1,105 @@
+DESTDIR ?=
+PREFIX ?= /usr
+BINDIR := $(DESTDIR)$(PREFIX)/bin
+LIBDIR := $(DESTDIR)$(PREFIX)/lib
+INCDIR := $(DESTDIR)$(PREFIX)/include
-# Change these if necessary.
-export CC=gcc
-export AR=ar
-export CFLAGS=-Wall -g -O6 -std=c99
+IMGDIR := /usr/share/asciidoc/images
+
+CFLAGS += -std=c99
+CPPFLAGS := -Iruntime/include
ifeq ($(shell uname), Darwin)
- export LUA_INCLUDE=-I/usr/include/lua5.1
- export LUA_LINK=-L/usr/local/lib -llua
+ CPPFLAGS += -I/usr/include/lua5.1
+ LDFLAGS := -L/usr/local/lib -llua
else
- export LUA_INCLUDE=`pkg-config --silence-errors --cflags lua || pkg-config --cflags lua5.1`
- export LUA_LINK=`pkg-config --silence-errors --libs lua || pkg-config --libs lua5.1`
+ CFLAGS += $(strip $(shell pkg-config --silence-errors --cflags lua || pkg-config --cflags lua5.1))
+ LDFLAGS := $(strip $(shell pkg-config --silence-errors --libs lua || pkg-config --libs lua5.1))
endif
+ADFLAGS := -a toc -a toclevels=3 -a icons -a iconsdir=.
+
+export LUA_PATH := $(CURDIR)/compiler/?.lua;$(CURDIR)/sketches/?.lua;$(CURDIR)/tests/?.lua
+export LUA_CPATH := $(CURDIR)/lang_ext/lua/?.so
-SUBDIRS=runtime lang_ext utilities
-ALLSUBDIRS=$(SUBDIRS) docs
-TARGETS=all clean docs doc default install runtime test utilities
-PREFIX=/usr/local
+RTSRC := $(wildcard runtime/*.c)
+RTOBJ := $(RTSRC:.c=.o)
+EXTSRC := $(wildcard lang_ext/lua/*.c)
+EXTOBJ := $(EXTSRC:.c=.o)
+LUASRC := $(wildcard compiler/*.lua) $(wildcard compiler/bootstrap/*.lua)
+SRC := $(RTSRC) $(EXTSRC) $(wildcard utilities/*.c)
+OBJ := $(SRC:.c=.o)
+DEP := $(SRC:.c=.d)
+UTIL := utilities/bitcode_dump utilities/srlua utilities/srlua-glue
+PROG := gzlc utilities/gzlparse
+LUALIB := lang_ext/lua/bc_read_stream.so lang_ext/lua/gazelle.so
+LIB := $(LUALIB) runtime/libgazelle.a
+INC := $(wildcard runtime/include/gazelle/*.h)
+IMG := $(foreach img,$(wildcard $(IMGDIR)/*.png),docs/images/$(notdir $(img)))
-.PHONY: $(TARGETS)
+.PHONY: all clean doc install test
-default: lua_path gzlc
- @for dir in $(SUBDIRS) ; do $(MAKE) -w -C $$dir $@ || break ; done
+%.d: %.c
+ $(CC) $(CFLAGS) $(CPPFLAGS) -MM -MT $(patsubst %.c,%.o,$<) -o $@ $^
-runtime:
- $(MAKE) -w -C runtime
+%.so: %.o
+ $(CC) $(LDFLAGS) -shared -o $@ $^
-utilities: runtime
- $(MAKE) -w -C utilities
+all: $(UTIL) $(LIB) $(PROG)
-all: lua_path doc
- @for dir in $(ALLSUBDIRS) ; do $(MAKE) -w -C $$dir $@ || break ; done
+ifneq ($(filter-out clean doc test,$(MAKECMDGOALS)),)
+ -include $(DEP)
+endif
-doc: docs
-docs:
- @$(MAKE) -w -C docs
+$(RTOBJ) $(EXTOBJ): CFLAGS += -fPIC
-clean:
- rm -f lua_path *.dot *.png docs/manual.html docs/*.png gzlc gzlc.out
- @for dir in $(ALLSUBDIRS) ; do make -w -C $$dir $@; done
+lang_ext/lua/bc_read_stream.so: lang_ext/lua/bc_read_stream.o \
+ runtime/bc_read_stream.o
+
+runtime/libgazelle.a(%.o): %.o
+ $(AR) cr $@ $^
+
+runtime/libgazelle.a: runtime/libgazelle.a($(RTOBJ))
+ ranlib $@
+
+utilities/bitcode_dump: utilities/bitcode_dump.o $(RTOBJ)
-lua_path: Makefile
- echo "export LUA_PATH=`pwd`/compiler/?.lua\\;`pwd`/sketches/?.lua\\;`pwd`/tests/?.lua" > lua_path
- echo export LUA_CPATH=`pwd`/lang_ext/lua/?.so >> lua_path
+utilities/gzlparse: utilities/gzlparse.o $(RTOBJ)
-gzlc: utilities
- lua utilities/luac.lua compiler/gzlc -L compiler/*.lua compiler/bootstrap/*.lua sketches/pp.lua sketches/dump_to_html.lua
- ./utilities/srlua-glue ./utilities/srlua luac.out gzlc
+gzlc: utilities/luac.lua utilities/srlua utilities/srlua-glue \
+ compiler/gzlc | $(LUASRC) sketches/pp.lua sketches/dump_to_html.lua
+ lua utilities/luac.lua compiler/gzlc -L $|
+ ./utilities/srlua-glue ./utilities/srlua luac.out $@
chmod a+x gzlc
-install: gzlc runtime/libgazelle.a
- mkdir -p $(PREFIX)/bin
- cp gzlc $(PREFIX)/bin
- cp utilities/gzlparse $(PREFIX)/bin
- mkdir -p $(PREFIX)/include
- cp -R runtime/include/gazelle $(PREFIX)/include
+docs/images:
+ mkdir -p docs/images
+
+docs/images/%.png: /usr/share/asciidoc/images/%.png docs/images
+ cp $(filter-out docs/images, $^) $@
+
+docs/manual.html: docs/gzl-rtn-graph docs/manual.conf docs/manual.txt
+ (cd docs; asciidoc -o manual.html manual.txt)
+
+doc: $(IMG) docs/images docs/manual.html
test:
lua tests/run_tests.lua
+
+install: gzlc utilities/gzlparse runtime/libgazelle.a $(INC)
+ install -d -o root -g root $(BINDIR)
+ install -m 0755 -o root -g root gzlc $(BINDIR)
+ install -m 0755 -o root -g root utilities/gzlparse $(BINDIR)
+ install -d -o root -g root $(LIBDIR)
+ install -m 0644 -o root -g root runtime/libgazelle.a $(LIBDIR)
+ install -d $(INCDIR)/gazelle
+ install -m 0644 -o root -g root $(INC) $(INCDIR)/gazelle
+
+clean:
+ $(RM) $(OBJ)
+ $(RM) $(DEP)
+ $(RM) $(PROG)
+ $(RM) $(UTIL)
+ $(RM) $(LIB)
+ $(RM) luac.out
+ $(RM) -r docs/images
+ $(RM) docs/manual.html
+ $(RM) docs/*.dot docs/*.png
View
@@ -1,14 +0,0 @@
-
-.PHONY: all default images
-
-default: manual.html images
-all: default
-
-manual.html: manual.txt manual.conf gzl-rtn-graph Makefile
- asciidoc -a toc -a toclevels=3 -a icons -a iconsdir=. manual.txt
-
-images:
- mkdir -p images && cp -f /usr/share/asciidoc/images/*.png images
-
-clean:
- rm -rf *.png *.html images
View
@@ -1,9 +0,0 @@
-
-CFLAGS=-Wall -g -O6 -std=c99
-SUBDIRS=lua
-TARGETS=default all clean
-
-.PHONY: $(TARGETS)
-$(TARGETS):
- @for dir in $(SUBDIRS) ; do make -w -C $$dir $@; done
-
View
@@ -1,36 +0,0 @@
-
-CFLAGS=-Wall -g -O6 -std=c99
-EXTS=bc_read_stream.so gazelle.so
-
-default: $(EXTS)
-
-all: default
-
-clean:
- rm -f $(EXTS) bc_read_stream.o gazelle.o
-
-.PHONY: all clean default
-
-bc_read_stream.o: bc_read_stream.c ../../runtime/include/gazelle/bc_read_stream.h
- gcc $(CFLAGS) -o bc_read_stream.o -c bc_read_stream.c -I../../runtime/include -I/usr/include/lua5.1
-
-gazelle.o: gazelle.c ../../runtime/include/gazelle/bc_read_stream.h ../../runtime/include/gazelle/parse.h
- gcc $(CFLAGS) -o gazelle.o -c gazelle.c -I../../runtime/include -I/usr/include/lua5.1
-
-ifeq ($(shell uname), Darwin)
-
-bc_read_stream.so: ../../runtime/bc_read_stream.o bc_read_stream.o
- gcc -o bc_read_stream.so -undefined dynamic_lookup -bundle bc_read_stream.o ../../runtime/bc_read_stream.o
-
-gazelle.so: ../../runtime/parse.o ../../runtime/bc_read_stream.o ../../runtime/load_grammar.o gazelle.o
- gcc -o gazelle.so -undefined dynamic_lookup -bundle gazelle.o ../../runtime/bc_read_stream.o ../../runtime/parse.o ../../runtime/load_grammar.o
-
-else
-
-bc_read_stream.so: ../../runtime/bc_read_stream.o bc_read_stream.o
- gcc -o bc_read_stream.so -shared bc_read_stream.o ../../runtime/bc_read_stream.o
-
-gazelle.so: ../../runtime/bc_read_stream.o ../../runtime/load_grammar.o gazelle.o
- gcc -o gazelle.so -shared gazelle.o ../../runtime/bc_read_stream.o ../../runtime/load_grammar.o
-
-endif
View
@@ -1,17 +0,0 @@
-
-OBJS=bc_read_stream.o parse.o load_grammar.o
-
-default: libgazelle.a
-
-clean:
- rm -f libgazelle.a $(OBJS)
-
-.PHONY: all clean
-
-$(OBJS): include/gazelle/parse.h include/gazelle/bc_read_stream.h
-
-$(OBJS): %.o: %.c include/gazelle/parse.h include/gazelle/bc_read_stream.h
- $(CC) $(CFLAGS) -Iinclude -o $@ -c $<
-
-libgazelle.a: $(OBJS)
- $(AR) rcs libgazelle.a $(OBJS)
View
@@ -1,24 +0,0 @@
-
-default: bitcode_dump gzlparse srlua-glue srlua
-all: default
-
-clean:
- rm -rf bitcode_dump.o bitcode_dump gzlparse.o gzlparse
-
-bitcode_dump.o: bitcode_dump.c ../runtime/include/gazelle/bc_read_stream.h
- $(CC) $(CFLAGS) -o bitcode_dump.o -c bitcode_dump.c -I../runtime/include
-
-bitcode_dump: bitcode_dump.o ../runtime/libgazelle.a
- $(CC) -o bitcode_dump bitcode_dump.o ../runtime/bc_read_stream.o
-
-gzlparse.o: gzlparse.c ../runtime/include/gazelle/bc_read_stream.h ../runtime/include/gazelle/parse.h
- $(CC) $(CFLAGS) -o gzlparse.o -c gzlparse.c -I../runtime/include
-
-gzlparse: gzlparse.o ../runtime/libgazelle.a
- $(CC) -o gzlparse gzlparse.o ../runtime/libgazelle.a
-
-srlua-glue:
- $(CC) -o srlua-glue srlua-glue.c $(LUA_INCLUDE) $(LUA_LINK)
-
-srlua:
- $(CC) -o srlua srlua.c $(LUA_INCLUDE) $(LUA_LINK)

3 comments on commit 5c49bca

Owner

Hi @ott ,

I'm really sorry to have to ask you this after so long, but to be in compliance with Google's open-source policy would it be possible for you to sign Google CLA? https://cla.developers.google.com/

If you would rather not I understand. In that case I would have to remove the code from the repo.

Let me know, thanks!
Josh

Contributor
ott replied Jul 9, 2015

If I'm not mistaken, you need a Google Account to sign the CLA. I'm willing to sign the CLA for that particular commit or gazelle in general but I don't want to have a Google Account. Can you provide me with the CLA as a PDF that I can print, sign and send to your legal department?

Owner

Hi there, I looked into this and unfortunately it is not possible to sign the CLA without a Google Account.

I appreciate your consideration and I respect your wishes not to have a Google Account. I will unfortunately need to remove your code contributions from this repository.

Please sign in to comment.