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.
This commit is contained in:
Antonin Décimo
2015-06-18 10:31:08 +02:00
parent 3b48234432
commit 6302efed97
6 changed files with 121 additions and 31 deletions

View File

@@ -11,7 +11,14 @@ SED_INSTALL_DIR=$(shell echo "$(INSTALL_DIR)" | sed -e 's/[\/&]/\\&/g')
love-release: clean
mkdir -p $(BUILD_DIR)
sed -e 's/INSTALLED=false/INSTALLED=true/' -e 's/SCRIPTS_DIR="scripts"/SCRIPTS_DIR="$(SED_INSTALL_DIR)\/scripts"/' love-release.sh > '$(BUILD_DIR)/love-release'
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'
@@ -25,15 +32,19 @@ install:
embedded: clean
mkdir -p '$(BUILD_DIR)'
sed 's/EMBEDDED=false/EMBEDDED=true/' love-release.sh > '$(BUILD_DIR)/love-release.sh'
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"; \
done
sed -i.bak -e '/include_scripts_here$$/r $(BUILD_DIR)/tmp' '$(BUILD_DIR)/love-release.sh';
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)/love-release.sh.bak' '$(BUILD_DIR)/tmp'
rm -rf '$(BUILD_DIR)/tmp'
remove:
rm -rf '$(BINARY_DIR)/love-release'