Files
love-release/Makefile
Antonin Décimo 6302efed97 Options & file args support with GNU getopt
Short options are stored in the OPTIONS variable, and longs in
LONG_OPTIONS. Modules scripts need to add theses to be able to use
options. Theses lines are then parsed by sed at make-time and added to
the corresponding variable in the main script.

init_module now requires a third argument corresponding to the option
that will trigger the execution of the module.

Files can also be passed by argument to zip. They are stored in the
FILES array.

check_deps:
    - add dependency check for GNU getopt,
    - echo errors to stderr

gen_version now returns 0 on success and 1 on failure.

Add short_help function. Shown if -h options is passed, or on parsing
options failure.

exit_module:
    - add 'options' exit value if there is an error while parsing the
      options,
    - add 'version' exit value if there is an error while generating
      LÖVE version from user input.

dump_var shows files to zip.

Script will now exit if it has not been embedded nor installed.
Fix bugs with default module.
2015-06-22 22:54:49 +02:00

58 lines
2.5 KiB
Makefile

BUILD_DIR=build
# Installation directories
BINARY_DIR=/usr/bin
INSTALL_DIR=/usr/share/love-release
MANPAGE_DIR=/usr/share/man/man1
COMPLETION_DIR=/usr/share/bash-completion/completions
SED_INSTALL_DIR=$(shell echo "$(INSTALL_DIR)" | sed -e 's/[\/&]/\\&/g')
love-release: clean
mkdir -p $(BUILD_DIR)
for file in scripts/*.sh; do \
short="$${short}$$(grep -E -m 1 "^OPTIONS=['\"]?.*['\"]?" "$$file" | sed -r -e "s/OPTIONS=['\"]?//" -e "s/['\"]?$$//")"; \
long="$${long}$$(grep -E -m 1 "^LONG_OPTIONS=['\"]?.*['\"]?" "$$file" | sed -r -e "s/LONG_OPTIONS=['\"]?//" -e "s/['\"]?$$//")"; \
done; \
if [[ -n $$long && $${long: -1} != ',' ]]; then long="$${long},"; fi; \
sed -re "s/^OPTIONS=(['\"]?)/OPTIONS=\1$$short/" -e "s/^LONG_OPTIONS=(['\"]?)/LONG_OPTIONS=\1$$long/" \
-e 's/INSTALLED=false/INSTALLED=true/' \
-e 's/SCRIPTS_DIR="scripts"/SCRIPTS_DIR="$(SED_INSTALL_DIR)\/scripts"/' love-release.sh > '$(BUILD_DIR)/love-release'
cp love-release.1 '$(BUILD_DIR)/love-release.1'
gzip '$(BUILD_DIR)/love-release.1'
install:
install -m 0755 '$(BUILD_DIR)/love-release' '$(BINARY_DIR)'
install -m 0755 -d '$(INSTALL_DIR)' '$(INSTALL_DIR)/scripts' '$(COMPLETION_DIR)'
install -m 0755 scripts/* '$(INSTALL_DIR)/scripts'
install -m 0644 -t '$(INSTALL_DIR)' README.md conf.lua example.sh
install -m 0644 completion.sh '$(COMPLETION_DIR)/love-release'
install -m 0644 '$(BUILD_DIR)/love-release.1.gz' '$(MANPAGE_DIR)'
embedded: clean
mkdir -p '$(BUILD_DIR)'
for file in scripts/*.sh; do \
module="$$(basename -s '.sh' "$$file")"; \
content='(source <(cat <<\EndOfModule'$$'\n'"$$(cat $$file)"$$'\n''EndOfModule'$$'\n''))'$$'\n''default_module'$$'\n\n'; \
echo "$$content" >> "$(BUILD_DIR)/tmp"; \
short="$${short}$$(grep -E -m 1 "^OPTIONS=['\"]?.*['\"]?" "$$file" | sed -r -e "s/OPTIONS=['\"]?//" -e "s/['\"]?$$//")"; \
long="$${long}$$(grep -E -m 1 "^LONG_OPTIONS=['\"]?.*['\"]?" "$$file" | sed -r -e "s/LONG_OPTIONS=['\"]?//" -e "s/['\"]?$$//")"; \
done; \
if [[ -n $$long && $${long: -1} != ',' ]]; then long="$${long},"; fi; \
sed -re "s/^OPTIONS=(['\"]?)/OPTIONS=\1$$short/" -e "s/^LONG_OPTIONS=(['\"]?)/LONG_OPTIONS=\1$$long/" \
-e 's/EMBEDDED=false/EMBEDDED=true/' \
-e '/include_scripts_here$$/r $(BUILD_DIR)/tmp' love-release.sh > '$(BUILD_DIR)/love-release'
chmod 0775 '$(BUILD_DIR)/love-release.sh'
rm -rf '$(BUILD_DIR)/tmp'
remove:
rm -rf '$(BINARY_DIR)/love-release'
rm -rf '$(INSTALL_DIR)'
rm -rf '$(MANPAGE_DIR)/love-release.1.gz'
rm -rf '$(COMPLETION_DIR)/love-release' '/etc/bash_completion.d/love-release'
clean:
rm -rf '$(BUILD_DIR)'