From f38362d81293d345393736fcb55afdbfdf1f234d Mon Sep 17 00:00:00 2001
From: sebastien <sebastien@ac1d8469-bf42-47a9-8791-bf33cf982152>
Date: Thu, 12 Mar 2009 11:02:56 +0000
Subject: [PATCH] trunk preprocessor: simplified build system (only one
 Makefile now)

git-svn-id: https://www.dynare.org/svn/dynare/trunk@2455 ac1d8469-bf42-47a9-8791-bf33cf982152
---
 Makefile         | 102 ++++++++++++++++++++++++++++++++++++-----------
 Makefile.include |  36 -----------------
 macro/Makefile   |  27 -------------
 3 files changed, 79 insertions(+), 86 deletions(-)
 delete mode 100644 Makefile.include
 delete mode 100644 macro/Makefile

diff --git a/Makefile b/Makefile
index 40d47a87..7b4477c9 100644
--- a/Makefile
+++ b/Makefile
@@ -1,16 +1,39 @@
-include Makefile.include
+CXXFLAGS = -Wall
 
 ifeq ($(shell uname -o), Cygwin)
-	DYNARE_M = dynare_m.exe
+# Detection of uninitialized variables is buggy in Cygwin and generates spurious warnings
+CXXFLAGS += -Wno-uninitialized
+CXXFLAGS += -mno-cygwin
+endif
+
+ifeq ($(CROSS_WIN32), yes)
+CXX = i586-mingw32msvc-g++
+AR = i586-mingw32msvc-ar
+# Detection of uninitialized variables is buggy in MinGW and generates spurious warnings
+CXXFLAGS += -Wno-uninitialized
+endif
+
+ifeq ($(DEBUG),yes)
+CXXFLAGS += -ggdb
 else
-	DYNARE_M = dynare_m
+CXXFLAGS += -O3
+endif
+
+ifeq ($(VALGRIND), yes)
+CXXFLAGS = -Wall -O -g -fno-inline
+endif
+
+ifeq ($(shell uname -o), Cygwin)
+DYNARE_M = dynare_m.exe
+else
+DYNARE_M = dynare_m
 endif
 
 ifeq ($(CROSS_WIN32), yes)
-	DYNARE_M = dynare_m.exe
+DYNARE_M = dynare_m.exe
 endif
 
-OBJS = \
+MAIN_OBJS = \
 	DynareFlex.o \
 	DynareBison.o \
 	ComputingTasks.o \
@@ -36,35 +59,65 @@ OBJS = \
 	DynareMain.o \
 	DynareMain2.o
 
+MACRO_OBJS = \
+	macro/MacroFlex.o \
+	macro/MacroBison.o \
+	macro/MacroDriver.o \
+	macro/MacroValue.o
+
+$(MAIN_OBJS) $(MAIN_OBJS:.o=.d): CPPFLAGS = -Iinclude
 
-# Build rules
 
-all: all-recursive $(DYNARE_M)
+# Build rules
 
-all-recursive:
-	make -C macro
+.PHONY: all
+all: $(DYNARE_M)
 
-$(DYNARE_M): $(OBJS) macro/libmacro.a
-	$(CXX) $(CXXFLAGS) -o $(DYNARE_M) $(OBJS) -Lmacro -lmacro
+$(DYNARE_M): $(MAIN_OBJS) $(MACRO_OBJS)
+	$(CXX) $(CXXFLAGS) -o $(DYNARE_M) $(MAIN_OBJS) $(MACRO_OBJS)
 	cp $(DYNARE_M) ../matlab/
 
 
-# Dependencies
-
--include $(OBJS:.o=.P)
+# Build rules for Flex and Bison files
 
-DynareFlex.cc: DynareFlex.ll include/DynareBison.hh include/ParsingDriver.hh
+DynareFlex.cc: DynareFlex.ll
 	flex -oDynareFlex.cc DynareFlex.ll
 
-DynareBison.cc include/DynareBison.hh: DynareBison.yy include/ParsingDriver.hh
+DynareBison.cc include/DynareBison.hh include/location.hh include/stack.hh include/position.hh: DynareBison.yy
 	bison --verbose -o DynareBison.cc DynareBison.yy
 	mv DynareBison.hh location.hh stack.hh position.hh include/
 
