diff --git a/new/builtin.jam b/new/builtin.jam index 381fb5b94..ea4db1388 100644 --- a/new/builtin.jam +++ b/new/builtin.jam @@ -46,6 +46,7 @@ feature exception-handling : on off : propagated ; feature debug-symbols : on off : propagated ; feature define : : free ; feature "include" : : free path ; +feature cflags : : free ; feature cxxflags : : free ; feature linkflags : : free ; feature version : : free ; diff --git a/new/toolset.jam b/new/toolset.jam index 94e2147f0..23f47751f 100644 --- a/new/toolset.jam +++ b/new/toolset.jam @@ -209,12 +209,15 @@ rule set-target-variables ( rule-or-module targets + : properties * ) } } - # recurse for any module-specific flags - local module_ = [ MATCH ^(.+)\\..* : $(rule-or-module) ] ; - if $(module_) + # strip away last dot separated part and recurse. + local next = [ MATCH ^(.+)\\.([^\\.])* : $(rule-or-module) ] ; + if $(next) { - set-target-variables $(module_) $(targets) : $(properties) ; - + set-target-variables $(next) $(targets) : $(properties) ; + } + else + { + # If there's no next dot-separated element, we've got the module name. # Allow a rule-based hook for more-sophisticated setting # of build options than flags allows. if prepare-target in [ RULENAMES $(module_) ] @@ -225,6 +228,7 @@ rule set-target-variables ( rule-or-module targets + : properties * ) } } } + } .toolsets += $(toolset) ; diff --git a/test/c_file.py b/test/c_file.py new file mode 100644 index 000000000..30bc90755 --- /dev/null +++ b/test/c_file.py @@ -0,0 +1,34 @@ +#!/usr/bin/python + +# Copyright (C) Vladimir Prus 2003. Permission to copy, use, modify, sell and +# distribute this software is granted provided this copyright notice appears in +# all copies. This software is provided "as is" without express or implied +# warranty, and with no claim as to its suitability for any purpose. + +# Test that C files are compiled by C compiler +from BoostBuild import Tester, List + +t = Tester() + +t.write("project-root.jam", """ +project ; + +exe hello : hello.cpp a.c ; +""") +t.write("hello.cpp", """ +extern "C" int foo(); +int main() { return foo(); } +""") +t.write("a.c", """ +// This won't compile unless in C mode +int foo() +{ + int new = 0; + new = (new+1)*7; + return new; +} +""") +t.run_build_system() +t.expect_addition("bin/$toolset/debug/hello.exe") + +t.cleanup() diff --git a/test/test_all.py b/test/test_all.py index 2b1386cd0..aec41b1c8 100644 --- a/test/test_all.py +++ b/test/test_all.py @@ -96,6 +96,7 @@ tests = [ "project_test1", "dependency_property", "custom_generator", "bad_dirname", + "c_file", ] if os.name == 'posix': diff --git a/tools/borland.jam b/tools/borland.jam index abd82cc6f..10069af76 100644 --- a/tools/borland.jam +++ b/tools/borland.jam @@ -63,8 +63,8 @@ type.register BORLAND.TDS : tds ; generators.register-linker borland.link "" : RSP : EXE : borland ; generators.register-linker borland.link "" : RSP : SHARED_LIB IMPORT_LIB : borland ; generators.register-composing borland.archive : OBJ : STATIC_LIB : borland ; -generators.register-c-compiler borland.compile : CPP : OBJ : borland ; -generators.register-c-compiler borland.compile : C : OBJ : borland ; +generators.register-c-compiler borland.compile.c++ : CPP : OBJ : borland ; +generators.register-c-compiler borland.compile.c : C : OBJ : borland ; # Declare flags @@ -126,11 +126,18 @@ flags borland NEED_IMPLIB LIB/shared : "" ; # -U$(UNDEFS) -D$(DEFINES) $(CFLAGS) $(C++FLAGS) -I"$(HDRS)" -I"$(STDHDRS)" -o"$(<)" "$(>)" -actions compile +actions compile.c++ { "$(.root)bcc32" -j5 -g255 -q -c -P -w -Ve -Vx -a8 -b- $(OPTIONS) -D$(DEFINES) -I"$(INCLUDES)" -I"$(STDHDRS)" -o"$(<)" "$(>)" } +# For C, we don't pass -P flag +actions compile.c +{ + "$(.root)bcc32" -j5 -g255 -q -c -w -Ve -Vx -a8 -b- $(OPTIONS) -D$(DEFINES) -I"$(INCLUDES)" -I"$(STDHDRS)" -o"$(<)" "$(>)" +} + + # Declare flags and action for linking toolset.flags borland.link OPTIONS on : -v ; toolset.flags borland.link LINKPATH ; diff --git a/tools/gcc.jam b/tools/gcc.jam index 1c61743bc..e8da3117d 100644 --- a/tools/gcc.jam +++ b/tools/gcc.jam @@ -51,9 +51,9 @@ if [ os.name ] = NT # Declare generators generators.register-linker gcc.link : LIB OBJ : EXE : gcc ; generators.register-composing gcc.archive : OBJ : STATIC_LIB : gcc ; -generators.register-linker gcc.link-dll : LIB OBJ : SHARED_LIB : gcc ; -generators.register-c-compiler gcc.compile : CPP : OBJ : gcc ; -generators.register-c-compiler gcc.compile : C : OBJ : gcc ; +generators.register-linker gcc.link.dll : LIB OBJ : SHARED_LIB : gcc ; +generators.register-c-compiler gcc.compile.c++ : CPP : OBJ : gcc ; +generators.register-c-compiler gcc.compile.c : C : OBJ : gcc ; # Declare flags and action for compilation @@ -68,15 +68,22 @@ flags gcc.compile OPTIONS full : -finline-functions -Wno-inline ; flags gcc.compile OPTIONS on : -g ; flags gcc.compile OPTIONS on : -pg ; -flags gcc.compile OPTIONS ; +flags gcc.compile OPTIONS ; +flags gcc.compile.c++ OPTIONS ; flags gcc.compile DEFINES ; flags gcc.compile INCLUDES ; -actions compile +actions compile.c++ { $(NAME:E=g++) -Wall -ftemplate-depth-100 $(OPTIONS) -D$(DEFINES) -I"$(INCLUDES)" -c -o "$(<)" "$(>)" } +actions compile.c +{ + $(NAME:E=gcc) -Wall $(OPTIONS) -D$(DEFINES) -I"$(INCLUDES)" -c -o "$(<)" "$(>)" +} + + # Declare flags and action for linking flags gcc.link OPTIONS on : -g ; # Strip the binary when no debugging is needed. @@ -89,8 +96,7 @@ flags gcc.link FINDLIBS-SA ; flags gcc.link LIBRARIES ; flags gcc.link LINK-RUNTIME static : static ; flags gcc.link LINK-RUNTIME shared : dynamic ; -flags gcc.link-dll RPATH ; - +flags gcc.link RPATH ; rule link ( targets * : sources * : properties * ) { @@ -108,25 +114,14 @@ actions piecemeal archive ar ur "$(<)" "$(>)" } -# Declare flags and action for linking shared libraries -flags gcc.link-dll OPTIONS on : -g ; -flags gcc.link-dll OPTIONS off : -s ; -flags gcc.link-dll OPTIONS on : -pg ; -flags gcc.link-dll OPTIONS ; -flags gcc.link-dll LINKPATH ; -flags gcc.link-dll FINDLIBS-ST ; -flags gcc.link-dll FINDLIBS-SA ; -flags gcc.link-dll LIBRARIES ; -flags gcc.link-dll LINK-RUNTIME static : static ; -flags gcc.link-dll LINK-RUNTIME shared : dynamic ; -flags gcc.link RPATH ; -rule link-dll ( targets * : sources * : properties * ) +rule link.dll ( targets * : sources * : properties * ) { SPACE on $(targets) = " " ; } -actions link-dll bind LIBRARIES +# Differ from 'link' above only by -shared. +actions link.dll bind LIBRARIES { $(NAME:E=g++) $(OPTIONS) -L"$(LINKPATH)" -Wl,-rpath$(SPACE)-Wl,"$(RPATH)" -o "$(<)" -Wl,-soname,$(<[1]:D=) -shared "$(>)" "$(LIBRARIES)" -Wl,-Bdynamic -l$(FINDLIBS-SA) -Wl,-Bstatic -l$(FINDLIBS-ST) "$(LIBRARIES)" -Wl,-Bdynamic -l$(FINDLIBS-SA) -Wl,-Bstatic -l$(FINDLIBS-ST) -Wl,-B$(LINK-RUNTIME) } diff --git a/v2/build/toolset.jam b/v2/build/toolset.jam index 94e2147f0..23f47751f 100644 --- a/v2/build/toolset.jam +++ b/v2/build/toolset.jam @@ -209,12 +209,15 @@ rule set-target-variables ( rule-or-module targets + : properties * ) } } - # recurse for any module-specific flags - local module_ = [ MATCH ^(.+)\\..* : $(rule-or-module) ] ; - if $(module_) + # strip away last dot separated part and recurse. + local next = [ MATCH ^(.+)\\.([^\\.])* : $(rule-or-module) ] ; + if $(next) { - set-target-variables $(module_) $(targets) : $(properties) ; - + set-target-variables $(next) $(targets) : $(properties) ; + } + else + { + # If there's no next dot-separated element, we've got the module name. # Allow a rule-based hook for more-sophisticated setting # of build options than flags allows. if prepare-target in [ RULENAMES $(module_) ] @@ -225,6 +228,7 @@ rule set-target-variables ( rule-or-module targets + : properties * ) } } } + } .toolsets += $(toolset) ; diff --git a/v2/test/c_file.py b/v2/test/c_file.py new file mode 100644 index 000000000..30bc90755 --- /dev/null +++ b/v2/test/c_file.py @@ -0,0 +1,34 @@ +#!/usr/bin/python + +# Copyright (C) Vladimir Prus 2003. Permission to copy, use, modify, sell and +# distribute this software is granted provided this copyright notice appears in +# all copies. This software is provided "as is" without express or implied +# warranty, and with no claim as to its suitability for any purpose. + +# Test that C files are compiled by C compiler +from BoostBuild import Tester, List + +t = Tester() + +t.write("project-root.jam", """ +project ; + +exe hello : hello.cpp a.c ; +""") +t.write("hello.cpp", """ +extern "C" int foo(); +int main() { return foo(); } +""") +t.write("a.c", """ +// This won't compile unless in C mode +int foo() +{ + int new = 0; + new = (new+1)*7; + return new; +} +""") +t.run_build_system() +t.expect_addition("bin/$toolset/debug/hello.exe") + +t.cleanup() diff --git a/v2/test/test_all.py b/v2/test/test_all.py index 2b1386cd0..aec41b1c8 100644 --- a/v2/test/test_all.py +++ b/v2/test/test_all.py @@ -96,6 +96,7 @@ tests = [ "project_test1", "dependency_property", "custom_generator", "bad_dirname", + "c_file", ] if os.name == 'posix': diff --git a/v2/tools/borland.jam b/v2/tools/borland.jam index abd82cc6f..10069af76 100644 --- a/v2/tools/borland.jam +++ b/v2/tools/borland.jam @@ -63,8 +63,8 @@ type.register BORLAND.TDS : tds ; generators.register-linker borland.link "" : RSP : EXE : borland ; generators.register-linker borland.link "" : RSP : SHARED_LIB IMPORT_LIB : borland ; generators.register-composing borland.archive : OBJ : STATIC_LIB : borland ; -generators.register-c-compiler borland.compile : CPP : OBJ : borland ; -generators.register-c-compiler borland.compile : C : OBJ : borland ; +generators.register-c-compiler borland.compile.c++ : CPP : OBJ : borland ; +generators.register-c-compiler borland.compile.c : C : OBJ : borland ; # Declare flags @@ -126,11 +126,18 @@ flags borland NEED_IMPLIB LIB/shared : "" ; # -U$(UNDEFS) -D$(DEFINES) $(CFLAGS) $(C++FLAGS) -I"$(HDRS)" -I"$(STDHDRS)" -o"$(<)" "$(>)" -actions compile +actions compile.c++ { "$(.root)bcc32" -j5 -g255 -q -c -P -w -Ve -Vx -a8 -b- $(OPTIONS) -D$(DEFINES) -I"$(INCLUDES)" -I"$(STDHDRS)" -o"$(<)" "$(>)" } +# For C, we don't pass -P flag +actions compile.c +{ + "$(.root)bcc32" -j5 -g255 -q -c -w -Ve -Vx -a8 -b- $(OPTIONS) -D$(DEFINES) -I"$(INCLUDES)" -I"$(STDHDRS)" -o"$(<)" "$(>)" +} + + # Declare flags and action for linking toolset.flags borland.link OPTIONS on : -v ; toolset.flags borland.link LINKPATH ; diff --git a/v2/tools/builtin.jam b/v2/tools/builtin.jam index 381fb5b94..ea4db1388 100644 --- a/v2/tools/builtin.jam +++ b/v2/tools/builtin.jam @@ -46,6 +46,7 @@ feature exception-handling : on off : propagated ; feature debug-symbols : on off : propagated ; feature define : : free ; feature "include" : : free path ; +feature cflags : : free ; feature cxxflags : : free ; feature linkflags : : free ; feature version : : free ; diff --git a/v2/tools/gcc.jam b/v2/tools/gcc.jam index 1c61743bc..e8da3117d 100644 --- a/v2/tools/gcc.jam +++ b/v2/tools/gcc.jam @@ -51,9 +51,9 @@ if [ os.name ] = NT # Declare generators generators.register-linker gcc.link : LIB OBJ : EXE : gcc ; generators.register-composing gcc.archive : OBJ : STATIC_LIB : gcc ; -generators.register-linker gcc.link-dll : LIB OBJ : SHARED_LIB : gcc ; -generators.register-c-compiler gcc.compile : CPP : OBJ : gcc ; -generators.register-c-compiler gcc.compile : C : OBJ : gcc ; +generators.register-linker gcc.link.dll : LIB OBJ : SHARED_LIB : gcc ; +generators.register-c-compiler gcc.compile.c++ : CPP : OBJ : gcc ; +generators.register-c-compiler gcc.compile.c : C : OBJ : gcc ; # Declare flags and action for compilation @@ -68,15 +68,22 @@ flags gcc.compile OPTIONS full : -finline-functions -Wno-inline ; flags gcc.compile OPTIONS on : -g ; flags gcc.compile OPTIONS on : -pg ; -flags gcc.compile OPTIONS ; +flags gcc.compile OPTIONS ; +flags gcc.compile.c++ OPTIONS ; flags gcc.compile DEFINES ; flags gcc.compile INCLUDES ; -actions compile +actions compile.c++ { $(NAME:E=g++) -Wall -ftemplate-depth-100 $(OPTIONS) -D$(DEFINES) -I"$(INCLUDES)" -c -o "$(<)" "$(>)" } +actions compile.c +{ + $(NAME:E=gcc) -Wall $(OPTIONS) -D$(DEFINES) -I"$(INCLUDES)" -c -o "$(<)" "$(>)" +} + + # Declare flags and action for linking flags gcc.link OPTIONS on : -g ; # Strip the binary when no debugging is needed. @@ -89,8 +96,7 @@ flags gcc.link FINDLIBS-SA ; flags gcc.link LIBRARIES ; flags gcc.link LINK-RUNTIME static : static ; flags gcc.link LINK-RUNTIME shared : dynamic ; -flags gcc.link-dll RPATH ; - +flags gcc.link RPATH ; rule link ( targets * : sources * : properties * ) { @@ -108,25 +114,14 @@ actions piecemeal archive ar ur "$(<)" "$(>)" } -# Declare flags and action for linking shared libraries -flags gcc.link-dll OPTIONS on : -g ; -flags gcc.link-dll OPTIONS off : -s ; -flags gcc.link-dll OPTIONS on : -pg ; -flags gcc.link-dll OPTIONS ; -flags gcc.link-dll LINKPATH ; -flags gcc.link-dll FINDLIBS-ST ; -flags gcc.link-dll FINDLIBS-SA ; -flags gcc.link-dll LIBRARIES ; -flags gcc.link-dll LINK-RUNTIME static : static ; -flags gcc.link-dll LINK-RUNTIME shared : dynamic ; -flags gcc.link RPATH ; -rule link-dll ( targets * : sources * : properties * ) +rule link.dll ( targets * : sources * : properties * ) { SPACE on $(targets) = " " ; } -actions link-dll bind LIBRARIES +# Differ from 'link' above only by -shared. +actions link.dll bind LIBRARIES { $(NAME:E=g++) $(OPTIONS) -L"$(LINKPATH)" -Wl,-rpath$(SPACE)-Wl,"$(RPATH)" -o "$(<)" -Wl,-soname,$(<[1]:D=) -shared "$(>)" "$(LIBRARIES)" -Wl,-Bdynamic -l$(FINDLIBS-SA) -Wl,-Bstatic -l$(FINDLIBS-ST) "$(LIBRARIES)" -Wl,-Bdynamic -l$(FINDLIBS-SA) -Wl,-Bstatic -l$(FINDLIBS-ST) -Wl,-B$(LINK-RUNTIME) }