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.
This commit is contained in:
Neil Brown 2008-03-25 14:53:06 +00:00
parent 5e70e70d95
commit 4e890a45d5
5 changed files with 67 additions and 36 deletions

23
CompilerCommands.hs.in Normal file
View File

@ -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@"

View File

@ -19,12 +19,12 @@ else
GHC_OPTS += -fallow-undecidable-instances GHC_OPTS += -fallow-undecidable-instances
endif endif
tock$(EXEEXT): $(BUILT_SOURCES) $(tock_SOURCES) tock$(EXEEXT): $(BUILT_SOURCES) $(tock_SOURCES) CompilerCommands.hs TypeSizes.hs
@MKDIR_P@ obj @MKDIR_P@ obj
ghc $(GHC_OPTS) -o tock$(EXEEXT) --make Main -odir obj -hidir 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: #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 @MKDIR_P@ obj
ghc $(GHC_OPTS) -o tocktest$(EXEEXT) -main-is TestMain --make TestMain -odir obj -hidir 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 @MKDIR_P@ obj
ghc $(GHC_OPTS) -o GenOrdAST$(EXEEXT) -main-is GenOrdAST --make GenOrdAST -odir obj -hidir 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 # 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 # 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 # -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) data/OrdAST.hs: GenOrdAST$(EXEEXT)
./GenOrdAST$(EXEEXT) > data/OrdAST.hs ./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) CLEANFILES = $(BUILT_SOURCES)
EXTRA_DIST = docextra testcases/automatic EXTRA_DIST = docextra testcases/automatic

8
TypeSizes.hs.in Normal file
View File

@ -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@

View File

@ -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: #Must remember to switch the language to C++ before checking the C++ headers:
AC_LANG(C++) AC_LANG(C++)
CPPFLAGS="$CPPCSP2_CFLAGS"
AC_CHECK_HEADERS([cppcsp/cppcsp.h],[HAVE_CPPCSP=true],[HAVE_CPPCSP=false]) AC_CHECK_HEADERS([cppcsp/cppcsp.h],[HAVE_CPPCSP=true],[HAVE_CPPCSP=false])
if test "x$HAVE_CPPCSP" = "xfalse"; then 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]) 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_COMPUTE_INT(C_INT_SIZE,SIZEOF_INT)
AC_SUBST(C_INT_SIZE) 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(ccsp_kroc_available)
AC_SUBST(cppcsp_available) AC_SUBST(cppcsp_available)
AC_SUBST(MKDIR_P) AC_SUBST(MKDIR_P)
AC_CONFIG_FILES([Makefile]) AC_CONFIG_FILES([Makefile] [TypeSizes.hs] [CompilerCommands.hs] [tock-1.0.pc])
AC_OUTPUT AC_OUTPUT

15
tock-1.0.pc.in Normal file
View File

@ -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