SHELL := /bin/bash BUILDTAG := "$(shell [ -f ./git_build_tags.sh ] && { ./git_build_tags.sh | tee buildtag.txt | sed -n '1,1p'; } )" BTLINES := "$(shell [ -f buildtag.txt ] && { cat buildtag.txt | wc -l | sed "s/ .*//" ; } )" MYID := "$(shell id -u)" -include .brand_selection BRAND_SHORT ?= dwarfg BRAND_LONG ?= Dwarfguard BRAND_OPT ?= 1 DAEMON := "$(BRAND_SHORT)d" INST_PATH := "$(BRAND_SHORT)_install" PACKAGE_NAME := "$(BRAND_SHORT)_install" RELEASE_NAME := "$(BRAND_SHORT)_release" export BRAND_SHORT export BRAND_LONG export BRAND_OPT ifneq ($(shell test $(BTLINES) -gt 2; echo $$?),0) $(error Broken buildtag.txt file) else $(info Lines in buildtag.txt: $(BTLINES)) endif ifeq ($(shell test $(MYID) -eq 0; echo $$?),0) $(error Fook root. Stop messing up builddir) endif -include .debug_defs CFLAGS += ${ECFLAGS} -g -std=c++11 -pthread -Wall -Wno-format-truncation -DBUILDTAG=\"$(BUILDTAG)\" -DBRAND=$(BRAND_OPT) # export BETABUILD flag if set in environment ifdef BETABUILD CFLAGS += -DBETABUILD endif LDFLAGS += -lbsd -lpthread -lcurl -lssl -lcrypto -larchive -ljson-c CC=g++ CP=cp LN=ln DEBUG_DEFS=.debug_defs DBCFLAGS=`mysql_config --cflags` DBLFLAGS=`mysql_config --libs` BUILDVER := $(shell grep VERSION base_defs | sed 's/[^"]*"\([^"]*\).*/\1/') BDIR=build HDR=$(wildcard *.h) ALLSRC=$(wildcard *.cpp) SRCEXCEPT=dwarfg.cpp mysql_gen.cpp licman.cpp dwt_mdm.cpp #SRC1=$(subst dwarfg.cpp,,${ALLSRC}) SRC=$(filter-out $(SRCEXCEPT),$(ALLSRC)) DWARFG_SRC=dwarfg.cpp OBJ=$(SRC:%.cpp=%.o) export RCFLAGS ECFLAGS BDIR .PHONY : clean list all log alllog c_hotstuff c_fixme c_todo agents buildtag dwarflenc list: @echo @echo "Building $(BRAND_LONG) ... there are multiple targets serving different purposes." @echo @echo "Build targets:" @echo " - all ... builds all binary targets" @echo " - $(DAEMON) ... builds $(BRAND_LONG) daemon (main target)" @echo " - package ... creates packages containing all install stuff (.tgz ATM)" @echo " - devpackage ... creates devel package (like normal package but includes DEV CA)" @echo " - dwarfgperf ... create archive containing emulator and all stuff needed for perf tests." @echo " - agents ... builds/prepares $(BRAND_LONG) client agents" @echo "Config targets: (use like: make ; make )" @echo " - cleandebug ... cleans any debug settings" @echo " - debug ... sets debug level to DEBUG" @echo " - debugwait ... sets debug level to DEBUG and SIGSTOP itself after setting UID/GID to be attached by gdb" @echo " - superdebug ... maximal debug level" @echo " - superdebugwait ... maximal debug level and SIGSTOP itself after setting UID/GID to be attached by gdb" @echo "DEV-text targets:" @echo " - pycheck ... runs pycheck script" @echo " - c_hotstuff ... greps dev tree for lines containing \" @echo " - c_fixme ... greps dev tree for lines containing FIXME" @echo " - c_todo ... greps dev tree for lines containing TODO" @echo " - ctags ... builds CTAGS DB (e.g. for use with vim)" @echo "DEV-info targets: (after || during running Dwarfguard)" @echo " - log ... filter DEBUG messages out of log file and send rest to stdout (less)" @echo " - logimp ... show only WARN, ERR and CRIT messages and Dwarfguard startup from log file (less)" @echo " - logcont ... continuous filtering of DEBUG msgs. WARN: there is a delay" @echo " - alllog ... show all log messages to stdout (less) - no filtering" @echo " - alllogcont ... continuous display of log messages. WARN: there is a delay" @echo "DEV-execution targets: (once built && installed; run as root to get correct user by setuid())" @echo " - valgrind ... runs $(DAEMON) in valgrind. NOTE: ramdisk must be up!" @echo " - valgrind_leak ... runs $(DAEMON) in valgrind looking for leaks. NOTE: ramdisk must be up!" @echo " - devrunhere ... preps links for running $(DAEMON) directly from srctree. NOTE: $(DAEMON) must be installed, stop system service first and prep ramdisk before starting (as a root!) e.g. gdb ./$(DAEMON)" @echo all: licman $(DAEMON) libdwarflenc.so agents unittest pycheck: @./pycheck.sh dwarflenc: dwarflenc.c dwarflenc.h gcc -g -Wall -c -o $@.o $@.c dwarflenc_win: dwarflenc.c dwarflenc.h x86_64-w64-mingw32-gcc -g -Wall -c -o $@.o $@.c libdwarflenc.so: dwarflenc gcc -g -Wall -shared -o $@ -fPIC $<.c libdwarflenc.dll: dwarflenc_win x86_64-w64-mingw32-gcc --shared -o dwarflenc.dll $<.o -lpthread $(BRAND_SHORT): $(DAEMON) @echo "$(BRAND_SHORT) is provided by $(DAEMON) (that has been built)" debug: clean $(CP) -f .debug_regular $(DEBUG_DEFS) debugwait: clean $(CP) -f .debug_wait $(DEBUG_DEFS) superdebug: clean $(CP) -f .debug_max $(DEBUG_DEFS) superdebugwait: clean $(CP) -f .debug_maxwait $(DEBUG_DEFS) cleandebug: clean $(RM) $(DEBUG_DEFS) showsize: wc *cpp *h appdir/*h agents/*/*h Makefile *py test/*[ph] test/*py playground/*[ph] | sort -rn | nl -v 0 -s . | tac showsize_top12: wc *cpp *h appdir/*h Makefile *py test/*py | sort -rn | nl -v 0 -s . | tac | tail -13 %.o: %.cpp $(HDR) $(CC) $(LCFLAGS) $(RCFLAGS) $(CFLAGS) $(DBCFLAGS) -c $< -o $@ $(DAEMON): $(DWARFG_SRC) $(OBJ) dwarflenc buildtag $(eval LOC_CFLAGS += -DTEST) $(eval RCFLAGS += -DTEST) $(eval BDIR := testbuild) $(CC) $(CFLAGS) $(LOC_CFLAGS) $(DBCFLAGS) -o $@ $(DWARFG_SRC) $(OBJ) dwarflenc.o $(LDFLAGS) $(DBLFLAGS) dwt_mdm: dwt_mdm.cpp $(OBJ) $(CC) $(CFLAGS) $(LOC_CFLAGS) $(DBCFLAGS) -o dwt_mdm dwt_mdm.cpp $(OBJ) $(LDFLAGS) $(DBLFLAGS) licgenclean: $(RM) licgen.o licgen 2>/dev/null licgen: licgenclean dwarflib.o globals.o $(CC) $(CFLAGS) $(DBCFLAGS) -DLICGEN -o $@ licgen.cpp dwarflib.o globals.o $(LDFLAGS) $(DBLFLAGS) licmanclean: $(RM) licman.o licman 2>/dev/null licman: licmanclean dwarflib.o globals.o licgen.o $(CC) $(CFLAGS) $(DBCFLAGS) -o $@ licman.cpp dwarflib.o licgen.o globals.o $(LDFLAGS) $(DBLFLAGS) clean: licgenclean $(RM) -r export/ $(BRAND_SHORT)_install.tgz 2>/dev/null $(RM) -f $(DAEMON) *.o *.so 2>/dev/null $(MAKE) -C agents clean $(MAKE) -C unittests clean unittest: $(MAKE) -C unittests tags: ctags ctags: ctags -R --exclude=.git --exclude=.devdeploy --exclude=export log: for i in /srv/$(BRAND_SHORT)* ; do echo -e "\n\t=== $$i ==="; cat $$i/logs/log_$(BRAND_SHORT).txt | grep -v "^[^/]*/DBG" | tr -s '\n'; done logimp: for i in /srv/$(BRAND_SHORT)* ; do echo -e "\n\t=== $$i ==="; cat $$i/logs/log_$(BRAND_SHORT).txt | grep -E "^[^/]*/WARN|^[^/]*/ERR|^[^/]*/CRIT|INIT" | tr -s '\n'; done rlogtime: for i in /srv/$(BRAND_SHORT)* ; do echo -e "\n\t=== $$i ==="; cat $$i/logs/log_$(BRAND_SHORT).txt | grep "Opened at \|/ERR\|Rvector" | tr -s ' ' | sort -n -k 6 -r; done alogtime: for i in /srv/$(BRAND_SHORT)* ; do echo -e "\n\t=== $$i ==="; cat $$i/logs/log_$(BRAND_SHORT).txt | grep "Opened at \|/ERR\|vector" | grep -v "TDBvector: 0,0,0,0,0,0,0" | sort -n -k 6 -r; done alllog: for i in /srv/$(BRAND_SHORT)* ; do echo -e "\n\t=== $$i ==="; cat $$i/logs/log_$(BRAND_SHORT).txt | tr -s '\n'; done logcont: tail -F /srv/$(BRAND_SHORT)/logs/log_$(BRAND_SHORT).txt | grep -v "^[^/]*/DBG" alllogcont: tail -F /srv/$(BRAND_SHORT)/logs/log_$(BRAND_SHORT).txt c_hotstuff: grep -rnI --color --exclude-dir=.git --exclude-dir=playground --exclude-dir=export --exclude-dir=.devdeploy --exclude=Makefile --exclude=tags --exclude=README "\" . || echo "No match found." c_fixme: grep -rnI --color --exclude-dir=.git --exclude-dir=export --exclude-dir=.devdeploy --exclude=Makefile --exclude=tags --exclude=README FIXME . || echo "No match found." c_todo: grep -rnI --color --exclude-dir=.git --exclude-dir=export --exclude-dir=.devdeploy --exclude=Makefile --exclude=tags --exclude=README TODO . || echo "No match found." agents: $(MAKE) -C $@ prepexportdir: $(RM) -fr export mkdir -p export/$(INST_PATH)/ $(CP) -dpR appdir export/$(INST_PATH)/ $(CP) $(BRAND_SHORT)_license.lic export/$(INST_PATH)/appdir/ ./prep_upgscripts.sh export/$(INST_PATH)/appdir $(RM) -fr export/$(INST_PATH)/appdir/__pycache__ $(CP) $(DAEMON) licman export/$(INST_PATH)/appdir/ $(CP) install.sh upgrade.sh export/$(INST_PATH)/ $(CP) -L doc/eula_content.html export/$(INST_PATH)/appdir/eula_content.html $(CP) buildtag.txt export/$(INST_PATH)/appdir/ mkdir export/$(INST_PATH)/appdir/agents $(CP) -r agents/out/* export/$(INST_PATH)/appdir/agents/ mkdir export/$(INST_PATH)/appdir/agents/aad $(LN) -s ../../push_agent.py export/$(INST_PATH)/appdir/agents/aad/push_agent.py rsync -rlD --exclude '.git/' --exclude '.gitignore' ../mamasweb/ export/$(INST_PATH)/appdir/web/gui/ rsync -rlD --exclude '.git/' --exclude '.gitignore' ../mamasbig/web/vendor export/$(INST_PATH)/appdir/web/gui/ rsync -rlD --exclude '.git/' --exclude '.gitignore' ../mamasnotify/ export/$(INST_PATH)/appdir/notifier/ rsync -rlD --exclude '.git/' --exclude '.gitignore' ../mamasbig/notifier/vendor export/$(INST_PATH)/appdir/notifier/ rsync -rlD --exclude '.git/' --exclude '.gitignore' ../mamasbig/sshwifty/ export/$(INST_PATH)/appdir/sshwifty_distrib $(LN) -s sshwifty_distrib/sshwifty export/$(INST_PATH)/appdir/sshwifty $(CP) dwarflenc.h libdwarflenc.so export/$(INST_PATH)/appdir/web/gui/libs/ $(RM) export/$(INST_PATH)/appdir/web/gui/.gitignore prepdevexportdir: # $(CP) dwarfg_dev_CA.key export/$(INST_PATH)/appdir/ # $(CP) dwarfg_dev_CA.pem export/$(INST_PATH)/appdir/ $(RM) export/$(INST_PATH)/appdir/dwarflib_cfg.txt $(LN) -s dwarflib_cfg_dbg.txt export/$(INST_PATH)/appdir/dwarflib_cfg.txt $(CP) test/test_ffi_web.php export/$(INST_PATH)/appdir/web/gui/public/ sed -i 's/^SCDKEY=""/SCDKEY="f00112f0012182f001eef001188f0018"/' export/$(INST_PATH)/appdir/base_defs finishpackage: ./expand_brand.sh ./prep_cmdline.sh export/$(INST_PATH)/appdir/cmdline $(RM) -r export/$(INST_PATH)/appdir/web/gui/assets tar -czf $(PACKAGE_NAME)_$(BUILDVER).tgz -C export $(INST_PATH) @echo "ARTIFACT=$(PACKAGE_NAME)_$(BUILDVER).tgz" clearexport: $(RM) -fr export packagebuild: all prepexportdir finishpackage repackage: prepexportdir finishpackage package: cleandebug packagebuild clearexport release: package cp $(PACKAGE_NAME)_$(BUILDVER).tgz $(RELEASE_NAME)_$(BUILDVER).tgz devpackage: CFLAGS += -DBETABUILD devpackage: all libdwarflenc.so prepexportdir prepdevexportdir finishpackage devrepackage: prepexportdir prepdevexportdir finishpackage dwarfgperf: perftest.lic test/emulator.py test/mamas_lib.py test/matelib.py test/example_data test/benchtest_local.sh test/stabtest.sh test/perftest.sh .brand_selection $(RM) -fr export/ mkdir -p export/$@ $(CP) -LR $^ export/$@/ tar czf $@.tgz -C export $@ $(RM) -fr export valgrind: $(DAEMON) valgrind --log-file=valgrind_report.txt ./$(DAEMON) valgrind_leak: $(DAEMON) valgrind --leak-check=full --log-file=valgrind_report_leak.txt --num-callers=50 ./$(DAEMON) devrunhere: $(DAEMON) ln -s appdir/$(BRAND_SHORT)_license.lic ln -s appdir/download_fw_advantech.sh ln -s appdir/exchange_server_ip.sh