+macro/MacroFlex.cc: macro/MacroFlex.ll
+	cd macro && flex -oMacroFlex.cc MacroFlex.ll
+
+macro/MacroBison.cc macro/MacroBison.hh macro/location.hh macro/stack.hh macro/position.hh: macro/MacroBison.yy
+	cd macro && bison --verbose -o MacroBison.cc MacroBison.yy
+
+
+# Dependencies
+
+# General rule for creating per-source dependencies Makefile
+# We use -MG to avoid failing on generated headers (MacroBison.hh, DynareBison.hh)
+# As a consequence, these headers are included without path-prefix
+%.d: %.cc
+	@set -e; rm -f $@; \
+	 $(CXX) -MM -MG $(CPPFLAGS) $< > $@.$$$$; \
+	 sed 's,\($*\)\.o[ :]*,\1.o $@ : ,g' < $@.$$$$ > $@; \
+	 rm -f $@.$$$$
+
+# These files are included in the .d files without their path, so we force them
+vpath DynareBison.hh include
+vpath MacroBison.hh macro
+
+-include $(MAIN_OBJS:.o=.d)
+-include $(MACRO_OBJS:.o=.d)
+
 
 # Clean
 
-clean: clean-recursive
-	rm -f *.o *.P \
+.PHONY: clean
+clean:
+	rm -f *.o *.d \
 		*~ include/*~ \
 		DynareFlex.cc \
 		DynareBison.output \
@@ -74,8 +127,11 @@ clean: clean-recursive
 		include/location.hh \
 		include/DynareBison.hh \
 		$(DYNARE_M)
-
-clean-recursive:
-	make -C macro clean
-
-.PHONY: all all-recursive clean clean-recursive
+	cd macro && rm -f *.o *.d *~ \
+		MacroFlex.cc \
+		MacroBison.output \
+		MacroBison.cc \
+		MacroBison.hh \
+		location.hh \
+		stack.hh \
+		position.hh
diff --git a/Makefile.include b/Makefile.include
deleted file mode 100644
index 0a3cdbc4..00000000
--- a/Makefile.include
+++ /dev/null
@@ -1,36 +0,0 @@
-CXXFLAGS = -Wall
-
-ifeq ($(shell uname -o), Cygwin)
-	# Detection of uninitialized variables is buggy in Cygwin and generates spurious warnings
-	CXXFLAGS += -Wno-uninitialized
-	CXXFLAGS += -mno-cygwin
-endif
-
-ifeq ($(CROSS_WIN32), yes)
-	CXX = i586-mingw32msvc-g++
-	AR = i586-mingw32msvc-ar
-	# Detection of uninitialized variables is buggy in MinGW and generates spurious warnings
-	CXXFLAGS += -Wno-uninitialized
-endif
-
-ifeq ($(DEBUG),yes)
-	CXXFLAGS += -ggdb
-else
-	CXXFLAGS += -O3
-endif
-
-ifeq ($(VALGRIND), yes)
-	CXXFLAGS = -Wall -O -g -fno-inline
-endif
-
-# General rule for compilation
-%.o : %.cc
-	$(CXX) $(CXXFLAGS) -MD -I include -c $<
-	@cp $*.d $*.P; \
-	  sed -e 's/#.*//' -e 's/^[^:]*: *//' -e 's/ *\\$$//' \
-	      -e '/^$$/ d' -e 's/$$/ :/' < $*.d >> $*.P; \
-	  rm -f $*.d
-
-# Local variables:
-# mode: makefile
-# End:
diff --git a/macro/Makefile b/macro/Makefile
deleted file mode 100644
index 8ce93aa9..00000000
--- a/macro/Makefile
+++ /dev/null
@@ -1,27 +0,0 @@
-include ../Makefile.include
-
-OBJ = MacroFlex.o MacroBison.o MacroDriver.o MacroValue.o
-
-libmacro.a: $(OBJ)
-	$(AR) crs libmacro.a $(OBJ)
-
--include $(OBJ:.o=.P)
-
-MacroFlex.cc: MacroFlex.ll MacroBison.hh MacroDriver.hh
-	flex -oMacroFlex.cc MacroFlex.ll
-
-MacroBison.cc MacroBison.hh: MacroBison.yy MacroDriver.hh
-	bison --verbose -o MacroBison.cc MacroBison.yy
-
-clean: 
-	rm -f *.o *.P *~ \
-		MacroFlex.cc \
-		MacroBison.output \
-		MacroBison.cc \
-		MacroBison.hh \
-		location.hh \
-		stack.hh \
-		position.hh \
-		libmacro.a
-
-.PHONY: clean
-- 
GitLab