diff --git a/.gitignore b/.gitignore index 4c9fc34..ed2f798 100644 --- a/.gitignore +++ b/.gitignore @@ -4,4 +4,5 @@ include/grammatical.h src/parser/grammatical.cpp include/lexical.h src/parser/lexical.cpp -src/makemap \ No newline at end of file +src/makemap +modules/test/* diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..0b1b6c8 --- /dev/null +++ b/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 + + diff --git a/src/Makefile b/src/Makefile index cf63006..01c3f7f 100644 --- a/src/Makefile +++ b/src/Makefile @@ -13,8 +13,8 @@ SOURCE = $(wildcard *.cpp) parser/lexical.cpp parser/grammatical.cpp DEPENDS = $(subst .cpp,.d,$(SOURCE)) OBJECTS = $(subst .cpp,.o,$(SOURCE)) -makemap: $(OBJECTS) - $(CC) $(LDFLAGS) -o $@ $(OBJECTS) +makemap: $(OBJECTS) $(MODOBJECTS) + $(CC) $(LDFLAGS) $(MODLIBS) -o $@ $(OBJECTS) $(MODOBJECTS) include $(DEPENDS)