From e32dcb85e90fac426e5f3b825d5613aaaefff011 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ciro=20Santilli=20=E5=85=AD=E5=9B=9B=E4=BA=8B=E4=BB=B6=20?= =?UTF-8?q?=E6=B3=95=E8=BD=AE=E5=8A=9F?= Date: Wed, 13 Mar 2019 00:00:01 +0000 Subject: [PATCH] userland: start per-directory flags with userland/gcc --- build-userland | 51 ++++++++++++++++++++++++------------ userland/{ => c}/hello.c | 0 userland/gcc/empty_struct.c | 11 ++++++++ userland/{ => posix}/uname.c | 0 4 files changed, 45 insertions(+), 17 deletions(-) rename userland/{ => c}/hello.c (100%) create mode 100644 userland/gcc/empty_struct.c rename userland/{ => posix}/uname.c (100%) diff --git a/build-userland b/build-userland index cf005bd..c532c57 100755 --- a/build-userland +++ b/build-userland @@ -17,6 +17,8 @@ class Main(common.BuildCliFunction): Build our compiled userland examples. ''' ) + self.default_cstd = 'c11' + self.default_cxxstd = 'c++17' self.add_argument( '--has-package', action='append', @@ -45,11 +47,12 @@ Default: build all examples that have their package dependencies met, e.g.: in_path, out_path, ccflags, - extra_deps=None, - link=True, - extra_objs=None, - std=None, ccflags_after=None, + cstd=None, + cxxstd=None, + extra_deps=None, + extra_objs=None, + link=True, raise_on_failure=True, thread_limiter=None, ): @@ -69,15 +72,19 @@ Default: build all examples that have their package dependencies met, e.g.: do_compile = True if in_ext == self.env['c_ext']: cc = self.env['gcc'] - if std is None: - std = 'c11' + if cstd is None: + std = self.default_cstd + else: + std = cstd ccflags.extend([ '-fopenmp', LF, ]) elif in_ext == self.env['cxx_ext']: cc = self.env['gxx'] - if std is None: - std = 'c++17' + if cxxstd is None: + std = self.default_cxxstd + else: + std = cxxstd else: do_compile = False if do_compile: @@ -121,7 +128,6 @@ Default: build all examples that have their package dependencies met, e.g.: '-Werror', LF, '-Wextra', LF, '-Wno-unused-function', LF, - '-pedantic', LF, '-ggdb3', LF, ] if self.env['static']: @@ -183,6 +189,15 @@ Default: build all examples that have their package dependencies met, e.g.: dirpath_relative_root ) os.makedirs(out_dir, exist_ok=True) + ccflags_dir = ccflags.copy() + if dirpath_relative_root_components == ['gcc']: + cstd = 'gnu11' + cxxstd = 'gnu++17' + else: + cstd = self.default_cstd + cxxstd = self.default_cxxstd + # -pedantic complains even if we use -std=gnu11. + ccflags_dir.extend(['-pedantic', LF]) for in_filename in in_filenames: in_path = os.path.join(path, in_filename) in_name, in_ext = os.path.splitext(in_filename) @@ -191,7 +206,7 @@ Default: build all examples that have their package dependencies met, e.g.: in_name + self.env['userland_build_ext'] ) pkg_key = in_name.split('_')[0] - ccflags_file = ccflags.copy() + ccflags_file = ccflags_dir.copy() ccflags_after = [] if pkg_key in pkgs: if pkg_key not in has_packages: @@ -221,13 +236,15 @@ Default: build all examples that have their package dependencies met, e.g.: thread = threading.Thread( target=self._build_one, kwargs={ - 'in_path':in_path, - 'out_path':out_path, - 'ccflags':ccflags_file, - 'extra_objs':[common_obj], - 'ccflags_after':ccflags_after, - 'raise_on_failure':False, - 'thread_limiter':thread_limiter, + 'in_path': in_path, + 'out_path': out_path, + 'ccflags': ccflags_file, + 'cstd': cstd, + 'cxxstd': cxxstd, + 'extra_objs': [common_obj], + 'ccflags_after': ccflags_after, + 'raise_on_failure': False, + 'thread_limiter': thread_limiter, } ) thread.start() diff --git a/userland/hello.c b/userland/c/hello.c similarity index 100% rename from userland/hello.c rename to userland/c/hello.c diff --git a/userland/gcc/empty_struct.c b/userland/gcc/empty_struct.c new file mode 100644 index 0000000..1cf5bc8 --- /dev/null +++ b/userland/gcc/empty_struct.c @@ -0,0 +1,11 @@ +/* Empty struct */ + +#include +#include + +int main(void) { + struct s {}; + struct s s0; + assert(sizeof(s0) == 0); + return EXIT_SUCCESS; +} diff --git a/userland/uname.c b/userland/posix/uname.c similarity index 100% rename from userland/uname.c rename to userland/posix/uname.c