Skip to content

Commit 4d15639

Browse files
Don't compile bin/cbordump in freestanding builds
Signed-off-by: Thiago Macieira <[email protected]>
1 parent f29859d commit 4d15639

File tree

2 files changed

+20
-10
lines changed

2 files changed

+20
-10
lines changed

Makefile

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ pkgconfigdir = $(libdir)/pkgconfig
88

99
CFLAGS = -Wall -Wextra
1010
LDFLAGS_GCSECTIONS = -Wl,--gc-sections
11-
LDFLAGS = $(if $(gc_sections-pass),$(LDFLAGS_GCSECTIONS))
11+
LDFLAGS += $(if $(gc_sections-pass),$(LDFLAGS_GCSECTIONS))
1212

1313
GIT_ARCHIVE = git archive --prefix="$(PACKAGE)/" -9
1414
INSTALL = install
@@ -28,13 +28,6 @@ TINYCBOR_FREESTANDING_SOURCES = \
2828
src/cborparser.c \
2929
src/cborpretty.c \
3030
#
31-
TINYCBOR_SOURCES = \
32-
$(TINYCBOR_FREESTANDING_SOURCES) \
33-
src/cborparser_dup_string.c \
34-
src/cborpretty_stdio.c \
35-
src/cbortojson.c \
36-
src/cborvalidation.c \
37-
#
3831
CBORDUMP_SOURCES = tools/cbordump/cbordump.c
3932

4033
BUILD_SHARED = $(shell file -L /bin/sh 2>/dev/null | grep -q ELF && echo 1)
@@ -87,6 +80,16 @@ endif
8780

8881
-include .config
8982

83+
ifeq ($(freestanding-pass),1)
84+
TINYCBOR_SOURCES = $(TINYCBOR_FREESTANDING_SOURCES)
85+
else
86+
TINYCBOR_SOURCES = \
87+
$(TINYCBOR_FREESTANDING_SOURCES) \
88+
src/cborparser_dup_string.c \
89+
src/cborpretty_stdio.c \
90+
src/cbortojson.c \
91+
src/cborvalidation.c \
92+
#
9093
# if open_memstream is unavailable on the system, try to implement our own
9194
# version using funopen or fopencookie
9295
ifeq ($(open_memstream-pass),)
@@ -97,6 +100,7 @@ ifeq ($(open_memstream-pass),)
97100
TINYCBOR_SOURCES += src/open_memstream.c
98101
endif
99102
endif
103+
endif
100104

101105
# json2cbor depends on an external library (cjson)
102106
ifneq ($(cjson-pass)$(system-cjson-pass),)
@@ -114,7 +118,8 @@ endif
114118
all: .config \
115119
$(if $(subst 0,,$(BUILD_STATIC)),lib/libtinycbor.a) \
116120
$(if $(subst 0,,$(BUILD_SHARED)),lib/libtinycbor.so) \
117-
bin/cbordump tinycbor.pc
121+
$(if $(freestanding-pass),,bin/cbordump) \
122+
tinycbor.pc
118123
all: $(if $(JSON2CBOR_SOURCES),bin/json2cbor)
119124
check: tests/Makefile | $(BINLIBRARY)
120125
$(MAKE) -C tests check

Makefile.configure

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
ALLTESTS = open_memstream funopen fopencookie gc_sections \
2-
system-cjson cjson
2+
system-cjson cjson freestanding
33
MAKEFILE := $(lastword $(MAKEFILE_LIST))
44
OUT :=
55

@@ -8,6 +8,11 @@ PROGRAM-funopen = extern int funopen(); int main() { return funopen(); }
88
PROGRAM-fopencookie = extern int fopencookie(); int main() { return fopencookie(); }
99
PROGRAM-gc_sections = int main() {}
1010
CCFLAGS-gc_sections = -Wl,--gc-sections
11+
PROGRAM-freestanding = \#if !defined(__STDC_HOSTED__) || __STDC_HOSTED__-0 == 1\n
12+
PROGRAM-freestanding += \#error Hosted implementation\n
13+
PROGRAM-freestanding += \#endif\n
14+
PROGRAM-freestanding += int main() {}
15+
CCFLAGS-freestanding = $(CFLAGS)
1116

1217
PROGRAM-cjson = \#include <stdlib.h>\n
1318
PROGRAM-cjson += \#include <cjson/cJSON.h>\n

0 commit comments

Comments
 (0)