1 # override with `make BUILD=release`
2 # default to release build
12 OBJ_DIR = $(ROOT_DIR)/obj
15 OCLOGGER_DIR = $(ROOT_DIR)/logger
16 OCRANDOM_DIR = $(ROOT_DIR)/ocrandom
17 OCSOCKET_DIR = $(ROOT_DIR)/ocsocket
18 LCOAP_DIR = $(ROOT_DIR)/libcoap-4.1.1
19 OCCOAP_DIR = $(ROOT_DIR)/occoap
20 OCTBSTACK_DIR = $(ROOT_DIR)/stack
21 UTILS_DIR = $(ROOT_DIR)/../../ccf-utilities/tb
22 CJSON_DIR = $(UTILS_DIR)/cJSON
24 OCCOAP_SRC = $(OCCOAP_DIR)/src
25 OCTBSTACK_SRC = $(OCTBSTACK_DIR)/src
26 CJSON_SRC = $(CJSON_DIR)
28 OCLOGGER_INC = $(OCLOGGER_DIR)/include
29 OCRANDOM_INC = $(OCRANDOM_DIR)/include
30 OCSOCKET_INC = $(OCSOCKET_DIR)/include
31 LCOAP_INC = $(LCOAP_DIR)
32 OCCOAP_INC = $(OCCOAP_DIR)/include
33 OCTBSTACK_INC = $(OCTBSTACK_DIR)/include
34 CJSON_INC = $(CJSON_DIR)
36 INC_DIRS := -I$(OCLOGGER_INC)
37 INC_DIRS += -I$(OCRANDOM_INC)
38 INC_DIRS += -I$(OCSOCKET_INC)
39 INC_DIRS += -I$(LCOAP_INC)
40 INC_DIRS += -I$(OCCOAP_INC)
41 INC_DIRS += -I$(OCTBSTACK_INC)
42 INC_DIRS += -I$(OCTBSTACK_INC)/internal
43 INC_DIRS += -I$(CJSON_INC)
45 CC_FLAGS.debug := -O0 -g3 -Wall -c -fmessage-length=0 -pedantic -std=c99 -fpic \
47 CC_FLAGS.release := -Os -Wall -c -fmessage-length=0 -std=c99 -fpic
49 CFLAGS += $(CC_FLAGS.$(BUILD)) -DWITH_POSIX $(INC_DIRS)
52 CJSON_SOURCES := $(CJSON_SRC)/cJSON.c
54 OCCOAP_SOURCES := $(OCCOAP_SRC)/occoap.c
55 OCCOAP_SOURCES += $(OCCOAP_SRC)/occoaphelper.c
57 OCTBSTACK_SOURCES := $(OCTBSTACK_SRC)/ocstack.c
58 OCTBSTACK_SOURCES += $(OCTBSTACK_SRC)/occlientcb.c
59 OCTBSTACK_SOURCES += $(OCTBSTACK_SRC)/ocserverrequest.c
60 OCTBSTACK_SOURCES += $(OCTBSTACK_SRC)/ocresource.c
61 OCTBSTACK_SOURCES += $(OCTBSTACK_SRC)/ocobserve.c
63 SOURCES := $(CJSON_SOURCES)
64 SOURCES += $(OCCOAP_SOURCES)
65 SOURCES += $(OCTBSTACK_SOURCES)
67 all: make_lcoap objdirs obj_build liboctbstack.a #print_vars
70 $(MAKE) -C $(LCOAP_DIR) "BUILD=$(BUILD)"
74 mkdir -p $(OBJ_DIR)/$(BUILD)
78 # Output all *.o files to $(OBJ_DIR)/$(BUILD)
79 $(foreach source,$(SOURCES), $(CC) $(LDLIBS) $(CFLAGS) $(source) -o $(patsubst %.c, %.o, $(patsubst %, $(OBJ_DIR)/$(BUILD)/%, $(notdir $(source))));)
83 # Unpackage libcoap.a to $(OBJ_DIR)/$(BUILD). The output objects from OCStack and OCCoap are already at this location
84 @cd $(OBJ_DIR)/$(BUILD) && ar -x $(LCOAP_DIR)/$(BUILD)/libcoap.a
85 # Repackage all the objects at this location into a single archive. This is OCStack, OCCoap, and LibCoap (LibCoap contains OCRandom, OCLogger, and OCSocket.).
86 ar -r $@ $(OBJ_DIR)/$(BUILD)/*.o
88 .PHONY: clean print_vars
94 deepclean: legacy_deepclean
98 legacy_clean: $(ROOT_DIR)
100 rm -f $(OBJ_DIR)/$(BUILD)/*.o
101 rm -f $(ROOT_DIR)/liboctbstack.a
104 legacy_deepclean: $(ROOT_DIR)
105 @echo "Deep-Cleaning all."
106 rm -f $(OBJ_DIR)/$(BUILD)/*.o
107 rm -f $(ROOT_DIR)/liboctbstack.a
109 $(MAKE) clean -C $(LCOAP_DIR)
113 @echo 'INCLUDES ARE: '$(value INC_DIRS)
115 @echo 'SOURCE FILES ARE: '$(value SOURCES)
117 @echo 'OBJ_DIR/BUILD is: '$(OBJ_DIR)'/'$(BUILD)
119 @echo 'ROOT_DIR is: '$(ROOT_DIR)