Skip to content

Commit 583ee8c

Browse files
committed
build: Quick Meson
1 parent ebaa760 commit 583ee8c

File tree

9 files changed

+125
-31
lines changed

9 files changed

+125
-31
lines changed

.vscode/c_cpp_properties.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"cStandard": "c89",
66
"intelliSenseMode": "linux-gcc-x64",
77
"compilerPath": "/usr/bin/clang",
8-
"cppStandard": "c++14"
8+
"includePath": ["./include"]
99
}
1010
],
1111
"version": 4

.vscode/settings.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@
1616
"string.h": "c",
1717
"main.h": "c",
1818
"unistd.h": "c",
19-
"limits.h": "c"
19+
"limits.h": "c",
20+
"pwd.h": "c",
21+
"util.h": "c"
2022
},
2123
"C_Cpp.files.exclude": {
2224
"**/cosmopolitan": true,

bin/d.c

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#include <stdbool.h>
2+
#include <stdio.h>
3+
#include <stdlib.h>
4+
#include <string.h>
5+
#include <unistd.h>
6+
#include <sys/types.h>
7+
#include <sys/stat.h>
8+
#include <ctype.h>
9+
#include <linux/limits.h>
10+
#include <pwd.h>
11+
12+
#include "util.h"
13+
14+
int main(int argc, char *argv[]) {
15+
struct Cli cli = parse_cli(argc, argv);
16+
if (cli.help) {
17+
show_help();
18+
exit(0);
19+
}
20+
struct Config config = parse_config(cli.config_file);
21+
22+
if (STR_EQ(cli.command, "init")) {
23+
command_init(cli, config);
24+
} else if (STR_EQ(cli.command, "list")) {
25+
command_list(cli, config);
26+
} else if (STR_EQ(cli.command, "deploy")) {
27+
command_deploy(cli, config);
28+
} else if (STR_EQ(cli.command, "replace")) {
29+
command_replace(cli, config);
30+
} else if (STR_EQ(cli.command, "undeploy")) {
31+
command_undeploy(cli, config);
32+
} else {
33+
die("Command not accounted for");
34+
}
35+
}

include/meson.build

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
install_headers('util.h')

meson.build

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
project('d', 'c',
2+
version : '0.1.0',
3+
license : 'MPL-2.0')
4+
add_global_arguments(language : 'c')
5+
6+
my_inc = include_directories('include')
7+
my_inc2 = include_directories('src')
8+
install_headers('./src/util.h')
9+
10+
libsimple_proj = subproject('inih')
11+
inih_dep = libsimple_proj.get_variable('inih_dep')
12+
inih_inc = libsimple_proj.get_variable('inc_inih')
13+
14+
15+
# subdir('include')
16+
# subdir('src')
17+
my_lib = static_library('mylib',
18+
'src/util.c',
19+
include_directories : [my_inc2, inih_inc])
20+
21+
#subdir('test')
22+
my_dep = declare_dependency(link_with : my_lib,
23+
include_directories : my_inc)
24+
#pkg_mod = import('pkgconfig')
25+
#pkg_mod.generate(libraries : foolib,
26+
# version : '1.0',
27+
# name : 'libfoobar',
28+
# filebase : 'foobar',
29+
# description : 'A Library to barnicate your foos.')
30+
build_args = [
31+
]
32+
project_source_files = [
33+
'bin/d.c'
34+
]
35+
project_dependencies = [
36+
my_dep
37+
]
38+
build_args += [
39+
'-DPROJECT_NAME=' + meson.project_name(),
40+
'-DPROJECT_VERSION=' + meson.project_version(),
41+
]
42+
43+
44+
45+
project_dependencies += inih_dep
46+
project_target = executable(
47+
meson.project_name(),
48+
project_source_files,
49+
dependencies: project_dependencies,
50+
install : false,
51+
include_directories : my_inc2,
52+
c_args : build_args,
53+
)
54+
55+
test('basic', project_target)

src/meson.build

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
sources = ['util.c']
2+
3+
headers = ['util.h']
4+
5+
# libmeson_example = library('meson-example-' + meson_example_api_version,
6+
# sources,
7+
# soversion: meson_example_soversion,
8+
# version: meson_example_version,
9+
# install: true,
10+
# )
11+
12+
# pkg.generate(
13+
# filebase: 'meson-example-' + meson_example_api_version,
14+
# version: meson.project_version(),
15+
# name: 'meson-example',
16+
# subdirs: 'meson-example-' + meson_example_api_version,
17+
# description: 'A library demostrating doing it right in meson',
18+
# libraries: libmeson_example
19+
# )
20+
21+
# install_headers (headers,
22+
# subdir: 'meson-example-@0@'.format(meson_example_api_version))

main.c renamed to src/util.c

Lines changed: 4 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313
#error "Unsupported platform"
1414
#endif
1515

16-
#include "./inih/ini.h"
17-
#include "main.h"
16+
#include "ini.h"
17+
#include "util.h"
1818

1919
/** PLUMBING UTILITY FUNCTIONS */
2020
char *compat_getenv(char *var) {
@@ -62,7 +62,7 @@ void show_help() {
6262
/** APPLICATION UTILITY FUNCTIONS */
6363
void deploy_symlink(struct Entry entry) {
6464
#ifdef __linux__
65-
symlink(source, target);
65+
// symlink(source, target);
6666
#endif
6767
}
6868

@@ -305,7 +305,7 @@ char pwddir[PATH_MAX];
305305
if (thing == NULL) {
306306
thing = config->current_entry.source;
307307
}
308-
deploy_symlink(entry);
308+
// deploy_symlink(entry);
309309

310310
config->current_entry_ready = false;
311311
struct Entry entry = {
@@ -446,28 +446,3 @@ struct Cli parse_cli(int argc, char *argv[]) {
446446

447447
return cli;
448448
}
449-
450-
#ifdef IS_NOT_TEST
451-
int main(int argc, char *argv[]) {
452-
struct Cli cli = parse_cli(argc, argv);
453-
if (cli.help) {
454-
show_help();
455-
exit(0);
456-
}
457-
struct Config config = parse_config(cli.config_file);
458-
459-
if (STR_EQ(cli.command, "init")) {
460-
command_init(cli, config);
461-
} else if (STR_EQ(cli.command, "list")) {
462-
command_list(cli, config);
463-
} else if (STR_EQ(cli.command, "deploy")) {
464-
command_deploy(cli, config);
465-
} else if (STR_EQ(cli.command, "replace")) {
466-
command_replace(cli, config);
467-
} else if (STR_EQ(cli.command, "undeploy")) {
468-
command_undeploy(cli, config);
469-
} else {
470-
die("Command not accounted for");
471-
}
472-
}
473-
#endif

main.h renamed to src/util.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,11 @@ struct ExpandStringResult {
5151
enum ExpandStringCode code;
5252
char *str;
5353
};
54+
int parse_config_handler(void *data, const char *section, const char *key, const char *value);
55+
struct Cli parse_cli(int argc, char *argv[]);
56+
struct Config parse_config(char *config_file);
5457

58+
void die(char *message);
5559
struct ExpandStringResult expand_string(char *input, struct ExpandStringVars vars);
5660
void command_init(struct Cli cli, struct Config config);
5761
void command_list(struct Cli cli, struct Config config);

test/test.c

Whitespace-only changes.

0 commit comments

Comments
 (0)