1# 2# %CopyrightBegin% 3# 4# Copyright Ericsson AB 2001-2020. All Rights Reserved. 5# 6# Licensed under the Apache License, Version 2.0 (the "License"); 7# you may not use this file except in compliance with the License. 8# You may obtain a copy of the License at 9# 10# http://www.apache.org/licenses/LICENSE-2.0 11# 12# Unless required by applicable law or agreed to in writing, software 13# distributed under the License is distributed on an "AS IS" BASIS, 14# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15# See the License for the specific language governing permissions and 16# limitations under the License. 17# 18# %CopyrightEnd% 19 20include $(ERL_TOP)/make/target.mk 21 22EBIN = ../../ebin 23MEGACO_INCLUDEDIR = ../../include 24 25include $(ERL_TOP)/make/$(TARGET)/otp.mk 26 27# ---------------------------------------------------- 28# Application version 29# ---------------------------------------------------- 30include ../../vsn.mk 31VSN=$(MEGACO_VSN) 32 33# ---------------------------------------------------- 34# The following variables differ on different systems, we set 35# reasonable defaults, if something different is needed it should 36# be set for that system only. 37# ---------------------------------------------------- 38 39FLEX_VSN = $(shell flex --version) 40 41TMP_CFLAGS = @DED_BASIC_CFLAGS@ @OTP_EXTRA_FLAGS@ 42ifeq ($(TYPE),valgrind) 43CFLAGS = $(subst -O2, , $(TMP_CFLAGS)) -DVALGRIND 44else 45CFLAGS = $(TMP_CFLAGS) 46endif 47CC = @DED_CC@ 48CFLAGS_MT = $(CFLAGS) @DED_THR_DEFS@ 49LD = @DED_LD@ 50LDFLAGS = @DED_LDFLAGS@ 51LEX = @LEX@ 52LEXLIB = @LEXLIB@ 53PERL = @PERL@ 54 55# Shall we build the flex scanner or not. 56# We assume that it does not exist on windows... 57ifeq ($(ENABLE_MEGACO_FLEX_SCANNER),) 58ifeq ($(findstring win32,$(TARGET)), win32) 59ENABLE_MEGACO_FLEX_SCANNER = false 60ENABLE_REENTRANT_MEGACO_FLEX_SCANNER = false 61else 62ENABLE_MEGACO_FLEX_SCANNER = @ENABLE_MEGACO_FLEX_SCANNER@ 63ENABLE_REENTRANT_MEGACO_FLEX_SCANNER = @ENABLE_REENTRANT_MEGACO_FLEX_SCANNER@ 64endif 65endif 66ERL_COMPILE_FLAGS += -DENABLE_MEGACO_FLEX_SCANNER=$(ENABLE_MEGACO_FLEX_SCANNER) 67 68ifeq ($(ENABLE_REENTRANT_MEGACO_FLEX_SCANNER),true) 69CFLAGS_MT += -DMEGACO_REENTRANT_FLEX_SCANNER 70MT_LEX_FLAGS += -R 71ERL_COMPILE_FLAGS += -DMEGACO_REENTRANT_FLEX_SCANNER=true 72else 73ERL_COMPILE_FLAGS += -DMEGACO_REENTRANT_FLEX_SCANNER=false 74endif 75 76# Shall the library be built with line-number checks or without 77ifeq ($(ENABLE_MEGACO_FLEX_SCANNER_LINENO),) 78# This is not really needed in this case (since we don't support 79# this for windows), but just to ensure that the variable _has_ 80# a value... 81ifeq ($(findstring win32,$(TARGET)), win32) 82ENABLE_MEGACO_FLEX_SCANNER_LINENO = true 83else 84ENABLE_MEGACO_FLEX_SCANNER_LINENO = @ENABLE_MEGACO_FLEX_SCANNER_LINENO@ 85endif 86endif 87 88PRIVDIR = ../../priv 89LIBDIR = $(PRIVDIR)/lib/$(TARGET) 90OBJDIR = $(PRIVDIR)/obj/$(TARGET) 91 92# ---------------------------------------------------- 93# Release directory specification 94# ---------------------------------------------------- 95RELSYSDIR = $(RELEASE_PATH)/lib/megaco-$(VSN) 96 97 98# ---------------------------------------------------- 99# Target Specs 100# ---------------------------------------------------- 101 102include modules.mk 103 104ERL_FILES = $(MODULES:%=%.erl) 105 106TARGET_FILES = \ 107 $(MODULES:%=$(EBIN)/%.$(EMULATOR)) 108 109FLEX_SRC = $(FLEX_MODULES:%=%.flex.src) 110FLEX_FILES = $(STD_DRV).flex $(MT_DRV).flex 111 112C_TARGETS = $(STD_DRV).c $(MT_DRV).c 113 114 115# ---------------------------------------------------- 116# Misc Macros 117# ---------------------------------------------------- 118 119STD_DRV_NAME=-DMEGACO_DRV_NAME=\"$(STD_DRV)\" 120MT_DRV_NAME=-DMEGACO_DRV_NAME=\"$(MT_DRV)\" 121 122ifeq ($(findstring win32,$(TARGET)), win32) 123FLEX_SCANNER_SO = 124SOLIBS = $(FLEX_SCANNER_SO) 125else 126FLEX_SCANNER_SO = $(LIBDIR)/$(STD_DRV).@DED_EXT@ 127FLEX_SCANNER_MT_SO = $(LIBDIR)/$(MT_DRV).@DED_EXT@ 128SOLIBS = $(FLEX_SCANNER_SO) $(FLEX_SCANNER_MT_SO) 129endif 130 131 132# ---------------------------------------------------- 133# FLAGS 134# ---------------------------------------------------- 135ifeq ($(TYPE),debug) 136ERL_COMPILE_FLAGS += -Ddebug 137endif 138 139include ../app/megaco.mk 140 141ERL_COMPILE_FLAGS += \ 142 $(MEGACO_ERL_COMPILE_FLAGS) \ 143 -I../../include 144 145ifeq ($(MFS_DEBUG),true) 146CFLAGS += -DMFS_DEBUG=true 147endif 148 149ifeq ($(MFS_FLEX_PERF),true) 150STD_LEX_FLAGS += -p 151MT_LEX_FLAGS += -p 152endif 153 154ifeq ($(MFS_FLEX_DEBUG),true) 155CFLAGS += -DMFS_FLEX_DEBUG=1 156STD_LEX_FLAGS += -d 157MT_LEX_FLAGS += -d 158else 159CFLAGS += -DMFS_FLEX_DEBUG=0 160endif 161 162CFLAGS += @DED_INCLUDE@ -I$(ERL_TOP)/erts/$(TARGET) $(DRV_FLAGS) -funroll-loops -Wall 163 164#ifneq ($(FLEX_VSN),) 165#CFLAGS += -DFLEX_VERSION="$(FLEX_VSN)" 166#else 167#CFLAGS += -DFLEX_VERSION=unknown 168#endif 169 170ifeq ($(ENABLE_MEGACO_FLEX_SCANNER_LINENO),true) 171CFLAGS += -DMEGACO_LINENO 172STD_LEX_FLAGS += -Ca 173MT_LEX_FLAGS += -Ca 174ifeq ($(ENABLE_REENTRANT_MEGACO_FLEX_SCANNER),true) 175MT_LEX_FLAGS += --yylineno 176endif 177else 178CFLAGS += -DMEGACO_TOKENCNT 179STD_LEX_FLAGS += -Cfe 180MT_LEX_FLAGS += -Cfe 181endif 182 183 184 185# ---------------------------------------------------- 186# Targets 187# ---------------------------------------------------- 188 189ifeq ($(ENABLE_MEGACO_FLEX_SCANNER),true) 190debug opt: $(TARGET_FILES) $(C_TARGETS) solibs 191else 192debug opt: $(TARGET_FILES) 193endif 194 195clean: 196 rm -f $(TARGET_FILES) 197 rm -f $(FLEX_FILES) 198 rm -f $(C_TARGETS) 199 rm -f $(SOLIBS) 200 rm -f errs core *~ 201 202docs: 203 204info: 205 @echo "ENABLE_MEGACO_FLEX_SCANNER = $(ENABLE_MEGACO_FLEX_SCANNER)" 206 @echo "ENABLE_MEGACO_FLEX_SCANNER_LINENO = $(ENABLE_MEGACO_FLEX_SCANNER_LINENO)" 207 @echo "ENABLE_REENTRANT_MEGACO_FLEX_SCANNER = $(ENABLE_REENTRANT_MEGACO_FLEX_SCANNER)" 208 @echo "" 209 @echo "FLEX_VSN = $(FLEX_VSN)" 210 @echo "" 211 @echo "CFLAGS = $(CFLAGS)" 212 @echo "CFLAGS_MT = $(CFLAGS_MT)" 213 @echo "DRV_FLAGS = $(DRV_FLAGS)" 214 @echo "STD_LEX_FLAGS = $(STD_LEX_FLAGS)" 215 @echo "MT_LEX_FLAGS = $(MT_LEX_FLAGS)" 216 @echo "" 217 @echo "MODULES = $(MODULES)" 218 @echo "ERL_FILES = $(ERL_FILES)" 219 @echo "TARGET_FILES = $(TARGET_FILES)" 220 @echo "" 221 @echo "FLEX_MODULES = $(FLEX_MODULES)" 222 @echo "FLEX_SRC = $(FLEX_SRC)" 223 @echo "FLEX_FILES = $(FLEX_FILES)" 224 @echo "" 225 @echo "C_TARGETS = $(C_TARGETS)" 226 @echo "" 227 @echo "LIBDIR = $(LIBDIR)" 228 @echo "LEXLIB = $(LEXLIB)" 229 @echo "" 230 @echo "STD_DRV = $(STD_DRV)" 231 @echo "MT_DRV = $(MT_DRV)" 232 @echo "" 233 @echo "STD_DRV_NAME = $(STD_DRV_NAME)" 234 @echo "MT_DRV_NAME = $(MT_DRV_NAME)" 235 @echo "" 236 @echo "SOLIBS = $(SOLIBS)" 237 238 239# ---------------------------------------------------- 240# Release Target 241# ---------------------------------------------------- 242include $(ERL_TOP)/make/otp_release_targets.mk 243 244 245release_spec: opt 246 $(INSTALL_DIR) "$(RELSYSDIR)/ebin" 247 $(INSTALL_DIR) "$(RELSYSDIR)/src" 248 $(INSTALL_DIR) "$(RELSYSDIR)/src/flex" 249 $(INSTALL_DIR) "$(RELSYSDIR)/priv/lib" 250 $(INSTALL_DIR) "$(RELSYSDIR)/include" 251 $(INSTALL_DATA) $(ERL_FILES) $(INTERNAL_HRL_FILES) "$(RELSYSDIR)/src/flex" 252 $(INSTALL_DATA) $(TARGET_FILES) "$(RELSYSDIR)/ebin" 253ifeq ($(ENABLE_MEGACO_FLEX_SCANNER),true) 254 $(INSTALL_DATA) $(FLEX_FILES) $(C_TARGETS) "$(RELSYSDIR)/src/flex" 255 $(INSTALL_PROGRAM) $(SOLIBS) "$(RELSYSDIR)/priv/lib" 256endif 257 258 259release_docs_spec: 260 261# megaco_flex_scanner_drv.flex: megaco_flex_scanner_drv.flex.src 262# ifeq ($(ENABLE_MEGACO_FLEX_SCANNER_LINENO),true) 263# ifeq ($(ENABLE_REENTRANT_MEGACO_FLEX_SCANNER),true) 264# @printf "\treentrant [flex] scanner lineno enabled\n" 265# $(PERL) -p -e \ 266# 's/%FLEX_VERSION%/$(FLEX_VSN)/ ; \ 267# s/%MEGACO_YY_LINENO_OPTION%/%option yylineno/ ; \ 268# s/%MEGACO_YY_REENTRANT_OPTION%/%option reentrant/ ; \ 269# s/%MEGACO_DUMMY_DECL_YY_LINENO%/\/* static int yylineno = 1; *\//' \ 270# < $< > $@ 271# else 272# @printf "\tnon-reentrant [flex] scanner lineno enabled\n" 273# $(PERL) -p -e \ 274# 's/%FLEX_VERSION%/$(FLEX_VSN)/ ; \ 275# s/%MEGACO_YY_LINENO_OPTION%/%option yylineno/ ; \ 276# s/%MEGACO_YY_REENTRANT_OPTION%/\/\* %option reentrant \*\// ; \ 277# s/%MEGACO_DUMMY_DECL_YY_LINENO%/\/* static int yylineno = 1; *\//' \ 278# < $< > $@ 279# endif 280# else 281# ifeq ($(ENABLE_REENTRANT_MEGACO_FLEX_SCANNER),true) 282# @printf "\treentrant [flex] scanner lineno disabled\n" 283# $(PERL) -p -e \ 284# 's/%FLEX_VERSION%/$(FLEX_VSN)/ ; \ 285# s/%MEGACO_YY_LINENO_OPTION%/\/\* %option yylineno \*\// ; \ 286# s/%MEGACO_YY_REENTRANT_OPTION%/%option reentrant/ ; \ 287# s/%MEGACO_DUMMY_DECL_YY_LINENO%/\/* static int yylineno = 1; - REENTRANT SCANNER*\//' \ 288# < $< > $@ 289# else 290# @printf "\tnon-reentrant [flex] scanner lineno disabled\n" 291# $(PERL) -p -e \ 292# 's/%FLEX_VERSION%/$(FLEX_VSN)/ ; \ 293# s/%MEGACO_YY_LINENO_OPTION%/\/\* %option yylineno \*\// ; \ 294# s/%MEGACO_YY_REENTRANT_OPTION%/\/\* %option reentrant \*\// ; \ 295# s/%MEGACO_DUMMY_DECL_YY_LINENO%/static int yylineno = 1;/' \ 296# < $< > $@ 297# endif 298# endif 299# 300 301$(STD_DRV).flex: megaco_flex_scanner_drv.flex.src 302ifeq ($(ENABLE_MEGACO_FLEX_SCANNER_LINENO),true) 303 $(V_colon)@printf "std [flex] scanner - lineno enabled\n" 304 $(gen_verbose)$(PERL) -p -e \ 305 's/%FLEX_VERSION%/$(FLEX_VSN)/ ; \ 306 s/%MEGACO_YY_LINENO_OPTION%/%option yylineno/ ; \ 307 s/%MEGACO_YY_REENTRANT_OPTION%/\/\* %option reentrant \*\// ; \ 308 s/%MEGACO_DUMMY_DECL_YY_LINENO%/\/* static int yylineno = 1; *\//' \ 309 < $< > $@ 310else 311 $(V_colon)@printf "std [flex] scanner - lineno disabled\n" 312 $(gen_verbose)$(PERL) -p -e \ 313 's/%FLEX_VERSION%/$(FLEX_VSN)/ ; \ 314 s/%MEGACO_YY_LINENO_OPTION%/\/\* %option yylineno \*\// ; \ 315 s/%MEGACO_YY_REENTRANT_OPTION%/\/\* %option reentrant \*\// ; \ 316 s/%MEGACO_DUMMY_DECL_YY_LINENO%/static int yylineno = 1;/' \ 317 < $< > $@ 318endif 319 320$(MT_DRV).flex: megaco_flex_scanner_drv.flex.src 321ifeq ($(ENABLE_MEGACO_FLEX_SCANNER_LINENO),true) 322ifeq ($(ENABLE_REENTRANT_MEGACO_FLEX_SCANNER),true) 323 $(V_colon)@printf "multi-threaded reentrant [flex] scanner - lineno enabled\n" 324 $(gen_verbose)$(PERL) -p -e \ 325 's/%FLEX_VERSION%/$(FLEX_VSN)/ ; \ 326 s/%MEGACO_YY_LINENO_OPTION%/%option yylineno/ ; \ 327 s/%MEGACO_YY_REENTRANT_OPTION%/%option reentrant/ ; \ 328 s/%MEGACO_DUMMY_DECL_YY_LINENO%/\/* static int yylineno = 1; *\//' \ 329 < $< > $@ 330else 331 $(V_colon)@printf "multi-threaded non-reentrant [flex] scanner - lineno enabled\n" 332 $(gen_verbose)$(PERL) -p -e \ 333 's/%FLEX_VERSION%/$(FLEX_VSN)/ ; \ 334 s/%MEGACO_YY_LINENO_OPTION%/%option yylineno/ ; \ 335 s/%MEGACO_YY_REENTRANT_OPTION%/\/\* %option reentrant \*\// ; \ 336 s/%MEGACO_DUMMY_DECL_YY_LINENO%/\/* static int yylineno = 1; *\//' \ 337 < $< > $@ 338endif 339else 340ifeq ($(ENABLE_REENTRANT_MEGACO_FLEX_SCANNER),true) 341 $(V_colon)@printf "multi-threaded reentrant [flex] scanner - lineno disabled\n" 342 $(gen_verbose)$(PERL) -p -e \ 343 's/%FLEX_VERSION%/$(FLEX_VSN)/ ; \ 344 s/%MEGACO_YY_LINENO_OPTION%/\/\* %option yylineno \*\// ; \ 345 s/%MEGACO_YY_REENTRANT_OPTION%/%option reentrant/ ; \ 346 s/%MEGACO_DUMMY_DECL_YY_LINENO%/\/* static int yylineno = 1; - REENTRANT SCANNER*\//' \ 347 < $< > $@ 348else 349 $(V_colon)@printf "multi-threaded non-reentrant [flex] scanner - lineno disabled\n" 350 $(gen_verbose)$(PERL) -p -e \ 351 's/%FLEX_VERSION%/$(FLEX_VSN)/ ; \ 352 s/%MEGACO_YY_LINENO_OPTION%/\/\* %option yylineno \*\// ; \ 353 s/%MEGACO_YY_REENTRANT_OPTION%/\/\* %option reentrant \*\// ; \ 354 s/%MEGACO_DUMMY_DECL_YY_LINENO%/static int yylineno = 1;/' \ 355 < $< > $@ 356endif 357endif 358 359# megaco_flex_scanner_drv.c: megaco_flex_scanner_drv.flex 360# $(V_LEX) $(LEX_FLAGS) -P$* -o$@ $< 361$(STD_DRV).c: $(STD_DRV).flex 362 $(V_LEX) $(STD_LEX_FLAGS) -P$* -o$@ $< 363$(MT_DRV).c: $(MT_DRV).flex 364 $(V_LEX) $(MT_LEX_FLAGS) -P$* -o$@ $< 365 366_create_dirs := $(shell mkdir -p $(OBJDIR) $(LIBDIR)) 367 368solibs: $(SOLIBS) 369 370$(OBJDIR)/$(STD_DRV).o: $(STD_DRV).c 371 $(V_colon)@echo "compiling std driver:" 372 $(V_CC) -c $(STD_DRV_NAME) $(CFLAGS) -o $@ $< 373 374$(OBJDIR)/$(MT_DRV).o: $(MT_DRV).c 375 $(V_colon)@echo "compiling multi-threaded driver:" 376 $(V_CC) -c $(MT_DRV_NAME) $(CFLAGS_MT) -o $@ $< 377 378 379# No need to link with -lfl as we have also defined %option noyywrap - 380# and having -lfl doesn't work under Darwin for some reason. - Sean 381$(LIBDIR)/$(STD_DRV).@DED_EXT@: $(OBJDIR)/$(STD_DRV).o 382 $(V_colon)@echo "linking std driver:" 383 $(V_LD) $(LDFLAGS) -o $@ $< 384 385$(LIBDIR)/$(MT_DRV).@DED_EXT@: $(OBJDIR)/$(MT_DRV).o 386 $(V_colon)@echo "linking multi-threaded driver:" 387 $(V_LD) $(LDFLAGS) -o $@ $< 388