forked from Marvell-switching/SAI-plugin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
makefile
131 lines (107 loc) · 3.75 KB
/
makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
.PHONY: all
all: lib fpa_deb deb
###############################################################################
ARCH ?= intel
DEBUG ?= yes
DEMO ?= yes
CROSS_COMPILE ?=
BASE_DIR ?= $(shell pwd)
OUT_DIR ?= $(BASE_DIR)/bin/$(ARCH)
FPA_PATH ?= $(BASE_DIR)/FPA-switch/
SAI_H_PATH ?= $(BASE_DIR)/SAI/
SAI_OBJ_PATH ?= $(OUT_DIR)
SCRIPT_PATH ?= $(BASE_DIR)/scripts
PLUGIN_VERSION =`cat version.txt | grep plugin_version | awk {'print $$2'}`
SAI_VERSION =`cat version.txt | grep sai_version | awk {'print $$2'}`
SAI_BASELINE =`cat version.txt | grep sai_baseline | awk {'print $$2'}`
FPA_BASELINE =`cat version.txt | grep fpa_baseline | awk {'print $$2'}`
###############################################################################
CC = $(CROSS_COMPILE)gcc
LD = $(CROSS_COMPILE)gcc
AR = $(CROSS_COMPILE)ar
ECHO = echo
MKDIR_P = mkdir -p
# Name of makefile to include in each sub-module
MAKEFILE := Makefile
# Function compile(flags, output_folder)
#
# Compile a .c file into .o file using the defined toolchain, including dependecy .d file.
# Object and dependency files will be located together in output_folder,
# under the relative path to the source.
#
# Example: $(call compile $(MY_CFLAGS),/local/objects)
# Source file: foo/bar/baz.c
# Targets: /local/objects/foo/bar/baz.o
# /local/objects/foo/bar/baz.d
define compile
@# Create ouput folder
$(MKDIR_P) $(dir $@)
@# create dependency file
$(CC) -M -c $1 $< -o $2/$*.d
@# Duplicate it
cp $2/$*.d $2/$*.tmp
@# Create empty rule per file in dependency rule to avoid "No rule to make target ..." Errors
sed -e 's/#.*//' -e 's/^[^:]*: *//' -e 's/ *\\$$//' -e '/^$$/d' -e 's/$$/ :/' < $2/$*.d >> $2/$*.tmp
@# Change object filename to include full path
sed -e 's/$(subst .,\.,$(notdir $@))/$(subst /,\/,$@)/' < $2/$*.tmp > $2/$*.d
@# Remove temporary file
rm $2/$*.tmp
@# print compilation msg
@ $(ECHO) CC $<
@# compile
$(CC) -c $1 $< -o $@
endef
###############################################################################
MY_CFLAGS = -Wno-pointer-sign -DCPU_LE -Wall -DLINUX -DUNIX -fPIC
ifeq ("$(DEBUG)","yes")
DEBUG_MY_CFLAGS = -g -O0
else
DEBUG_MY_CFLAGS = -O2
endif
MY_CFLAGS += $(DEBUG_MY_CFLAGS)
ifeq ("$(DEMO)", "yes")
MY_CFLAGS += -DDEMO
endif
###############################################################################
MODULES := \
inc \
src
CWD := $(dir $(lastword $(MAKEFILE_LIST)))
include $(patsubst %,$(CWD)%/$(MAKEFILE),$(MODULES))
SAI_H_INC := $(SAI_H_PATH)/inc
FPA_H_INC := $(FPA_PATH)/inc
MY_CFLAGS += \
-I$(FPA_H_INC) \
-I$(SAI_H_INC) \
$(SAI_INC)
###############################################################################
SAI_OBJ := $(patsubst %.c,$(SAI_OBJ_PATH)/%.o,$(SAI_SRC))
SAI_LIB := $(SAI_OBJ_PATH)/lib/libsai
FPA_LIB_PATH := $(FPA_PATH)/bin/$(ARCH)/lib
DEP = $(patsubst %.o,%.d,$(SAI_OBJ))
###############################################################################
MAKE_FPA := make ARCH=$(ARCH) DEBUG=$(DEBUG) DEMO=$(DEMO)
###############################################################################
# %.o - compile .c files to objects
$(OUT_DIR)/%.o: %.c
$(call compile,$(MY_CFLAGS),$(OUT_DIR))
uninstall:
@ rm -fr $(SAI_H_PATH)
@ rm -fr $(FPA_PATH)
clean:
@ rm -fr $(BASE_DIR)/bin
install:
@ $(SCRIPT_PATH)/install_sai.sh $(SAI_H_PATH) $(SAI_BASELINE)
@ $(SCRIPT_PATH)/install_fpa.sh $(FPA_PATH) $(FPA_BASELINE)
lib: install $(SAI_OBJ)
@ $(MKDIR_P) $(SAI_OBJ_PATH)/lib
@ $(AR) -rcs $(SAI_LIB).a $(SAI_OBJ)
@ $(CC) -shared -o $(SAI_LIB).so $(SAI_OBJ) -L$(FPA_LIB_PATH) -lfpa
@ $(ECHO) $(SAI_LIB) Done..
fpa_deb: install
@ cd $(FPA_PATH) && $(MAKE_FPA) deb && cd -
$(SAI_LIB).so:
@ $(ECHO) "SAI lib does not exist !!!"
deb: $(SAI_LIB).so
@ $(SCRIPT_PATH)/make_deb.sh $(OUT_DIR) $(SAI_H_PATH) $(PLUGIN_VERSION) $(SAI_VERSION)
-include $(DEP)