Skip to content

Commit 0a3a8b7

Browse files
authored
Doc & build process improvement (#5)
* added example to the main Readme * made a change to avoid duplication of LDFLAGS
1 parent 515b72c commit 0a3a8b7

File tree

8 files changed

+60
-7
lines changed

8 files changed

+60
-7
lines changed

README.md

+51-2
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,54 @@ Reflection implementation is based on [DWARF](https://en.wikipedia.org/wiki/DWAR
1111

1212
**Features**:
1313

14-
* 'Deep' functionality for printing, copying, comparing, and freeing memory of complex data structures: [demo link](/doc/demo/README.md#how-to-demo).
15-
* Supported on Ubuntu, macOS, Windows (msys2) with gcc or clang
14+
* Reflection for all native C types.
15+
* 'Deep' functionality for printing, copying, comparing, and freeing memory of complex data structures.
16+
* Supported on **Ubuntu, macOS, Windows (msys2)** with **gcc** or **clang**.
17+
18+
[**Example**](/examples/c_app_simplest/):
19+
20+
```c
21+
#include <stdio.h> // printf
22+
#include <stdlib.h> // free
23+
#include <math.h> // M_PI, M_E
24+
#include "metac/reflect.h"
25+
26+
struct test {
27+
int y;
28+
char c;
29+
double pi;
30+
double e;
31+
short _uninitialized_field;
32+
};
33+
34+
int main(){
35+
// we need to use this construction to wrap variable declaration
36+
// to get its type information
37+
WITH_METAC_DECLLOC(decl_location,
38+
struct test t = {
39+
.y = -10,
40+
.c = 'a',
41+
.pi = M_PI,
42+
.e = M_E,
43+
};
44+
)
45+
metac_value_t *p_val = METAC_VALUE_FROM_DECLLOC(decl_location, t);
46+
47+
char * s;
48+
s = metac_entry_cdecl(metac_value_entry(p_val));
49+
// next will output "struct test t = "
50+
printf("%s = ", s);
51+
free(s);
52+
53+
s = metac_value_string(p_val);
54+
// next will output "{.y = -10, .c = 'a', .pi = 3.141593, .e = 2.718282, ._uninitialized_field = 0,};\n"
55+
printf("%s;\n", s);
56+
free(s);
57+
58+
metac_value_delete(p_val);
59+
60+
return 0;
61+
}
62+
```
63+
64+
To get more details please refer to the [How to](/doc/demo/README.md#how-to-demo) document.

doc/demo/README.md

+1
Original file line numberDiff line numberDiff line change
@@ -413,6 +413,7 @@ TPL-_meta_demodb=bin_target
413413
IN-_meta_demodb= \
414414
main.meta.o \
415415
demodb.meta.o
416+
LDFLAGS-_meta_demodb=-Lsrc -lmetac
416417
POST-_meta_demodb=$(METAC_POST_META)
417418

418419
TPL-demodb.reflect.c:=metac_target

doc/demo/step_03/Makefile

+1
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ TPL-_meta_demodb=bin_target
4040
IN-_meta_demodb= \
4141
main.meta.o \
4242
demodb.meta.o
43+
LDFLAGS-_meta_demodb=-Lsrc -lmetac
4344
POST-_meta_demodb=$(METAC_POST_META)
4445

4546
TPL-demodb.reflect.c:=metac_target

doc/demo/step_04/Makefile

+1
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ TPL-_meta_demodb=bin_target
4040
IN-_meta_demodb= \
4141
main.meta.o \
4242
demodb.meta.o
43+
LDFLAGS-_meta_demodb=-Lsrc -lmetac
4344
POST-_meta_demodb=$(METAC_POST_META)
4445

4546
TPL-demodb.reflect.c:=metac_target

doc/demo/step_05/Makefile

+1
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ TPL-_meta_demodb=bin_target
4040
IN-_meta_demodb= \
4141
main.meta.o \
4242
demodb.meta.o
43+
LDFLAGS-_meta_demodb=-Lsrc -lmetac
4344
POST-_meta_demodb=$(METAC_POST_META)
4445

4546
TPL-demodb.reflect.c:=metac_target

examples/c_app_simplest/main.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
#include <stdio.h> // printf
1+
#include <stdio.h> // printf
22
#include <stdlib.h> // free
3-
#include <math.h> // M_PI, M_E
3+
#include <math.h> // M_PI, M_E
44
#include "metac/reflect.h"
55

66
struct test {

mk/bin.mk

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
# generates target to build binaries and .so
22
define bin_target_tpl
33

4-
# add extra LDFLAGS specific for this target
5-
$$(addprefix $1/,$2): LDFLAGS+=$$(LDFLAGS-$2)
4+
# add extra LDFLAGS specific for this target (don't add duplicates)
5+
$$(addprefix $1/,$2): LDFLAGS=$(filter-out $$(LDFLAGS-$2),$(LDFLAGS)) $$(LDFLAGS-$2)
66

77
ifneq ($$(CC-$2),)
88
$$(addprefix $1/,$2): CC=$$(CC-$2)

mk/test.mk

+1-1
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ IN-$(2:.checkmk=_checkmk.reflect.c)=$$(dir $(2:.c=))_meta_$$(notdir $(2:.checkmk
7878

7979
TPL-$$(dir $(2:.checkmk=_checkmk))_meta_$$(notdir $(2:.checkmk=_checkmk)):=bin_target
8080
IN-$$(dir $(2:.checkmk=_checkmk))_meta_$$(notdir $(2:.checkmk=_checkmk))=$(2:.checkmk=_checkmk.meta.o)
81-
LDFLAGS-$$(dir $(2:.checkmk=_checkmk))_meta_$$(notdir $(2:.checkmk=_checkmk))=$$(LDFLAGS-$(2:.checkmk=))
81+
LDFLAGS-$$(dir $(2:.checkmk=_checkmk))_meta_$$(notdir $(2:.checkmk=_checkmk))=$$(LDFLAGS-$(2:.checkmk=_checkmk))
8282
DEPS-$$(dir $(2:.checkmk=_checkmk))_meta_$$(notdir $(2:.checkmk=_checkmk))=$$(DEPS-$(2:.checkmk=))
8383
POST-$$(dir $(2:.checkmk=_checkmk))_meta_$$(notdir $(2:.checkmk=_checkmk))=$$(METAC_POST_META)
8484

0 commit comments

Comments
 (0)