.ONESHELL:
.SHELLFLAGS := -ec
+PACKAGE := paraslash
+DEFINES = \
+ $(call DEFINE,PACKAGE,$(PACKAGE)) \
+ $(call DEFINE,SLOGAN,network audio streaming) \
+ $(call DEFINE,AUTHOR,Andre Noll) \
+ $(call DEFINE,EMAIL,maan@tuebingen.mpg.de) \
+ $(call DEFINE,COPYRIGHT_YEAR,1997) \
+ $(call DEFINE,PROJECT_WEBSITE,https://people.tuebingen.mpg.de/maan/$(PACKAGE)/) \
+ $(call DEFINE,CLONE_URL,https://git.tuebingen.mpg.de/$(PACKAGE)) \
+ $(call DEFINE,GITWEB_URL,https://git.tuebingen.mpg.de/$(PACKAGE).git) \
+ $(call DEFINE,HOME_URL,https://people.tuebingen.mpg.de/maan/) \
+ $(call DEFINE,LICENSE,GPL-2.0) \
+ $(call DEFINE,LICENSE_URL,https://www.gnu.org/licenses/)
+DEFINE = -D '$(1)=$(2)'
+M4 += $(DEFINES)
+DEFINE = $(1)='$(2)'
+SHELL_DEFINES := $(DEFINES)
+
LOGLEVELS := LL_DEBUG,LL_INFO,LL_NOTICE,LL_WARNING,LL_ERROR,LL_CRIT,LL_EMERG
SEVERITIES := \"debug\",\"info\",\"notice\",\"warning\",\"error\",\"crit\",\"emerg\"
vardir := /var/paraslash
mandir := $(datarootdir)/man/man1
MKDIR_P := mkdir -p
-build_date := $(shell date)
uname_s := $(shell uname -s 2>/dev/null || echo "UNKNOWN_OS")
-uname_rs := $(shell uname -rs)
-cc_version := $(shell $(CC) --version | head -n 1)
-GIT_VERSION := $(shell ./GIT-VERSION-GEN git-version.h)
-COPYRIGHT_YEAR := 2025
ifeq ("$(origin O)", "command line")
build_dir := $(O)
else
build_dir := build
endif
+version_dir := $(build_dir)/version-gen
object_dir := $(build_dir)/objects
dep_dir := $(build_dir)/deps
man_dir := $(build_dir)/man/man1
test_dir := t
yy_src_dir := yy
yy_build_dir := $(build_dir)/yy
+GIT_VERSION := $(shell $(SHELL_DEFINES) ./version-gen.sh $(PACKAGE) $(version_dir)/version.c)
executables := recv filter audioc write afh
ifneq ($(CRYPTOLIB),)
crypt_common base64 ipc dccp_send fd user_list \
chunk_queue afs aft mood mp score attribute blob \
playlist sched acl send_common udp_send color fec \
- wma_afh wma_common sideband lsu \
+ wma_afh wma_common sideband lsu version \
)
ifeq ($(CRYPTOLIB),openssl)
server_objs += openssl.o
server_objs += aac_afh.o mp4.o
endif
upgrade_db_objs := $(addsuffix .o, crypt_common exec fd string \
- upgrade_db base64)
+ upgrade_db base64 version)
endif
endif
ifneq ($(CRYPTOLIB),)
executables += client audiod
client_objs := $(addsuffix .o, \
client net string fd lsu sched stdin stdout time sideband client_common \
- buffer_tree crypt_common base64 $(CRYPTOLIB) \
+ buffer_tree crypt_common base64 $(CRYPTOLIB) version \
)
ifeq ($(HAVE_READLINE),yes)
client_objs += interactive.o
http_recv dccp_recv recv_common fd sched write_common file_write \
audiod_command fecdec_filter client_common udp_recv color fec \
prebuffer_filter bitstream imdct wma_common wmadec_filter \
- buffer_tree sync_filter lsu $(CRYPTOLIB) \
+ buffer_tree sync_filter lsu $(CRYPTOLIB) version \
)
audiod_audio_formats := "wma"
ifeq ($(NEED_VORBIS_OBJECTS),yes)
endif
ifneq ($(HAVE_OSS)-$(HAVE_ALSA),no-no)
executables += mixer
- mixer_objs := $(addsuffix .o, mixer exec string fd time lsu)
+ mixer_objs := $(addsuffix .o, mixer exec string fd time lsu version)
ifeq ($(HAVE_OSS),yes)
mixer_objs += oss_mix.o
endif
ifeq ($(HAVE_CURSES),yes)
executables += gui
gui_objs := $(addsuffix .o, exec signal string stat ringbuffer fd \
- gui gui_theme lsu time sched)
+ gui gui_theme lsu time sched version)
endif
filter_objs := $(addsuffix .o, \
filter_common wav_filter compress_filter filter string stdin stdout \
sched fd amp_filter fecdec_filter fec lsu prebuffer_filter \
time bitstream imdct wma_common wmadec_filter buffer_tree net \
- sync_filter \
+ sync_filter version \
)
ifeq ($(NEED_VORBIS_OBJECTS),yes)
filter_objs += oggdec_filter.o
recv_objs := $(addsuffix .o, \
http_recv recv_common recv time string net dccp_recv fd sched stdout \
udp_recv buffer_tree afh_recv afh_common wma_afh wma_common mp3_afh \
+ version \
)
ifeq ($(NEED_OGG_OBJECTS),yes)
recv_objs += ogg_afh_common.o
audio_format_handlers := mp3 wma
afh_objs := $(addsuffix .o, afh string fd mp3_afh afh_common time wma_afh \
- wma_common)
+ wma_common version)
ifeq ($(NEED_OGG_OBJECTS),yes)
afh_objs += ogg_afh_common.o
endif
wma_afh wma_common mp3_afh recv_common udp_recv http_recv dccp_recv \
filter_common fec bitstream imdct wav_filter compress_filter \
amp_filter prebuffer_filter fecdec_filter wmadec_filter write_common \
- file_write sync_filter lsu interactive \
+ file_write sync_filter lsu interactive version \
)
ifeq ($(NEED_OGG_OBJECTS),yes)
play_objs += ogg_afh_common.o
endif
write_objs := $(addsuffix .o, write write_common file_write time fd \
- string sched stdin buffer_tree check_wav)
+ string sched stdin buffer_tree check_wav version)
ifeq ($(NEED_AO_OBJECTS),yes)
write_objs += ao_write.o
endif
write_objs += alsa_write.o
endif
-audioc_objs := $(addsuffix .o, audioc string lsu net fd time)
+audioc_objs := $(addsuffix .o, audioc string lsu net fd time version)
ifeq ($(HAVE_READLINE),yes)
audioc_objs += buffer_tree.o interactive.o sched.o
endif
$(yy_build_dir):
@$(MKDIR_P) $@
-CPPFLAGS += -DCOPYRIGHT_YEAR='"$(COPYRIGHT_YEAR)"'
-CPPFLAGS += -DBUILD_DATE='"$(build_date)"'
CPPFLAGS += -DLOGLEVELS='$(LOGLEVELS)'
CPPFLAGS += -DSEVERITIES=$(SEVERITIES)
-CPPFLAGS += -DUNAME_RS='"$(uname_rs)"'
-CPPFLAGS += -DCC_VERSION='"$(cc_version)"'
CPPFLAGS += -I$(lls_suite_dir)
CPPFLAGS += -I$(yy_build_dir)
CPPFLAGS += $(lopsub_cppflags)
$(lls_m4_dir)/copyright.m4 | $(man_dir)
$(call SAY, LLSMAN $<)
cat $< $(all_commands) > $@
- $(M4) -D COPYRIGHT_YEAR=$(COPYRIGHT_YEAR) $(lls_m4_dir)/copyright.m4 >> $@
+ $(M4) $(lls_m4_dir)/copyright.m4 >> $@
$(object_dir)/%.o: %.c | $(object_dir)
$(CPPFLAGS) $(STRICT_CFLAGS) $(CFLAGS) $<
endef
CC_PREREQUISITES := %.c | $(object_dir) $(dep_dir) $(lsg_h) $(yy_h)
-# These two have the same prerequisites and the same recipe. There should be a
-# better way to write this.
+# There should be a # better way to write these.
+$(object_dir)/%.o: $(version_dir)/%.c | $(object_dir)
+ $(CC_CMD)
$(object_dir)/%.o: $(CC_PREREQUISITES)
$(CC_CMD)
$(dep_dir)/%.d: $(CC_PREREQUISITES)
git archive --format=tar --prefix=$(tarball_pfx)/ HEAD \
| tar --delete $(tarball_delete) > $(tarball_pfx).tar
$(MKDIR_P) $(tarball_pfx)
- ./GIT-VERSION-GEN > $(tarball_pfx)/VERSION
+ ./version-gen.sh $(PACKAGE_TARNAME) > $(tarball_pfx)/VERSION
cp $(autocrap) $(tarball_pfx)
tar rf $(tarball_pfx).tar $(tarball_pfx)/*
xz -9 $(tarball_pfx).tar
--- /dev/null
+#!/bin/sh
+
+package="$1"
+version_file="$2"
+
+ver='unnamed_version'
+# Try git, version file and gitweb, in this order
+if [ -e '.git' -o -e '../.git' ]; then
+ git_ver=$(git describe --abbrev=4 --always HEAD 2>/dev/null)
+ [ -z "$git_ver" ] && git_ver="$ver"
+ # update stat information in index to match working tree
+ git update-index -q --refresh > /dev/null
+ # if there are differences (exit code 1), the working tree is dirty
+ git diff-index --quiet HEAD || git_ver=$git_ver-dirty
+ ver=$git_ver
+elif [ -f VERSION ]; then
+ ver=$(cat VERSION)
+elif [ "${PWD%%-*}" = $package- ]; then
+ ver=${PWD##*/$package-}
+fi
+ver=${ver#v}
+
+echo "$ver"
+[ -z "${version_file}" ] && exit 0
+# update version file if necessary
+content="const char *${package}_version(void) {return \"$ver\";};"
+info="
+ \"Copyright (C) $COPYRIGHT_YEAR - present $AUTHOR\\n\"
+ \"License: $LICENSE <$LICENSE_URL\\n\"
+ \"This is free software: you are free to change and redistribute it.\\n\"
+ \"There is NO WARRANTY, to the extent permitted by law.\\n\"
+ \"\\n\"
+ \"Project Website: $PROJECT_WEBSITE\\n\"
+ \"Clone URL: $CLONE_URL\\n\"
+ \"Gitweb: $GITWEB_URL\\n\"
+ \"Author Home Page: $HOME_URL\\n\"
+ \"Send feedback to: $AUTHOR <$EMAIL>\\n\"
+"
+content="$content
+const char *${package}_info(void) {return $info;};"
+[ -r "$version_file" ] && printf '%s\n' "$content" | cmp -s - $version_file && exit 0
+[ "$version_file" = "${version_file%/*}" ] || mkdir -p ${version_file%/*}
+printf '%s\n' "$content" > $version_file