Skip to content
Snippets Groups Projects
Commit e8043640 authored by Bruce Cowan's avatar Bruce Cowan :airplane:
Browse files

Lots of build system stuff, plus GCC attributes

parent 7bcf5b64
No related branches found
No related tags found
No related merge requests found
Pipeline #2900 passed
# SPDX-FileCopyrightText: 2018-2019 Bruce Cowan
# SPDX-FileCopyrightText: 2018-2020 Bruce Cowan
#
# SPDX-License-Identifier: CC0-1.0
subdir('utils')
subdir('types')
utils_src = [
'types/array.c',
'types/hashtable.c',
'types/slist.c',
'utils/mem.c',
'utils/utils.c',
]
utils_deps = [
config_h,
libm,
]
utils_includes = [
'types',
'utils',
]
utils_lib = library(
'utils',
utils_src,
dependencies: utils_deps,
include_directories: utils_includes,
)
utils_dep = declare_dependency(
link_with: utils_lib,
dependencies: utils_deps,
include_directories: utils_includes,
)
/*
* SPDX-FileCopyrightText: 2018, 2019 Bruce Cowan <bruce@bcowan.me.uk>
* SPDX-FileCopyrightText: 2018-2020 Bruce Cowan <bruce@bcowan.me.uk>
*
* SPDX-License-Identifier: Apache-2.0
*/
......
# SPDX-FileCopyrightText: 2018-2020 Bruce Cowan <bruce@bcowan.me.uk>
#
# SPDX-License-Identifier: CC0-1.0
types_src = ['array.c', 'hashtable.c', 'slist.c']
types_lib = static_library('types', types_src, dependencies: [libm, utils_dep])
types_dep = declare_dependency(link_with: types_lib, include_directories: '.')
/*
* SPDX-FileCopyrightText: 2019 Bruce Cowan <bruce@bcowan.me.uk>
* SPDX-FileCopyrightText: 2019-2020 Bruce Cowan <bruce@bcowan.me.uk>
*
* SPDX-License-Identifier: Apache-2.0
*/
#pragma once
#include "macros.h"
#include "types.h"
typedef struct _SList SList;
......@@ -16,7 +17,7 @@ struct _SList
};
SList * slist_prepend (SList *list,
void *data);
void *data) ATTR_WARN_UNUSED_RESULT;
SList * slist_find (SList *slist,
const void *data);
......@@ -28,6 +29,6 @@ void slist_foreach (SList *list,
SList * slist_remove (SList *list,
void *data,
FreeFunc func);
FreeFunc func) ATTR_WARN_UNUSED_RESULT;
void slist_free_all (SList *list,
FreeFunc func);
/*
* SPDX-FileCopyrightText: 2020 Bruce Cowan <bruce@bcowan.me.uk>
*
* SPDX-License-Identifier: Apache-2.0
*/
#pragma once
#include "config.h"
#ifdef HAVE_ATTR_ALLOC_SIZE
#define ATTR_ALLOC_SIZE(x) __attribute__((alloc_size(x)))
#define ATTR_ALLOC_SIZE2(x,y) __attribute__((alloc_size(x,y)))
#else
#define ATTR_ALLOC_SIZE(x)
#define ATTR_ALLOC_SIZE2(x,y)
#endif
#ifdef HAVE_ATTR_MALLOC
#define ATTR_MALLOC __attribute__((malloc))
#else
#define ATTR_MALLOC
#endif
#ifdef HAVE_ATTR_WARN_UNUSED_RESULT
#define ATTR_WARN_UNUSED_RESULT __attribute__((warn_unused_result))
#else
#define ATTR_WARN_UNUSED_RESULT
#endif
/*
* SPDX-FileCopyrightText: 2018, 2019 Bruce Cowan <bruce@bcowan.me.uk>
* SPDX-FileCopyrightText: 2018-2020 Bruce Cowan <bruce@bcowan.me.uk>
*
* SPDX-License-Identifier: Apache-2.0
*/
#pragma once
#include "macros.h"
#include <stddef.h>
void * check_calloc (size_t nmemb,
size_t size);
void * check_malloc (size_t size);
size_t size) ATTR_ALLOC_SIZE2(1,2) ATTR_MALLOC;
void * check_malloc (size_t size) ATTR_ALLOC_SIZE(1) ATTR_MALLOC;
void * check_reallocarray (void *ptr,
size_t nmemb,
size_t size);
size_t size) ATTR_ALLOC_SIZE2(2,3) ATTR_MALLOC ATTR_WARN_UNUSED_RESULT;
# SPDX-FileCopyrightText: 2019-2020 Bruce Cowan
#
# SPDX-License-Identifier: CC0-1.0
utils_lib = static_library('utils', ['mem.c', 'utils.c'], dependencies: config_dep)
utils_dep = declare_dependency(link_with: utils_lib,
include_directories: '.')
......@@ -18,12 +18,24 @@ if cc.has_function('reallocarray', prefix: '#define _GNU_SOURCE\n#include <stdli
conf_data.set('HAVE_REALLOCARRAY', 1)
endif
attrs = ['alloc_size', 'malloc', 'warn_unused_result']
foreach attr: attrs
if cc.has_function_attribute(attr)
conf_data.set('HAVE_ATTR_' + attr.to_upper(), 1)
endif
endforeach
if cc.has_header('endian.h')
has_endian_h = true
endif
configure_file(configuration: conf_data, output: 'config.h')
config_dep = declare_dependency(include_directories: '.')
config_h = declare_dependency(
sources: configure_file(
output: 'config.h',
configuration: conf_data,
),
include_directories: '.',
)
if host_machine.system() == 'windows'
socket_deps = [cc.find_library('ws2_32')]
......
......@@ -3,7 +3,7 @@
executable('add', 'add.c', dependencies: utils_dep)
executable('angle', 'angle.c', dependencies: libm)
executable('array-length', 'array-length.c', dependencies: types_dep)
executable('array-length', 'array-length.c', dependencies: utils_dep)
executable('binary', 'binary.c')
executable('binary2', 'binary2.c', dependencies: utils_dep)
executable('complex', 'complex.c', dependencies: libm)
......@@ -15,9 +15,9 @@ executable('fixed-sizeof', 'fixed-sizeof.c')
executable('fgets', 'fgets.c')
executable('gcd', 'gcd.c')
executable('getchar', 'getchar.c')
executable('hashtable-test', 'hashtable-test.c', dependencies: types_dep)
executable('hashtable-test', 'hashtable-test.c', dependencies: utils_dep)
executable('kepler', 'kepler.c', dependencies: libm)
executable('list-test', 'list-test.c', dependencies: types_dep)
executable('list-test', 'list-test.c', dependencies: utils_dep)
executable('next', 'next.c', dependencies: libm)
executable('parrot', 'parrot.c')
executable('sizeof', 'sizeof.c')
......
# SPDX-FileCopyrightText: 2019 Bruce Cowan <bruce@bcowan.me.uk>
# SPDX-FileCopyrightText: 2019-2020 Bruce Cowan <bruce@bcowan.me.uk>
#
# SPDX-License-Identifier: CC0-1.0
executable('thread-incr', 'thread-incr.c',
dependencies: [thread_dep, utils_dep])
executable('thread-incr',
'thread-incr.c',
dependencies: [thread_dep, utils_dep]
)
# SPDX-FileCopyrightText: 2019 Bruce Cowan <bruce@bcowan.me.uk>
# SPDX-FileCopyrightText: 2019-2020 Bruce Cowan <bruce@bcowan.me.uk>
#
# SPDX-License-Identifier: CC0-1.0
if host_machine.system() == 'windows'
udp_server_src = ['udp-server-win.c']
executable('udp-server', 'udp-server-win.c', dependencies: socket_deps)
else
udp_server_src = ['udp-server.c']
executable('udp-server', 'udp-server.c', dependencies: socket_deps)
endif
executable('udp-server', udp_server_src, dependencies: socket_deps)
# SPDX-FileCopyrightText: 2018 Bruce Cowan <bruce@bcowan.me.uk>
# SPDX-FileCopyrightText: 2018-2020 Bruce Cowan <bruce@bcowan.me.uk>
#
# SPDX-License-Identifier: CC0-1.0
avg = executable('array-average',
'array-average.c',
dependencies: [types_dep, glib_dep])
dependencies: [utils_dep, glib_dep])
basic = executable('array-basic',
'array-basic.c',
dependencies: [types_dep, glib_dep])
dependencies: [utils_dep, glib_dep])
empty = executable('array-empty',
'array-empty.c',
dependencies: [types_dep, glib_dep])
dependencies: [utils_dep, glib_dep])
test('array-average', avg)
test('array-basic', basic)
test('array-empty', empty)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment