-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathMakefile
198 lines (159 loc) · 5.22 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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
UNAME := $(shell uname)
MIPSEL_TOOLCHAIN_PREFIX=mipsel-openwrt-linux-
ARM_TOOLCHAIN_PREFIX=arm-linux-gnueabihf-
MINGW_TOOLCHAIN_PREFIX=i586-mingw32msvc-
ifndef TARGET
ifeq ($(UNAME), Linux)
TARGET=POSIX
else ifeq ($(findstring MINGW,$(UNAME)), MINGW)
TARGET=WIN32
endif
endif
ifeq ($(TARGET), WIN32)
ifeq ($(UNAME), Linux)
TOOLCHAIN_PREFIX=$(MINGW_TOOLCHAIN_PREFIX)
else
TOOLCHAIN_PREFIX=
endif
endif
ifeq ($(TARGET), LINUX-MIPSEL)
TOOLCHAIN_PREFIX=$(MIPSEL_TOOLCHAIN_PREFIX)
endif
ifeq ($(TARGET), LINUX-ARM)
TOOLCHAIN_PREFIX=$(ARM_TOOLCHAIN_PREFIX)
endif
ifeq ($(TARGET), WIN32)
HAL_IMPL = WIN32
LIB_OBJS_DIR = build_win32
CFLAGS=-g -DWIN32
LDLIBS=-lws2_32
else
HAL_IMPL = POSIX
ifeq ($(TARGET), LINUX-MIPSEL)
LIB_OBJS_DIR = build-mipsel
else ifeq ($(TARGET), LINUX-ARM)
LIB_OBJS_DIR = build-arm
else
LIB_OBJS_DIR = build
endif
CFLAGS=-g
LDLIBS=-lpthread
endif
CC=$(TOOLCHAIN_PREFIX)gcc
CPP=$(TOOLCHAIN_PREFIX)g++
AR=$(TOOLCHAIN_PREFIX)ar
RANLIB=$(TOOLCHAIN_PREFIX)ranlib
EXAMPLE_1 = simple_server_example1
EXAMPLE_1_SOURCES = examples/simple_server_example1.c
EXAMPLE_1_SOURCES += examples/static_model.c
EXAMPLE_2 = mms_client_example
EXAMPLE_2_SOURCES = examples/mms_client_example.c
EXAMPLE_3 = simple_server_example2
EXAMPLE_3_SOURCES = examples/simple_server_example2.c
EXAMPLE_3_SOURCES += examples/static_model.c
EXAMPLE_4 = simple_server_example3
EXAMPLE_4_SOURCES = examples/simple_server_example3.c
EXAMPLE_4_SOURCES += examples/static_model.c
EXAMPLE_5 = mms_server_example
EXAMPLE_5_SOURCES = examples/mms_server_example.c
EXAMPLE_5_SOURCES += examples/static_model.c
ifeq ($(TARGET), WIN32)
EXAMPLE_1 := $(EXAMPLE_1).exe
EXAMPLE_2 := $(EXAMPLE_2).exe
EXAMPLE_3 := $(EXAMPLE_3).exe
EXAMPLE_4 := $(EXAMPLE_4).exe
EXAMPLE_5 := $(EXAMPLE_5).exe
endif
EXAMPLES = $(EXAMPLE_1) $(EXAMPLE_2) $(EXAMPLE_3) $(EXAMPLE_4) $(EXAMPLE_5)
LIB_NAME = $(LIB_OBJS_DIR)/libiec61850.a
INCLUDES = -Iinc
INCLUDES += -Isrc/common
INCLUDES += -Isrc/mms/iso_presentation
INCLUDES += -Isrc/mms/iso_session
INCLUDES += -Isrc/mms/iso_cotp
INCLUDES += -Isrc/mms/iso_acse
INCLUDES += -Isrc/mms/iso_mms/common
INCLUDES += -Isrc/mms/iso_mms/client
INCLUDES += -Isrc/mms/iso_mms/server
INCLUDES += -Isrc/mms/iso_client
INCLUDES += -Isrc/mms/iso_server
INCLUDES += -Isrc/mms/asn1
INCLUDES += -Isrc/mms_mapping
INCLUDES += -Isrc/model
INCLUDES += -Isrc/api
INCLUDES += -Isrc/hal
INCLUDES += -Isrc/hal/thread
INCLUDES += -Isrc/hal/socket
LIB_SOURCE_DIRS = src/mms/iso_acse
LIB_SOURCE_DIRS += src/mms/iso_acse/asn1c
LIB_SOURCE_DIRS += src/mms/iso_presentation/asn1c
LIB_SOURCE_DIRS += src/mms/iso_presentation
LIB_SOURCE_DIRS += src/mms/iso_session
LIB_SOURCE_DIRS += src/common
LIB_SOURCE_DIRS += src/mms/asn1
LIB_SOURCE_DIRS += src/mms/iso_cotp
LIB_SOURCE_DIRS += src/mms/iso_mms/server
LIB_SOURCE_DIRS += src/mms/iso_mms/client
LIB_SOURCE_DIRS += src/mms/iso_client/impl
LIB_SOURCE_DIRS += src/mms/iso_mms/common
LIB_SOURCE_DIRS += src/mms/iso_mms/asn1c
LIB_SOURCE_DIRS += src/mms_mapping
LIB_SOURCE_DIRS += src/model
LIB_SOURCE_DIRS += src/mms/iso_server
LIB_SOURCE_DIRS += src/iedserver/simple_api
LIB_SOURCE_DIRS += src/hal
ifeq ($(HAL_IMPL), WIN32)
LIB_SOURCE_DIRS += src/hal/socket/win32
LIB_SOURCE_DIRS += src/hal/thread/win32
else ifeq ($(HAL_IMPL), POSIX)
LIB_SOURCE_DIRS += src/hal/socket/linux
LIB_SOURCE_DIRS += src/hal/thread/linux
endif
LIB_INCLUDES = -Isrc/mms/iso_presentation/asn1c
LIB_INCLUDES += -Isrc/mms/iso_presentation
LIB_INCLUDES += -Isrc/mms/iso_session
LIB_INCLUDES += -Isrc/mms/iso_cotp
LIB_INCLUDES += -Isrc/mms/iso_acse
LIB_INCLUDES += -Isrc/mms/iso_acse/asn1c
LIB_INCLUDES += -Iinc
LIB_INCLUDES += -Isrc/mms/asn1
LIB_INCLUDES += -Isrc/mms/iso_client
LIB_INCLUDES += -Isrc/mms/iso_mms/server
LIB_INCLUDES += -Isrc/mms/iso_mms/common
LIB_INCLUDES += -Isrc/mms/iso_mms/asn1c
LIB_INCLUDES += -Isrc/mms_mapping
LIB_INCLUDES += -Isrc/model
LIB_INCLUDES += -Isrc/common
LIB_INCLUDES += -Isrc/hal/socket
LIB_INCLUDES += -Isrc/hal/thread
LIB_INCLUDES += -Isrc/hal
LIB_INCLUDES += -Isrc/api
LIB_INCLUDES += -Isrc/mms/iso_server
get_sources_from_directory = $(wildcard $1/*.c)
get_sources = $(foreach dir, $1, $(call get_sources_from_directory,$(dir)))
src_to = $(addprefix $(LIB_OBJS_DIR)/,$(subst .c,$1,$2))
LIB_SOURCES = $(call get_sources,$(LIB_SOURCE_DIRS))
LIB_OBJS = $(call src_to,.o,$(LIB_SOURCES))
all: lib
examples: $(EXAMPLES)
lib: $(LIB_NAME)
$(LIB_NAME): $(LIB_OBJS)
$(AR) r $(LIB_NAME) $(LIB_OBJS)
$(RANLIB) $(LIB_NAME)
$(LIB_OBJS_DIR)/%.o: %.c
@echo compiling $(notdir $<)
$(SILENCE)mkdir -p $(dir $@)
$(CC) $(CFLAGS) -c $(LIB_INCLUDES) $(OUTPUT_OPTION) $<
$(EXAMPLE_1): $(EXAMPLE_1_SOURCES) $(LIB_NAME)
$(CC) $(CFLAGS) -o $(EXAMPLE_1) $(EXAMPLE_1_SOURCES) $(INCLUDES) $(LIB_NAME) $(LDLIBS)
$(EXAMPLE_2): $(EXAMPLE_2_SOURCES) $(LIB_NAME)
$(CC) $(CFLAGS) -o $(EXAMPLE_2) $(EXAMPLE_2_SOURCES) $(INCLUDES) $(LIB_NAME) $(LDLIBS)
$(EXAMPLE_3): $(EXAMPLE_3_SOURCES) $(LIB_NAME)
$(CC) $(CFLAGS) -o $(EXAMPLE_3) $(EXAMPLE_3_SOURCES) $(INCLUDES) $(LIB_NAME) $(LDLIBS)
$(EXAMPLE_4): $(EXAMPLE_4_SOURCES) $(LIB_NAME)
$(CC) $(CFLAGS) -o $(EXAMPLE_4) $(EXAMPLE_4_SOURCES) $(INCLUDES) $(LIB_NAME) $(LDLIBS)
$(EXAMPLE_5): $(EXAMPLE_5_SOURCES) $(LIB_NAME)
$(CC) $(CFLAGS) -o $(EXAMPLE_5) $(EXAMPLE_5_SOURCES) $(INCLUDES) $(LIB_NAME) $(LDLIBS)
clean:
rm -f $(EXAMPLES)
rm -rf $(LIB_OBJS_DIR)