-# makefile is generated from makefile.1.mak.
-# 2.07.2017
+# "makefile" is automatically generated from "makefile.1.mak"
+#
+# Copyright (C) 2016, 2017, 2023 Balthasar Szczepański
#
-# This is the makefile
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as
+# published by the Free Software Foundation, either version 3 of the
+# License, or (at your option) any later version.
#
-# Copyright (C) 2016 - 2017 Balthasar Szczepañski
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Affero General Public License for more details.
#
-# This program is free software: you can redistribute it and/or modify
-# it under the terms of the GNU Affero General Public License as
-# published by the Free Software Foundation, either version 3 of the
-# License, or (at your option) any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU Affero General Public License for more details.
-#
-# You should have received a copy of the GNU Affero General Public License
-# along with this program. If not, see <http://www.gnu.org/licenses/>.
-
-###CC;
-###CF;
-###PL;
-###CP;
-###MV;
-###RM;
-###CM;
-###OD;
-###LD;
-###WD;
-
-all: moveout copyoutwww moveoutlib remove config.txt
-
-moveout: reset.pl viewer viewer.pl frame frame.pl 2words 2words.pl chat chat.pl ong.pl updlist.pl oldlogs.pl attach attach.pl info info.pl goto goto.pl bbcode bbcode.pl setuid exec
- $(MV) reset.pl viewer viewer.pl frame frame.pl 2words 2words.pl chat chat.pl ong.pl updlist.pl oldlogs.pl attach attach.pl info info.pl goto goto.pl bbcode bbcode.pl $(OD)
-
-copyout: setuid exec
-# $(CP) access.pl $(OD)
-
-copyoutwww: timer.js bsta.css setuid exec
- $(CP) timer.js bsta.css $(WD)
-
-
-moveoutlib: bsta_lib.pm setuid exec
- $(MV) bsta_lib.pm $(LD)
-
-setuid: viewer frame 2words attach chat info goto bbcode
- $(CM) u+s viewer frame 2words attach chat info goto bbcode
-
-exec: reset.pl viewer.pl frame.pl 2words.pl ong.pl updlist.pl oldlogs.pl attach.pl chat.pl info.pl goto.pl bbcode.pl
- $(CM) +x reset.pl viewer.pl frame.pl 2words.pl ong.pl updlist.pl oldlogs.pl attach.pl chat.pl info.pl goto.pl bbcode.pl
-
-remove: viewer.c frame.c 2words.c chat.c attach.c info.c goto.c bbcode.c copyout moveout setuid exec
- $(RM) viewer.c frame.c 2words.c chat.c attach.c info.c goto.c bbcode.c
-
-
-bsta_lib.pm: bsta_lib.1.pm configure.pl settings
- $(PL) configure.pl settings <bsta_lib.1.pm >bsta_lib.pm
-
-
-viewer: viewer.c
- $(CC) $(CF) -o viewer viewer.c
-
-viewer.c: viewer.1.c configure.pl settings
- $(PL) configure.pl settings <viewer.1.c >viewer.c
-
-viewer.pl: viewer.1.pl configure.pl settings
- $(PL) configure.pl settings <viewer.1.pl >viewer.pl
-
-
-frame: frame.c
- $(CC) $(CF) -o frame frame.c
-
-frame.c: frame.1.c configure.pl settings
- $(PL) configure.pl settings <frame.1.c >frame.c
-
-frame.pl: frame.1.pl configure.pl settings
- $(PL) configure.pl settings <frame.1.pl >frame.pl
-
-
-2words: 2words.c
- $(CC) $(CF) -o 2words 2words.c
-
-2words.c: 2words.1.c configure.pl settings
- $(PL) configure.pl settings <2words.1.c >2words.c
-
-2words.pl: 2words.1.pl configure.pl settings
- $(PL) configure.pl settings <2words.1.pl >2words.pl
-
-
-attach: attach.c
- $(CC) $(CF) -o attach attach.c
-
-attach.c: attach.1.c configure.pl settings
- $(PL) configure.pl settings <attach.1.c >attach.c
-
-attach.pl: attach.1.pl configure.pl settings
- $(PL) configure.pl settings <attach.1.pl >attach.pl
-
-
-chat: chat.c
- $(CC) $(CF) -o chat chat.c
-
-chat.c: chat.1.c configure.pl settings
- $(PL) configure.pl settings <chat.1.c >chat.c
-
-chat.pl: chat.1.pl configure.pl settings
- $(PL) configure.pl settings <chat.1.pl >chat.pl
-
-
-info: info.c
- $(CC) $(CF) -o info info.c
-
-info.c: info.1.c configure.pl settings
- $(PL) configure.pl settings <info.1.c >info.c
-
-info.pl: info.1.pl configure.pl settings
- $(PL) configure.pl settings <info.1.pl >info.pl
-
-
-goto: goto.c
- $(CC) $(CF) -o goto goto.c
-
-goto.c: goto.1.c configure.pl settings
- $(PL) configure.pl settings <goto.1.c >goto.c
-
-goto.pl: goto.1.pl configure.pl settings
- $(PL) configure.pl settings <goto.1.pl >goto.pl
-
-
-bbcode: bbcode.c
- $(CC) $(CF) -o bbcode bbcode.c
-
-bbcode.c: bbcode.1.c configure.pl settings
- $(PL) configure.pl settings <bbcode.1.c >bbcode.c
-
-bbcode.pl: bbcode.1.pl configure.pl settings
- $(PL) configure.pl settings <bbcode.1.pl >bbcode.pl
-
-
-ong.pl: ong.1.pl configure.pl settings
- $(PL) configure.pl settings <ong.1.pl >ong.pl
-
-updlist.pl: updlist.1.pl configure.pl settings
- $(PL) configure.pl settings <updlist.1.pl >updlist.pl
-
-oldlogs.pl: oldlogs.1.pl configure.pl settings
- $(PL) configure.pl settings <oldlogs.1.pl >oldlogs.pl
-
-reset.pl: reset.1.pl configure.pl settings
- $(PL) configure.pl settings <reset.1.pl >reset.pl
-
-
-
-config.txt: config.1.txt configure.pl settings
- $(PL) configure.pl settings <config.1.txt >config.txt
+# You should have received a copy of the GNU Affero General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+DEFAULT_TARGET = debug
+ifndef TARGET
+TARGET = $(DEFAULT_TARGET) ###MAKE_TARGET:
+# when want to change target run this first:
+# make -B TARGET=target_name makefile
+endif
+PERL = perl
+
+###MAKE_CC: CC=gcc
+###MAKE_CF: CF=-g -Wall
+
+###MAKE_CHMOD: CHMOD = chmod
+###MAKE_CP: CP = cp
+###MAKE_MKDIR: MKDIR = mkdir
+###MAKE_PERL: PERL = perl
+###MAKE_RM: RM = rm
+###MAKE_SUDO: SUDO = sudo
+
+###MAKE_BIN_PATH: BIN_PATH = /botm/bin/bsta
+###MAKE_DATA_PATH: DATA_PATH = /botm/data/bsta
+###MAKE_LIB_PATH: LIB_PATH = /botm/lib/bsta
+###MAKE_LOG_PATH: LOG_PATH = /botm/log/bsta
+###MAKE_TMP_PATH: TMP_PATH = /botm/tmp/bsta
+###MAKE_WWW_PATH: WWW_PATH = /botm/www/1190/bsta
+
+###MAKE_CONF: CONF = /botm/etc/www/conf/1190/bsta.conf
+###MAKE_CRON: CRON = /etc/cron.d/bsta
+
+CONFIGFILE = settings-$(TARGET).txt settings.txt
+DEFAULT_CONFIGFILE = settings-$(DEFAULT_TARGET).txt settings.txt
+
+# The configuration tool
+CONFIGURE_CMD = $(PERL) ./configure.pl $(CONFIGFILE)
+
+# keep these 2 lists in the same order!:
+GENERATE_FROM=\
+2words.1.pl\
+attach.1.pl\
+bbcode.1.pl\
+bsta.1.conf\
+bsta.1.cron\
+bsta_lib.1.pm\
+chat.1.pl\
+frame.1.pl\
+goto.1.pl\
+info.1.pl\
+oldlogs.1.pl\
+ong.1.pl\
+reset.1.pl\
+updlist.1.pl\
+viewer.1.pl
+
+TO_GENERATE=\
+2words.pl\
+attach.pl\
+bbcode.pl\
+bsta.conf\
+bsta.cron\
+bsta_lib.pm\
+chat.pl\
+frame.pl\
+goto.pl\
+info.pl\
+oldlogs.pl\
+ong.pl\
+reset.pl\
+updlist.pl\
+viewer.pl
+
+DIR=\
+$(BIN_PATH)\
+$(DATA_PATH)\
+$(LIB_PATH)\
+$(LOG_PATH)\
+$(TMP_PATH)\
+$(WWW_PATH)
+
+HIDDEN_DIR=\
+$(DATA_PATH)\
+$(TMP_PATH)
+
+SETUID=\
+2words\
+bbcode\
+attach\
+chat\
+frame\
+goto\
+info\
+viewer
+
+EXEC=\
+2words.pl\
+attach.pl\
+bbcode.pl\
+chat.pl\
+frame.pl\
+goto.pl\
+info.pl\
+oldlogs.pl\
+ong.pl\
+reset.pl\
+updlist.pl\
+viewer.pl
+
+PERL_WRAP_EXEC=\
+2words\
+attach\
+bbcode\
+chat\
+frame\
+goto\
+info\
+viewer
+
+BIN=\
+$(EXEC)\
+$(PERL_WRAP_EXEC)
+
+LIB=\
+bsta_lib.pm
+
+WWW=\
+botmlogo.png\
+bsta.css\
+timer.js
+
+
+all: $(BIN) setuid exec
+
+makefile: makefile.1.mak $(CONFIGFILE) configure.pl
+ $(CONFIGURE_CMD) < makefile.1.mak > makefile
+
+configure.pl: $(CONFIGFILE) config/configure.1.pl
+ $(PERL) config/configure.1.pl target=direct settings-$(TARGET).txt config/settings.txt --in config/configure.1.pl --out configure.pl
+
+$(TO_GENERATE): $(GENERATE_FROM) $(CONFIGFILE) configure.pl
+ $(CONFIGURE_CMD) --in $(GENERATE_FROM) --out $(TO_GENERATE)
+
+$(PERL_WRAP_EXEC): %: exec/exec.c exec/settings.txt configure.pl
+ $(PERL) configure.pl path=$(BIN_PATH) target=$*.pl io_path=$(LOG_PATH) stderr=$*-stderr.log exec/settings.txt --in exec/exec.c --out $*.c
+ $(CC) $(CF) -o $@ $*.c
+
+exec: $(EXEC)
+ $(CHMOD) +x $(EXEC)
+
+wrap_exec:
+
+setuid: $(SETUID)
+ $(CHMOD) u+s,g+s $(SETUID)
+
+
+mktree:
+ $(MKDIR) -p $(DIR)
+ $(CHMOD) g-r,g-w,g-x,o-r,o-w,o-x $(HIDDEN_DIR)
+
+ifdef BIN_PATH
+cp_bin: $(BIN) setuid exec | mktree
+ $(RM) -f $(BIN_PATH)/*
+ $(CP) -p $(BIN) $(BIN_PATH)
+endif
+
+ifdef LIB_PATH
+cp_lib: $(LIB) | mktree
+ $(RM) -f $(LIB_PATH)/*
+ $(CP) -p $(LIB) $(LIB_PATH)
+endif
+
+cp_www:
+ $(CP) -p $(WWW) $(WWW_PATH)
+
+cp_conf: bsta.conf
+ $(CP) bsta.conf $(CONF)
+
+cp_cron: bsta.cron
+ $(SUDO) $(CP) bsta.cron $(CRON)
+
+install: all cp_bin cp_lib cp_www cp_conf cp_cron
+
+clean:
+ $(RM) -f configure.pl $(TO_GENERATE) $(PERL_WRAP_EXEC) $(PERL_WRAP_EXEC:=.c)
+ $(PERL) config/configure.1.pl $(DEFAULT_CONFIGFILE) < makefile.1.mak > makefile
+
+PHONY: all clean install setuid exec mktree cp_bin cp_lib cp_www cp_conf cp_cron