diff --git a/Makefile b/Makefile index 44e6da6..5c663db 100644 --- a/Makefile +++ b/Makefile @@ -1,28 +1,32 @@ -SUBDIRS = c_src src plugins - -all: - @set -e ; \ - for d in $(SUBDIRS) ; do \ - if [ -f $$d/Makefile ]; then \ - ( cd $$d && $(MAKE) ) || exit 1 ; \ - fi ; \ - done - -clean: $(LOCALCLEAN) - @set -e ; \ - for d in $(SUBDIRS) ; do \ - if [ -f $$d/Makefile ]; then \ - ( cd $$d && $(MAKE) $@ ) || exit 1 ; \ - fi ; \ - done +DESCRIPTION = Erlang YANG compiler + +SUBDIRS = plugins + +ERL_MODULES = yang_llerror xpath_parse + +include erl.mk + +erl.mk: + curl -s -O https://raw.githubusercontent.com/mbj4668/erl.mk/main/$@ + +ERLC_OPTS := $(filter-out +warn_export_vars,$(ERLC_OPTS)) include vsn.mk -dialyzer: - dialyzer -DVSN=\"$(VSN)\" -pa ../yanger/ebin --src src/*.erl - -# requires 'lux' in the PATH (https://github.com/hawk/lux) -# the tree test requires 'pyang' (https://github.com/mbj4668/pyang) -# checked out next to 'yanger' and in the PATH -test: - (cd test; $(MAKE)) -.PHONY: test +ERLC_OPTS += -DVSN=\"$(VSN)\" +DIALYZER_OPTS = -DVSN=\"$(VSN)\" + +src/yang_llerror.erl: c_src/yang_error.h + awk -f src/mk_llerror.awk < $< > $@ + +src/yang_llerror.hrl: c_src/yang_error.h + awk -f src/mk_llerror_hrl.awk < $< > $@ + +ebin/yang.beam: src/yang_llerror.hrl + +src/%.erl: src/%.yrl + erlc -o src $< + +clean: clean-gen + +clean-gen: + rm -rf src/yang_llerror.erl src/yang_llerror.hrl src/xpath_parse.erl diff --git a/c_src/Makefile b/c_src/Makefile index 87a524d..79b9aa2 100644 --- a/c_src/Makefile +++ b/c_src/Makefile @@ -1,10 +1,16 @@ - PARSER_NIF = ../priv/yang_parser_nif.so REGEX_NIF = ../priv/w3cregex_nif.so PRIV_FILES = $(PARSER_NIF) $(REGEX_NIF) -CFLAGS = -std=c99 +all: $(PRIV_FILES) + +include c_src.mk + +c_src.mk: + $(MAKE) -f ../erl.mk $@ + +CFLAGS += -std=c99 CWARNINGS = \ -Werror \ -Wall \ @@ -15,8 +21,6 @@ CWARNINGS = \ -Wwrite-strings \ -Wnested-externs -CFLAGS += -fpic -DDYNAMIC_DRIVER - ifneq ($(DEBUG),) CFLAGS += -g -ggdb CWARNINGS += -Wuninitialized @@ -27,12 +31,6 @@ endif CFLAGS += $(CWARNINGS) -ERL_EVAL = 'io:format("~s", [os:getenv("ROOTDIR")]), erlang:halt(0)' -ERL_ROOTDIR = $(shell erl -noinput -eval $(ERL_EVAL)) -ifneq ($(findstring /, $(ERL_ROOTDIR)),) - CFLAGS += -I$(ERL_ROOTDIR)/usr/include -endif - XML_CFLAGS ?= $(shell pkg-config --cflags libxml-2.0) ifeq ($(XML_CFLAGS),) XML_CFLAGS = -I/usr/include/libxml2 @@ -46,26 +44,15 @@ LIBS += $(XML_LIBS) LD = $(CC) -ifeq ($(shell uname -s), Darwin) - LDDRV_FLAGS = -bundle -undefined dynamic_lookup -else - LDDRV_FLAGS = -shared -endif - - -C_SOURCES := $(wildcard yang*.c) -C_HEADERS := $(wildcard yang*.h) -OBJS := $(C_SOURCES:%.c=./%.o) - -all: $(PRIV_FILES) - -$(OBJS): $(C_HEADERS) +PARSER_SOURCES := $(wildcard yang*.c) +PARSER_HEADERS := $(wildcard yang*.h) +PARSER_OBJS := $(PARSER_SOURCES:%.c=./%.o) -$(PARSER_NIF): $(OBJS) - $(LD) $(LDDRV_FLAGS) -o $@ $^ $(LIBS) +$(PARSER_NIF): $(PARSER_OBJS) + $(LD) $(LDFLAGS_NIF) -o $@ $^ $(LIBS) $(REGEX_NIF): w3cregex_nif.o - $(LD) $(LDDRV_FLAGS) -o $@ $^ $(LIBS) + $(LD) $(LDFLAGS_NIF) -o $@ $^ $(LIBS) debug: $(MAKE) DEBUG=true all diff --git a/ebin/.gitkeep b/ebin/.gitkeep deleted file mode 100644 index 8b13789..0000000 --- a/ebin/.gitkeep +++ /dev/null @@ -1 +0,0 @@ - diff --git a/plugins/Makefile b/plugins/Makefile index aec7b6b..2665559 100644 --- a/plugins/Makefile +++ b/plugins/Makefile @@ -1,6 +1,6 @@ include ../vsn.mk -ERL_SOURCES := $(wildcard *.erl) +ERL_SOURCES := $(wildcard *.erl) ERL_OBJECTS := $(ERL_SOURCES:%.erl=../priv/%.beam) ERLC_FLAGS += -pa ../../yanger/ebin -Werror diff --git a/src/Makefile b/src/Makefile deleted file mode 100644 index b799648..0000000 --- a/src/Makefile +++ /dev/null @@ -1,61 +0,0 @@ -include ../vsn.mk - -ERL_SOURCES := $(wildcard *.erl) -YECC_SOURCES := $(wildcard *.yrl) -ERL_OBJECTS := $(ERL_SOURCES:%.erl=../ebin/%.beam) \ - $(YECC_SOURCES:%.yrl=../ebin/%.beam) - -ERL_OBJECTS += ../ebin/yang_llerror.beam - -APP_SOURCES := $(wildcard *.app.src) -APP_OBJECTS := $(APP_SOURCES:%.app.src=../ebin/%.app) - -null := -space := $(null) # -comma := , -MODULES := $(subst $(space),$(comma),$(strip $(ERL_SOURCES:%.erl=%))) - -ERLC ?= erlc - -ERLC_FLAGS += -DVSN=\"$(VSN)\" -pa ../../yanger/ebin -Werror +debug_info - -compile: all - -all: $(ERL_OBJECTS) $(APP_OBJECTS) - -yang_llerror.erl: ../c_src/yang_error.h - awk -f mk_llerror.awk < $< > $@ - -yang_llerror.hrl: ../c_src/yang_error.h - awk -f mk_llerror_hrl.awk < $< > $@ - -../ebin/yang.beam: yang_llerror.hrl - -../ebin/%.app: %.app.src ../vsn.mk Makefile - sed -e "s/%VSN%/$(VSN)/; s/%MODULES%/$(MODULES)/" < $< > $@ - -../ebin/%.beam: %.erl - $(ERLC) $(ERLC_FLAGS) -o ../ebin $< - -%.erl: %.yrl - $(ERLC) $< - -clean: - rm -f ../ebin/*.* .*.erl.d - rm -f yang_llerror.erl yang_parse.erl - -ERL_DEPS = $(ERL_SOURCES:%.erl=.%.erl.d) - -.%.erl.d: %.erl - $(ERLC) -M -MG -I ../.. -o ../ebin -pa ../ebin $< > $@ - -.PHONY: depend - -# forcefully re-generate dependency files -depend: - rm -f .*.erl.d - $(MAKE) $(ERL_DEPS) - -ifneq ($(MAKECMDGOALS),clean) --include $(ERL_DEPS) -endif diff --git a/src/yanger.app.src b/src/yanger.app.src deleted file mode 100644 index 981b86b..0000000 --- a/src/yanger.app.src +++ /dev/null @@ -1,12 +0,0 @@ -{application, yanger, - [ - {description, ""}, - {vsn, "%VSN%"}, - {modules, [%MODULES%]}, - {registered, []}, - {applications, [ - kernel, - stdlib - ]}, - {env, []} - ]}. diff --git a/test/Makefile b/test/Makefile index e73e128..abf3a03 100644 --- a/test/Makefile +++ b/test/Makefile @@ -1,4 +1,4 @@ -DIRS = lux eunit +DIRS = eunit all: test diff --git a/test/lux/ENG-24068-submodule-post-expand-leafref/Makefile b/test/lux/ENG-24068-submodule-post-expand-leafref/Makefile index 5553a39..7e42d1c 100644 --- a/test/lux/ENG-24068-submodule-post-expand-leafref/Makefile +++ b/test/lux/ENG-24068-submodule-post-expand-leafref/Makefile @@ -2,5 +2,5 @@ include ../../support/*_testcases.mk build: -clean: iclean +clean: rm -rf lux_logs diff --git a/test/lux/eng-25448_deviated_type_scope/Makefile b/test/lux/eng-25448_deviated_type_scope/Makefile index e120470..6f3b4b2 100644 --- a/test/lux/eng-25448_deviated_type_scope/Makefile +++ b/test/lux/eng-25448_deviated_type_scope/Makefile @@ -1,6 +1,6 @@ +include ../../support/*_testcases.mk build: - lux run.lux clean: rm -f *.fxs diff --git a/test/lux/invalidate_default/Makefile b/test/lux/invalidate_default/Makefile index 3230cfc..ad9dec6 100644 --- a/test/lux/invalidate_default/Makefile +++ b/test/lux/invalidate_default/Makefile @@ -2,8 +2,7 @@ # Mandatory targets build: - @echo "Build complete" clean: - rm -r lux_logs + rm -rf lux_logs