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 -DTB_LOG
46 CC_FLAGS.release := -Os -Wall -c -fmessage-length=0 -std=c99 -fpic
48 CFLAGS += $(CC_FLAGS.$(BUILD)) -DWITH_POSIX $(INC_DIRS)
51 CJSON_SOURCES := $(CJSON_SRC)/cJSON.c
53 OCCOAP_SOURCES := $(OCCOAP_SRC)/occoap.c
54 OCCOAP_SOURCES += $(OCCOAP_SRC)/occoaphelper.c
56 OCTBSTACK_SOURCES := $(OCTBSTACK_SRC)/ocstack.c
57 OCTBSTACK_SOURCES += $(OCTBSTACK_SRC)/occlientcb.c
58 OCTBSTACK_SOURCES += $(OCTBSTACK_SRC)/ocserverrequest.c
59 OCTBSTACK_SOURCES += $(OCTBSTACK_SRC)/ocresource.c
61 SOURCES := $(CJSON_SOURCES)
62 SOURCES += $(OCCOAP_SOURCES)
63 SOURCES += $(OCTBSTACK_SOURCES)
65 all: make_lcoap objdirs obj_build liboctbstack.a #print_vars
68 $(MAKE) -C $(LCOAP_DIR)
72 mkdir -p $(OBJ_DIR)/$(BUILD)
76 # Output all *.o files to $(OBJ_DIR)/$(BUILD)
77 $(foreach source,$(SOURCES), $(CC) $(LDLIBS) $(CFLAGS) $(source) -o $(patsubst %.c, %.o, $(patsubst %, $(OBJ_DIR)/$(BUILD)/%, $(notdir $(source))));)
81 # Unpackage libcoap.a to $(OBJ_DIR)/$(BUILD). The output objects from OCStack and OCCoap are already at this location
82 @cd $(OBJ_DIR)/$(BUILD) && ar -x $(LCOAP_DIR)/libcoap.a
83 # Repackage all the objects at this location into a single archive. This is OCStack, OCCoap, and LibCoap (LibCoap contains OCRandom, OCLogger, and OCSocket.).
84 ar -r $@ $(OBJ_DIR)/$(BUILD)/*.o
86 .PHONY: clean print_vars
90 rm -f $(OBJ_DIR)/$(BUILD)/*.o
91 rm -f $(ROOT_DIR)/liboctbstack.a
94 deepclean: $(ROOT_DIR)
95 @echo "Deep-Cleaning all."
96 rm -f $(OBJ_DIR)/$(BUILD)/*.o
97 rm -f $(ROOT_DIR)/liboctbstack.a
99 $(MAKE) clean -C $(LCOAP_DIR)
103 @echo 'INCLUDES ARE: '$(value INC_DIRS)
105 @echo 'SOURCE FILES ARE: '$(value SOURCES)
107 @echo 'OBJ_DIR/BUILD is: '$(OBJ_DIR)'/'$(BUILD)
109 @echo 'ROOT_DIR is: '$(ROOT_DIR)