mirror of
https://github.com/boostorg/build.git
synced 2026-02-16 01:12:13 +00:00
Compile C files with C compiler, not C++. This commit would close BB32, if
it included MSVC... * new/toolset.jam: Allow action names with dots, so that we can set flags for gcc.compile.c, gcc.compile and gcc and combine those flags. * tools/gcc.jam: Use 'gcc' for compiling C files. There's still a problem: 'init' rules does not allow to configure name of C compiler. Also, don't declare flags individually for gcc.link and gcc.link-dll. * tools/borland.jam: Force C++ compile when needed. [SVN r18774]
This commit is contained in:
@@ -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 ;
|
||||
|
||||
@@ -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) ;
|
||||
|
||||
34
test/c_file.py
Normal file
34
test/c_file.py
Normal file
@@ -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()
|
||||
@@ -96,6 +96,7 @@ tests = [ "project_test1",
|
||||
"dependency_property",
|
||||
"custom_generator",
|
||||
"bad_dirname",
|
||||
"c_file",
|
||||
]
|
||||
|
||||
if os.name == 'posix':
|
||||
|
||||
@@ -63,8 +63,8 @@ type.register BORLAND.TDS : tds ;
|
||||
generators.register-linker borland.link "" : RSP : EXE : <toolset>borland ;
|
||||
generators.register-linker borland.link "" : RSP : SHARED_LIB IMPORT_LIB : <toolset>borland ;
|
||||
generators.register-composing borland.archive : OBJ : STATIC_LIB : <toolset>borland ;
|
||||
generators.register-c-compiler borland.compile : CPP : OBJ : <toolset>borland ;
|
||||
generators.register-c-compiler borland.compile : C : OBJ : <toolset>borland ;
|
||||
generators.register-c-compiler borland.compile.c++ : CPP : OBJ : <toolset>borland ;
|
||||
generators.register-c-compiler borland.compile.c : C : OBJ : <toolset>borland ;
|
||||
|
||||
|
||||
# Declare flags
|
||||
@@ -126,11 +126,18 @@ flags borland NEED_IMPLIB <main-target-type>LIB/<link>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 <debug-symbols>on : -v ;
|
||||
toolset.flags borland.link LINKPATH <library-path> ;
|
||||
|
||||
@@ -51,9 +51,9 @@ if [ os.name ] = NT
|
||||
# Declare generators
|
||||
generators.register-linker gcc.link : LIB OBJ : EXE : <toolset>gcc ;
|
||||
generators.register-composing gcc.archive : OBJ : STATIC_LIB : <toolset>gcc ;
|
||||
generators.register-linker gcc.link-dll : LIB OBJ : SHARED_LIB : <toolset>gcc ;
|
||||
generators.register-c-compiler gcc.compile : CPP : OBJ : <toolset>gcc ;
|
||||
generators.register-c-compiler gcc.compile : C : OBJ : <toolset>gcc ;
|
||||
generators.register-linker gcc.link.dll : LIB OBJ : SHARED_LIB : <toolset>gcc ;
|
||||
generators.register-c-compiler gcc.compile.c++ : CPP : OBJ : <toolset>gcc ;
|
||||
generators.register-c-compiler gcc.compile.c : C : OBJ : <toolset>gcc ;
|
||||
|
||||
|
||||
# Declare flags and action for compilation
|
||||
@@ -68,15 +68,22 @@ flags gcc.compile OPTIONS <inlining>full : -finline-functions -Wno-inline ;
|
||||
flags gcc.compile OPTIONS <debug-symbols>on : -g ;
|
||||
flags gcc.compile OPTIONS <profiling>on : -pg ;
|
||||
|
||||
flags gcc.compile OPTIONS <cxxflags> ;
|
||||
flags gcc.compile OPTIONS <cflags> ;
|
||||
flags gcc.compile.c++ OPTIONS <cxxflags> ;
|
||||
flags gcc.compile DEFINES <define> ;
|
||||
flags gcc.compile INCLUDES <include> ;
|
||||
|
||||
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 <debug-symbols>on : -g ;
|
||||
# Strip the binary when no debugging is needed.
|
||||
@@ -89,8 +96,7 @@ flags gcc.link FINDLIBS-SA <find-shared-library> ;
|
||||
flags gcc.link LIBRARIES <library> ;
|
||||
flags gcc.link LINK-RUNTIME <link-runtime>static : static ;
|
||||
flags gcc.link LINK-RUNTIME <link-runtime>shared : dynamic ;
|
||||
flags gcc.link-dll RPATH <dll-path> ;
|
||||
|
||||
flags gcc.link RPATH <dll-path> ;
|
||||
|
||||
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 <debug-symbols>on : -g ;
|
||||
flags gcc.link-dll OPTIONS <debug-symbols>off : -s ;
|
||||
flags gcc.link-dll OPTIONS <profiling>on : -pg ;
|
||||
flags gcc.link-dll OPTIONS <linkflags> ;
|
||||
flags gcc.link-dll LINKPATH <library-path> ;
|
||||
flags gcc.link-dll FINDLIBS-ST <find-static-library> ;
|
||||
flags gcc.link-dll FINDLIBS-SA <find-shared-library> ;
|
||||
flags gcc.link-dll LIBRARIES <library> ;
|
||||
flags gcc.link-dll LINK-RUNTIME <link-runtime>static : static ;
|
||||
flags gcc.link-dll LINK-RUNTIME <link-runtime>shared : dynamic ;
|
||||
flags gcc.link RPATH <dll-path> ;
|
||||
|
||||
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)
|
||||
}
|
||||
|
||||
@@ -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) ;
|
||||
|
||||
34
v2/test/c_file.py
Normal file
34
v2/test/c_file.py
Normal file
@@ -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()
|
||||
@@ -96,6 +96,7 @@ tests = [ "project_test1",
|
||||
"dependency_property",
|
||||
"custom_generator",
|
||||
"bad_dirname",
|
||||
"c_file",
|
||||
]
|
||||
|
||||
if os.name == 'posix':
|
||||
|
||||
@@ -63,8 +63,8 @@ type.register BORLAND.TDS : tds ;
|
||||
generators.register-linker borland.link "" : RSP : EXE : <toolset>borland ;
|
||||
generators.register-linker borland.link "" : RSP : SHARED_LIB IMPORT_LIB : <toolset>borland ;
|
||||
generators.register-composing borland.archive : OBJ : STATIC_LIB : <toolset>borland ;
|
||||
generators.register-c-compiler borland.compile : CPP : OBJ : <toolset>borland ;
|
||||
generators.register-c-compiler borland.compile : C : OBJ : <toolset>borland ;
|
||||
generators.register-c-compiler borland.compile.c++ : CPP : OBJ : <toolset>borland ;
|
||||
generators.register-c-compiler borland.compile.c : C : OBJ : <toolset>borland ;
|
||||
|
||||
|
||||
# Declare flags
|
||||
@@ -126,11 +126,18 @@ flags borland NEED_IMPLIB <main-target-type>LIB/<link>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 <debug-symbols>on : -v ;
|
||||
toolset.flags borland.link LINKPATH <library-path> ;
|
||||
|
||||
@@ -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 ;
|
||||
|
||||
@@ -51,9 +51,9 @@ if [ os.name ] = NT
|
||||
# Declare generators
|
||||
generators.register-linker gcc.link : LIB OBJ : EXE : <toolset>gcc ;
|
||||
generators.register-composing gcc.archive : OBJ : STATIC_LIB : <toolset>gcc ;
|
||||
generators.register-linker gcc.link-dll : LIB OBJ : SHARED_LIB : <toolset>gcc ;
|
||||
generators.register-c-compiler gcc.compile : CPP : OBJ : <toolset>gcc ;
|
||||
generators.register-c-compiler gcc.compile : C : OBJ : <toolset>gcc ;
|
||||
generators.register-linker gcc.link.dll : LIB OBJ : SHARED_LIB : <toolset>gcc ;
|
||||
generators.register-c-compiler gcc.compile.c++ : CPP : OBJ : <toolset>gcc ;
|
||||
generators.register-c-compiler gcc.compile.c : C : OBJ : <toolset>gcc ;
|
||||
|
||||
|
||||
# Declare flags and action for compilation
|
||||
@@ -68,15 +68,22 @@ flags gcc.compile OPTIONS <inlining>full : -finline-functions -Wno-inline ;
|
||||
flags gcc.compile OPTIONS <debug-symbols>on : -g ;
|
||||
flags gcc.compile OPTIONS <profiling>on : -pg ;
|
||||
|
||||
flags gcc.compile OPTIONS <cxxflags> ;
|
||||
flags gcc.compile OPTIONS <cflags> ;
|
||||
flags gcc.compile.c++ OPTIONS <cxxflags> ;
|
||||
flags gcc.compile DEFINES <define> ;
|
||||
flags gcc.compile INCLUDES <include> ;
|
||||
|
||||
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 <debug-symbols>on : -g ;
|
||||
# Strip the binary when no debugging is needed.
|
||||
@@ -89,8 +96,7 @@ flags gcc.link FINDLIBS-SA <find-shared-library> ;
|
||||
flags gcc.link LIBRARIES <library> ;
|
||||
flags gcc.link LINK-RUNTIME <link-runtime>static : static ;
|
||||
flags gcc.link LINK-RUNTIME <link-runtime>shared : dynamic ;
|
||||
flags gcc.link-dll RPATH <dll-path> ;
|
||||
|
||||
flags gcc.link RPATH <dll-path> ;
|
||||
|
||||
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 <debug-symbols>on : -g ;
|
||||
flags gcc.link-dll OPTIONS <debug-symbols>off : -s ;
|
||||
flags gcc.link-dll OPTIONS <profiling>on : -pg ;
|
||||
flags gcc.link-dll OPTIONS <linkflags> ;
|
||||
flags gcc.link-dll LINKPATH <library-path> ;
|
||||
flags gcc.link-dll FINDLIBS-ST <find-static-library> ;
|
||||
flags gcc.link-dll FINDLIBS-SA <find-shared-library> ;
|
||||
flags gcc.link-dll LIBRARIES <library> ;
|
||||
flags gcc.link-dll LINK-RUNTIME <link-runtime>static : static ;
|
||||
flags gcc.link-dll LINK-RUNTIME <link-runtime>shared : dynamic ;
|
||||
flags gcc.link RPATH <dll-path> ;
|
||||
|
||||
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)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user