You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@stdcxx.apache.org by se...@apache.org on 2006/03/28 04:27:39 UTC
svn commit: r389362 - /incubator/stdcxx/trunk/etc/config/GNUmakefile.cfg
Author: sebor
Date: Mon Mar 27 18:27:37 2006
New Revision: 389362
URL: http://svn.apache.org/viewcvs?rev=389362&view=rev
Log:
2006-03-27 Martin Sebor <se...@roguewave.com>
* GNUmakefile.cfg (compile, link, compile_then_link, prelink, archive):
New helper functions to invoke the compiler, linker, and archiver and
log the results.
(arch): Used the function(s) defined above and simplified. Exited with
an error when unable to determine the system architecture.
(sane, %.o: %.cpp, %: %.o, library rule): Used the function(s) defined
above and simplified.
Modified:
incubator/stdcxx/trunk/etc/config/GNUmakefile.cfg
Modified: incubator/stdcxx/trunk/etc/config/GNUmakefile.cfg
URL: http://svn.apache.org/viewcvs/incubator/stdcxx/trunk/etc/config/GNUmakefile.cfg?rev=389362&r1=389361&r2=389362&view=diff
==============================================================================
--- incubator/stdcxx/trunk/etc/config/GNUmakefile.cfg (original)
+++ incubator/stdcxx/trunk/etc/config/GNUmakefile.cfg Mon Mar 27 18:27:37 2006
@@ -75,6 +75,61 @@
CXXPRELINK = $(CXX) $(CPPFLAGS) $(LDFLAGS) $(PRELINKFLAGS)
endif # ($(PRELINKFLAGS),)
+
+# helper function to compile a file and log results
+# arguments:
+# $(1): source file name
+# $(2): object file name
+# $(3): additional compiler flags (optional)
+define compile
+ command="$(CXX) $(CPPFLAGS) $(CXXFLAGS) $(3) -c $(1) -o $(2)"; \
+ echo "$$command" >>$(LOGFILE); \
+ $(CXX) $(CPPFLAGS) $(CXXFLAGS) $(3) -c $(1) -o $(2) >>$(LOGFILE) 2>&1
+endef
+
+# helper function to link a file and log results
+# arguments:
+# $(1): object file name
+# $(2): executable file name
+# $(3): additional linker flags (optional)
+define link
+ command="$(LD) $(1) $(LDFLAGS) $(3) -o $(2)"; \
+ echo "$$command" >>$(LOGFILE); \
+ $(LD) $(1) $(LDFLAGS) $(3) -o $(2) >>$(LOGFILE) 2>&1
+endef
+
+# helper function to compile and link a file and log results
+# arguments:
+# $(1): source file name
+# $(2): object file name
+# $(3): executable file name
+# $(4): additional compiler flags (optional)
+# $(5): additional linker flags (optional)
+define compile_then_link
+ command="$(CXX) $(CPPFLAGS) $(CXXFLAGS) $(4) -c $(1) -o $(2)" \
+ "&& $(LD) $(2) $(LDFLAGS) $(5) -o $(3)"; \
+ echo "$$command" >>$(LOGFILE); \
+ $(CXX) $(CPPFLAGS) $(CXXFLAGS) $(4) -c $(1) -o $(2) >>$(LOGFILE) 2>&1 \
+ && $(LD) $(2) $(LDFLAGS) $(5) -o $(3) >>$(LOGFILE) 2>&1
+endef
+
+# helper function to prelink a file and log results
+# arguments:
+# $(1): source file name
+# $(2): object file name
+define prelink
+ command="$(CXXPRELINK) $(1) -o $(2)"; \
+ echo "$$command" >>$(LOGFILE); \
+ $(CXXPRELINK) $(1) -o $(2) >>$(LOGFILE)
+endef
+
+# helper function to create an archive out of an object file
+define archive
+ command="$(AR) $(ARFLAGS) $(1) $(2)"; \
+ echo "$$command" >>$(LOGFILE); \
+ $(AR) $(ARFLAGS) $(1) $(2) >>$(LOGFILE)
+endef
+
##############################################################################
# TARGETS
##############################################################################
@@ -193,10 +248,7 @@
for type in int long "long long" "void*" ; do \
echo "int main () { return sizeof ($$type); }" \
| tee a.cpp >>$(LOGFILE) ; \
- echo "$(CXX) $(CPPFLAGS) $(CXXFLAGS) -c a.cpp " \
- "&& $(LD) a.o -a.out $(LDFLAGS)" >>$(LOGFILE) ; \
- $(CXX) $(CPPFLAGS) $(CXXFLAGS) -c a.cpp && \
- $(LD) a.o $(LDFLAGS) -o a.out >>$(LOGFILE) 2>&1 ; \
+ $(call compile_then_link,a.cpp,a.o,a.out); \
if [ $$? -eq 0 ] ; then \
size="$$size`./a.out ; echo $$?`" ; \
else \
@@ -210,15 +262,16 @@
esac ; \
echo "int main () { int i = 1; return *(char*)&i; }" \
| tee a.cpp >>$(LOGFILE) ; \
- echo "$(CXX) $(CPPFLAGS) $(CXXFLAGS) -c a.cpp " \
- "&& $(LD) a.o -a.out $(LDFLAGS)" >>$(LOGFILE) ; \
- $(CXX) $(CPPFLAGS) $(CXXFLAGS) -c a.cpp && \
- $(LD) a.o $(LDFLAGS) -o a.out >>$(LOGFILE) 2>&1 ; \
+ $(call compile_then_link,a.cpp,a.o,a.out); \
if [ $$? -eq 0 ] ; then \
endian=" little endian" ; \
./a.out ; \
[ $$? -eq 0 ] && endian=" big endian" ; \
- fi ; \
+ else \
+ echo "error"; \
+ cat $(LOGFILE); \
+ exit 1; \
+ fi; \
echo "$$arch$$endian" >$$output ; \
)
@@ -228,31 +281,19 @@
@(echo; echo "configuring for $(CCNAME) on $(PLATFORM)"; echo; \
rm -f a.out ; \
echo "int main () { return 0; }" | tee a.cpp >>$(LOGFILE) ; \
- printf "%-50.50s " "checking if compiler is sane"; \
- echo "$(CXX) -c $(CXXFLAGS) $(CPPFLAGS) a.cpp" >>$(LOGFILE) 2>&1; \
- $(CXX) -c $(CXXFLAGS) $(CPPFLAGS) a.cpp >>$(LOGFILE) 2>&1; \
+ printf "%-50.50s " "checking if the compiler is sane"; \
+ $(call compile,a.cpp,a.o); \
if [ $$? -eq 0 ] ; then \
- echo "ok"; \
+ echo "ok (invoked with $(CXX))"; \
else \
echo "no"; echo; \
cat $(LOGFILE) ; \
exit 1; \
fi; \
- printf "%-50.50s " "checking if linker is sane"; \
- echo "$(LD) a.o $(LDFLAGS) -o a.out" >>$(LOGFILE) 2>&1; \
- $(LD) a.o $(LDFLAGS) -o a.out >>$(LOGFILE) 2>&1 ; \
+ printf "%-50.50s " "checking if the linker is sane"; \
+ $(call link,a.o,a.out); \
if [ $$? -eq 0 ] ; then \
- echo "ok"; \
- else \
- echo "no"; echo; \
- cat $(LOGFILE) ; \
- exit 1; \
- fi; \
- printf "%-50.50s " "checking if run environment is sane"; \
- echo "./a.out" >>$(LOGFILE) 2>&1; \
- ./a.out >>$(LOGFILE) 2>&1; \
- if [ $$? -eq 0 ] ; then \
- echo "ok"; \
+ echo "ok (invoked with $(LD))"; \
else \
echo "no"; echo; \
cat $(LOGFILE) ; \
@@ -310,40 +351,25 @@
fi; \
done; \
true)
- @echo "$(CXX) -c $(CXXFLAGS) $(CPPFLAGS) $<" >>$(LOGFILE)
- $(CXX) -c $(CXXFLAGS) $(CPPFLAGS) $< >>$(LOGFILE) 2>&1
+ $(call compile,$<,$@)
# remove .o to prevent the run target from getting confused
%: %.o
- @echo "$(LD) $^ $(LDFLAGS) -o $@" >>$(LOGFILE) 2>&1
- $(LD) $^ $(LDFLAGS) -o $@ >>$(LOGFILE) 2>&1 ; rm $<
+ $(call link,$^,$@); rm $<
# build a library from any source file named *.lib.cpp
%.lib$(LIBSUFFIX): %.lib.cpp
ifeq ($(findstring shared,$(BUILDMODE)),shared)
+ $(call compile,$<,$@.o,$(PICFLAGS))
ifeq ($(findstring xlC,$(CXX)),xlC)
# IBM xlC first "preprocesses" .o's with -qmkshrobj
# and then uses `ar' to create a shared library...
- echo "$(CXX) $< $(CPPFLAGS) $(CXXFLAGS) $(PICFLAGS) -c -o $@.o" \
- >>$(LOGFILE)
- $(CXX) $< $(CPPFLAGS) $(CXXFLAGS) $(PICFLAGS) -c -o $@.o \
- >>$(LOGFILE) 2>&1
- echo "$(CXXPRELINK) $@.o -o $@.lib.o" >>$(LOGFILE)
- $(CXXPRELINK) $@.o -o $@.lib.o >>$(LOGFILE)
- echo "$(AR) $(ARFLAGS) $@ $@.lib.o" >>$(LOGFILE)
- $(AR) $(ARFLAGS) $@ $@.lib.o >>$(LOGFILE)
+ $(call prelink,$@.o,@.lib.o)
+ $(call archive,$@,$@.lib.o)
else
- echo "$(CXX) $< $(CPPFLAGS) $(CXXFLAGS) $(PICFLAGS) -c -o $@.o" \
- >>$(LOGFILE)
- $(CXX) $< $(CPPFLAGS) $(CXXFLAGS) $(PICFLAGS) -c -o $@.o \
- >>$(LOGFILE) 2>&1
- echo "$(LD) $@.o $(LDFLAGS) $(LDSOFLAGS) -o $@" >>$(LOGFILE)
- $(LD) $@.o $(LDFLAGS) $(LDSOFLAGS) -o $@ >>$(LOGFILE) 2>&1
+ $(call link,$@.o,$@,$(LDSOFLAGS))
endif
else
- @echo "$(CXX) $(CPPFLAGS) $(CXXFLAGS) $< -c -o $@.o" >>$(LOGFILE)
- $(CXX) $< -c -o $@.o $(CPPFLAGS) $(CXXFLAGS) >>$(LOGFILE) 2>&1
- @echo "$(AR) $(ARFLAGS) $@ $@.o" >>$(LOGFILE)
- $(AR) $(ARFLAGS) $@ $@.o >>$(LOGFILE)
-
+ $(call compile,$<,$@.o)
+ $(call archive,$@,$@.o)
endif