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
55 OCTBSTACK_SOURCES := $(OCTBSTACK_SRC)/ocstack.c
56 OCTBSTACK_SOURCES += $(OCTBSTACK_SRC)/occlientcb.c
57 OCTBSTACK_SOURCES += $(OCTBSTACK_SRC)/ocserverrequest.c
59 SOURCES := $(CJSON_SOURCES)
60 SOURCES += $(OCCOAP_SOURCES)
61 SOURCES += $(OCTBSTACK_SOURCES)
63 all: make_lcoap objdirs obj_build liboctbstack.a #print_vars
66 $(MAKE) -C $(LCOAP_DIR)
70 mkdir -p $(OBJ_DIR)/$(BUILD)
74 $(foreach source,$(SOURCES), $(CC) $(LDLIBS) $(CFLAGS) $(source) -o $(patsubst %.c, %.o, $(patsubst %, $(OBJ_DIR)/$(BUILD)/%, $(notdir $(source))));) # Output all *.o files to $(OBJ_DIR)/$(BUILD)
78 @cd $(OBJ_DIR)/$(BUILD) && ar -x $(LCOAP_DIR)/libcoap.a # Unpackage libcoap.a to $(OBJ_DIR)/$(BUILD). The output objects from OCStack and OCCoap are already at this location
79 ar -r $@ $(OBJ_DIR)/$(BUILD)/*.o # Repackage all the objects at this location into a single archive. This is OCStack, OCCoap, and LibCoap (LibCoap contains OCRandom, OCLogger, and OCSocket.).
81 .PHONY: clean print_vars
85 rm -f $(OBJ_DIR)/$(BUILD)/*.o
86 rm -f $(ROOT_DIR)/liboctbstack.a
88 deepclean: $(ROOT_DIR)
89 @echo "Deep-Cleaning all."
90 rm -f $(OBJ_DIR)/$(BUILD)/*.o
91 rm -f $(ROOT_DIR)/liboctbstack.a
92 $(MAKE) clean -C $(LCOAP_DIR)
96 @echo 'INCLUDES ARE: '$(value INC_DIRS)
98 @echo 'SOURCE FILES ARE: '$(value SOURCES)
100 @echo 'OBJ_DIR/BUILD is: '$(OBJ_DIR)'/'$(BUILD)
102 @echo 'ROOT_DIR is: '$(ROOT_DIR)