Browse Source

Build system for modules

test
Michael Uleysky 9 years ago
parent
commit
705b220ae1
  1. 3
      .gitignore
  2. 77
      Makefile
  3. 4
      src/Makefile

3
.gitignore vendored

@ -4,4 +4,5 @@ include/grammatical.h
src/parser/grammatical.cpp src/parser/grammatical.cpp
include/lexical.h include/lexical.h
src/parser/lexical.cpp src/parser/lexical.cpp
src/makemap src/makemap
modules/test/*

77
Makefile

@ -0,0 +1,77 @@
OPTFLAGS=-O2 -flto -g
EXPORTFLAGS=-fvisibility=hidden -fpic -Wl,--export-dynamic
CPPFLAGS=-std=gnu++11 -I../include -I../../include
LIBSFLAGS=
WARNFLAGS=-Wall
CFLAGS=$(OPTFLAGS) $(EXPORTFLAGS) $(WARNFLAGS) $(CPPFLAGS)
LDFLAGS=$(OPTFLAGS) $(EXPORTFLAGS) $(WARNFLAGS) $(LIBSFLAGS)
CC=g++
ifdef MODULE
-include makemod
SOURCE = $(wildcard *.cpp)
DEPENDS = $(subst .cpp,.d,$(SOURCE))
OBJECTS = $(subst .cpp,.o,$(SOURCE))
../../bin/$(MODULE).so: $(OBJECTS)
$(CC) $(LDFLAGS) $(MODLIBS) -shared -o $@ $(OBJECTS)
%.o: %.cpp
$(CC) -c $(CFLAGS) -o $@ $<
%.d: %.cpp
$(CC) $(CPPFLAGS) -MM -MT $(subst .cpp,.o,$<) $< | sed 's%\(^.*\):%\1 $@ :%g' >$@
include $(DEPENDS)
clean:
rm -f *.d *.o
distclean: clean
rm -f ../../bin/$(MODULE).so
else
MODDIRS = $(wildcard modules/*)
MODDIRS+= $(wildcard extramodules/*)
MODSOURCE = $(wildcard modules/*/*.cpp extramodules/*/*.cpp)
MODHEADERS = $(wildcard modules/*/*.h extramodules/*/*.h)
MODOBJECTS = $(subst .cpp,.o,$(MODSOURCE))
MODDEPS = $(subst .cpp,.d,$(MODSOURCE))
modules: $(MODSOURCE) $(MODHEADERS)
for dir in $(MODDIRS); do\
make -C $$dir -f ../../Makefile MODULE=$${dir/*\//};\
done
all: modules makemap
makemap: $(MODOBJECTS)
make -C src MODLIBS="$(MODLIBS)" MODOBJECTS="$(patsubst %,../%,$(MODOBJECTS))";
$(MODOBJECTS): $(MODSOURCE) $(MODHEADERS)
for dir in $(MODDIRS); do\
make -C $$dir -f ../../Makefile MODULE=$${dir/*\//};\
done
clean:
for dir in $(MODDIRS); do\
make -C $$dir -f ../../Makefile MODULE=$${dir/*\//} clean;\
done
make -C src clean
distclean:
for dir in $(MODDIRS); do\
make -C $$dir -f ../../Makefile MODULE=$${dir/*\//} distclean;\
done
make -C src distclean
-include $(wildcard modules/*/makemod) $(wildcard extramodules/*/makemod)
endif

4
src/Makefile

@ -13,8 +13,8 @@ SOURCE = $(wildcard *.cpp) parser/lexical.cpp parser/grammatical.cpp
DEPENDS = $(subst .cpp,.d,$(SOURCE)) DEPENDS = $(subst .cpp,.d,$(SOURCE))
OBJECTS = $(subst .cpp,.o,$(SOURCE)) OBJECTS = $(subst .cpp,.o,$(SOURCE))
makemap: $(OBJECTS) makemap: $(OBJECTS) $(MODOBJECTS)
$(CC) $(LDFLAGS) -o $@ $(OBJECTS) $(CC) $(LDFLAGS) $(MODLIBS) -o $@ $(OBJECTS) $(MODOBJECTS)
include $(DEPENDS) include $(DEPENDS)

Loading…
Cancel
Save