From 4e890a45d5bdd101eebc7405c26639b41ba13a02 Mon Sep 17 00:00:00 2001 From: Neil Brown Date: Tue, 25 Mar 2008 14:53:06 +0000 Subject: [PATCH] Reworked the way we record the C/C++ compiler flags for Tock to use Previously, the files were auto-generated from the Makefile.am. This patch changes to generate the flags using .in files, generated by the configure script. The only problem with this is that the include directory for the Tock support files became difficult, because it depended on Tock's install prefix. As a solution, I've added a pkg-config file for the Tock flags. There might be some way to streamline the whole process once CCSP uses pkg-config, as then Tock, CCSP and C++CSP will all use pkg-config; it might be more flexible for Tock to run the pkg-config command every time it compiles, to avoid having to recompile Tock if you reinstall one of its C/C++ dependencies to a new directory. --- CompilerCommands.hs.in | 23 +++++++++++++++++++++++ Makefile.am | 37 +++---------------------------------- TypeSizes.hs.in | 8 ++++++++ configure.ac | 20 ++++++++++++++++++-- tock-1.0.pc.in | 15 +++++++++++++++ 5 files changed, 67 insertions(+), 36 deletions(-) create mode 100644 CompilerCommands.hs.in create mode 100644 TypeSizes.hs.in create mode 100644 tock-1.0.pc.in diff --git a/CompilerCommands.hs.in b/CompilerCommands.hs.in new file mode 100644 index 0000000..8bc5aa0 --- /dev/null +++ b/CompilerCommands.hs.in @@ -0,0 +1,23 @@ +-- | This file is automatically generated by autoconf from CompilerCommands.hs.in +module CompilerCommands where + +import Data.List + +-- Because we can't know for sure yet where Tock will be installed, +-- we must include this pkg-config call to be executed each time +-- to find out where our headers live. Suggestions for a better way +-- are welcome. +tockIncludeFlags :: String +tockIncludeFlags = "`pkg-config --cflags tock-1.0`" + +cCommand :: String -> String -> String +cCommand inp out = "@CC@ @TOCK_CFLAGS@ " ++ tockIncludeFlags ++ " -c -o " ++ out ++ " " ++ inp + +cAsmCommand :: String -> String -> String +cAsmCommand inp out = "@CC@ @TOCK_CFLAGS@ -S -o " ++ out ++ " " ++ inp + +cLinkCommand :: [String] -> String -> String +cLinkCommand files out = "@CC@ @TOCK_CFLAGS@ -o " ++ out ++ " " ++ (concat (intersperse " " files)) ++ " @TOCK_CLDFLAGS@" + +cxxCommand :: String -> String -> String +cxxCommand inp out = "@CXX@ @TOCK_CXXFLAGS@ " ++ tockIncludeFlags ++ " -o " ++ out ++ " " ++ inp ++ " @TOCK_CXXLDFLAGS@" diff --git a/Makefile.am b/Makefile.am index 80d248f..16bafbe 100644 --- a/Makefile.am +++ b/Makefile.am @@ -19,12 +19,12 @@ else GHC_OPTS += -fallow-undecidable-instances endif -tock$(EXEEXT): $(BUILT_SOURCES) $(tock_SOURCES) +tock$(EXEEXT): $(BUILT_SOURCES) $(tock_SOURCES) CompilerCommands.hs TypeSizes.hs @MKDIR_P@ obj ghc $(GHC_OPTS) -o tock$(EXEEXT) --make Main -odir obj -hidir obj #The order of the -main-is and --make flags is important here: -tocktest$(EXEEXT): $(BUILT_SOURCES) $(tocktest_SOURCES) +tocktest$(EXEEXT): $(BUILT_SOURCES) $(tocktest_SOURCES) CompilerCommands.hs TypeSizes.hs @MKDIR_P@ obj ghc $(GHC_OPTS) -o tocktest$(EXEEXT) -main-is TestMain --make TestMain -odir obj -hidir obj @@ -36,37 +36,6 @@ GenOrdAST$(EXEEXT): $(GenOrdAST_SOURCES) data/AST.hs @MKDIR_P@ obj ghc $(GHC_OPTS) -o GenOrdAST$(EXEEXT) -main-is GenOrdAST --make GenOrdAST -odir obj -hidir obj -common_cflags = -Wall -ggdb3 -Isupport -I$(pkgincludedir) -fno-strict-aliasing - -TOCK_CFLAGS = @gnu89_inline@ @CPPFLAGS@ @CFLAGS@ $(common_cflags) `kroc --cflags` `kroc --ccincpath` -# FIXME: -ldl is only necessary on some platforms for CCSP -TOCK_CLDFLAGS = @LDFLAGS@ `kroc --cclibpath` -lccsp -lpthread -ldl -lm - -TOCK_CXXFLAGS = @CPPFLAGS@ @CXXFLAGS@ $(common_cflags) -TOCK_CXXLDFLAGS = @LDFLAGS@ -lcppcsp2 -pthread - -CompilerCommands.hs: Makefile - echo 'module CompilerCommands where' > CompilerCommands.hs - echo '--This file is auto-generated by Makefile.am' >> CompilerCommands.hs - echo 'import Data.List' >> CompilerCommands.hs - echo 'cCommand :: String -> String -> String' >> CompilerCommands.hs - echo 'cCommand inp out = "$(CC) $(TOCK_CFLAGS) -c -o " ++ out ++ " " ++ inp' >> CompilerCommands.hs - echo 'cAsmCommand :: String -> String -> String' >> CompilerCommands.hs - echo 'cAsmCommand inp out = "$(CC) $(TOCK_CFLAGS) -S -o " ++ out ++ " " ++ inp' >> CompilerCommands.hs - echo 'cLinkCommand :: [String] -> String -> String' >> CompilerCommands.hs - echo 'cLinkCommand files out = "$(CC) $(TOCK_CFLAGS) -o " ++ out ++ " " ++ (concat (intersperse " " files)) ++ " $(TOCK_CLDFLAGS)"' >> CompilerCommands.hs - echo 'cxxCommand :: String -> String -> String' >> CompilerCommands.hs - echo 'cxxCommand inp out = "$(CXX) $(TOCK_CXXFLAGS) -o " ++ out ++ " " ++ inp ++ " $(TOCK_CXXLDFLAGS)"' >> CompilerCommands.hs - -TypeSizes.hs: Makefile - echo 'module TypeSizes where' > TypeSizes.hs - echo '--This file is auto-generated by Makefile.am' >> TypeSizes.hs - echo 'cBoolSize, cxxBoolSize, cIntSize, cxxIntSize :: Int' >> TypeSizes.hs - echo 'cBoolSize = @C_BOOL_SIZE@' >> TypeSizes.hs - echo 'cxxBoolSize = @CXX_BOOL_SIZE@' >> TypeSizes.hs - echo 'cIntSize = @C_INT_SIZE@' >> TypeSizes.hs - echo 'cxxIntSize = @CXX_INT_SIZE@' >> TypeSizes.hs - # Both these results are near-identical. The -g flag to alex tells it to generate # a lexer optimised for GHC. The other part of the rule inserts the # -fno-warn-tabs flag under GHC >= 6.8, but doesn't add anything under previous @@ -98,7 +67,7 @@ data/TagAST.hs: GenTagAST$(EXEEXT) data/OrdAST.hs: GenOrdAST$(EXEEXT) ./GenOrdAST$(EXEEXT) > data/OrdAST.hs -BUILT_SOURCES = frontends/LexOccam.hs frontends/LexRain.hs CompilerCommands.hs TypeSizes.hs data/TagAST.hs data/OrdAST.hs +BUILT_SOURCES = frontends/LexOccam.hs frontends/LexRain.hs data/TagAST.hs data/OrdAST.hs CLEANFILES = $(BUILT_SOURCES) EXTRA_DIST = docextra testcases/automatic diff --git a/TypeSizes.hs.in b/TypeSizes.hs.in new file mode 100644 index 0000000..419a5f9 --- /dev/null +++ b/TypeSizes.hs.in @@ -0,0 +1,8 @@ +-- | This module is auto-generated by autoconf from TypeSizes.hs.in +module TypeSizes where + +cBoolSize, cxxBoolSize, cIntSize, cxxIntSize :: Int +cBoolSize = @C_BOOL_SIZE@ +cxxBoolSize = @CXX_BOOL_SIZE@ +cIntSize = @C_INT_SIZE@ +cxxIntSize = @CXX_INT_SIZE@ diff --git a/configure.ac b/configure.ac index f1b6117..a077d57 100644 --- a/configure.ac +++ b/configure.ac @@ -99,6 +99,7 @@ PKG_CHECK_MODULES(CPPCSP2,cppcsp2-2.0 >= 2.0.4,, #Must remember to switch the language to C++ before checking the C++ headers: AC_LANG(C++) +CPPFLAGS="$CPPCSP2_CFLAGS" AC_CHECK_HEADERS([cppcsp/cppcsp.h],[HAVE_CPPCSP=true],[HAVE_CPPCSP=false]) if test "x$HAVE_CPPCSP" = "xfalse"; then AC_MSG_WARN([cppcsp/cppcsp.h not found; you will not be able to compile output from the C++ backend on this machine]) @@ -168,11 +169,26 @@ AC_CHECK_SIZEOF(int) AC_COMPUTE_INT(C_INT_SIZE,SIZEOF_INT) AC_SUBST(C_INT_SIZE) +common_cflags="-Wall -ggdb3 -Isupport -fno-strict-aliasing" + +CCSP_CFLAGS="`kroc --cflags` `kroc --ccincpath`" +CCSP_LIBS="`kroc --cclibpath` -lccsp -lpthread -ldl -lm" + +TOCK_CFLAGS="$gnu89_inline $CPPFLAGS $CFLAGS $common_cflags $CCSP_CFLAGS" +# FIXME: -ldl is only necessary on some platforms for CCSP +TOCK_CLDFLAGS="$LDFLAGS $CCSP_LIBS" + +TOCK_CXXFLAGS="$CPPFLAGS $CXXFLAGS $common_cflags $CPPCSP2_CFLAGS" +TOCK_CXXLDFLAGS="$LDFLAGS $CPPCSP2_LIBS" + +AC_SUBST(TOCK_CFLAGS) +AC_SUBST(TOCK_CLDFLAGS) +AC_SUBST(TOCK_CXXFLAGS) +AC_SUBST(TOCK_CXXLDFLAGS) -AC_SUBST(gnu89_inline) AC_SUBST(ccsp_kroc_available) AC_SUBST(cppcsp_available) AC_SUBST(MKDIR_P) -AC_CONFIG_FILES([Makefile]) +AC_CONFIG_FILES([Makefile] [TypeSizes.hs] [CompilerCommands.hs] [tock-1.0.pc]) AC_OUTPUT diff --git a/tock-1.0.pc.in b/tock-1.0.pc.in new file mode 100644 index 0000000..441dad7 --- /dev/null +++ b/tock-1.0.pc.in @@ -0,0 +1,15 @@ +prefix=@prefix@ +exec_prefix=@exec_prefix@ +libdir=@libdir@ +includedir=@includedir@ +pkgincludedir=${includedir}/@PACKAGE@ + +Name: Tock +Description: A compiler for concurrent languages +Requires: +Version: @VERSION@ +Libs: +Cflags: -I${pkgincludedir} +URL: https://www.cs.kent.ac.uk/research/groups/sys/wiki/Tock + +