Skip to content

Commit d354947

Browse files
committed
Add an example C project
1 parent 417b9cb commit d354947

File tree

8 files changed

+51
-4
lines changed

8 files changed

+51
-4
lines changed

examples/build/Makefile

+2
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,12 @@ VERSION = 1.0.0
1010
include /usr/local/src/fly/api.mk
1111

1212
# Main targets.
13+
$(eval $(call ADD_TARGET, libfly_c_example, c, BIN))
1314
$(eval $(call ADD_TARGET, libfly_cpp_example, cpp, BIN))
1415
$(eval $(call ADD_TARGET, libfly_jar_example, jar/src/main/java, JAR))
1516

1617
# Test targets.
18+
$(eval $(call ADD_TARGET, libfly_c_example_tests, c/test, TEST))
1719
$(eval $(call ADD_TARGET, libfly_cpp_example_tests, cpp/test, TEST))
1820

1921
# Import the build system.

examples/build/README.md

+9-4
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,15 @@ and extract the downloaded `.tar.gz` in the root system directory:
1717

1818
## Example
1919

20-
The usage example contains a main `Makefile` which imports the libfly build
21-
system from its installed location. It has a single binary target with one
22-
source directory, defined in `files.mk`.
20+
The usage example contains a main `Makefile` which imports the libfly build system from its
21+
installed location. It contains the following example targets:
2322

24-
To build:
23+
1. libfly_c_example - A binary created from a C project.
24+
2. libfly_c_example_tests - An example unit test of the C project.
25+
3. libfly_cpp_example - A binary created from a C++ project.
26+
4. libfly_cpp_example_tests - An example unit test of the C++ project.
27+
5. libfly_jar_example - An executable JAR file created from a Java project.
28+
29+
To build all of the above:
2530

2631
make -C libfly/examples/build

examples/build/c/files.mk

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
SRC_DIRS_$(d) := \
2+
c/some_lib
3+
4+
SRC_$(d) := \
5+
$(d)/main.c

examples/build/c/main.c

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#include "c/some_lib/some_lib.h"
2+
3+
#include <stdio.h>
4+
5+
int main()
6+
{
7+
printf("%d\n", some_value());
8+
return 0;
9+
}

examples/build/c/some_lib/some_lib.c

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#include "c/some_lib/some_lib.h"
2+
3+
int some_value()
4+
{
5+
return 12389;
6+
}

examples/build/c/some_lib/some_lib.h

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#pragma once
2+
3+
int some_value();

examples/build/c/test/files.mk

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
SRC_DIRS_$(d) := \
2+
c/some_lib
3+
4+
SRC_$(d) := \
5+
$(d)/some_lib.c

examples/build/c/test/some_lib.c

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#include "c/some_lib/some_lib.h"
2+
3+
#include <assert.h>
4+
#include <stdio.h>
5+
6+
int main()
7+
{
8+
assert(some_value() == 12389);
9+
10+
printf("Passed!\n");
11+
return 0;
12+
}

0 commit comments

Comments
 (0)