|
| 1 | +SHELL := /bin/bash |
| 2 | + |
| 3 | +## Copyright 2016-2017 Colin B. Macdonald |
| 4 | +## |
| 5 | +## Copying and distribution of this file, with or without modification, |
| 6 | +## are permitted in any medium without royalty provided the copyright |
| 7 | +## notice and this notice are preserved. This file is offered as-is, |
| 8 | +## without any warranty. |
| 9 | + |
| 10 | +PACKAGE := $(shell grep "^Name: " DESCRIPTION | cut -f2 -d" ") |
| 11 | +VERSION := $(shell grep "^Version: " DESCRIPTION | cut -f2 -d" ") |
| 12 | +MATLAB_PACKAGE_NAME := octsympy |
| 13 | + |
| 14 | +BUILD_DIR := tmp |
| 15 | +MATLAB_PKG := ${BUILD_DIR}/${MATLAB_PACKAGE_NAME}-matlab-${VERSION} |
| 16 | +MATLAB_PKG_ZIP := ${BUILD_DIR}/${MATLAB_PACKAGE_NAME}-matlab-${VERSION}.zip |
| 17 | +OCTAVE_RELEASE := ${BUILD_DIR}/${PACKAGE}-${VERSION} |
| 18 | +OCTAVE_RELEASE_TARBALL := ${BUILD_DIR}/${PACKAGE}-${VERSION}.tar.gz |
| 19 | + |
| 20 | +INSTALLED_PACKAGE := ~/octave/${PACKAGE}-${VERSION}/packinfo/DESCRIPTION |
| 21 | +HTML_DIR := ${BUILD_DIR}/${PACKAGE}-html |
| 22 | +HTML_TARBALL := ${HTML_DIR}.tar.gz |
| 23 | + |
| 24 | +OCTAVE ?= octave |
| 25 | +MATLAB ?= matlab |
| 26 | + |
| 27 | +.PHONY: help clean install test doctest dist dist_zip html matlab_test matlab_pkg |
| 28 | + |
| 29 | +help: |
| 30 | + @echo Available rules: |
| 31 | + @echo " clean clean all temporary files" |
| 32 | + @echo " install install package in Octave" |
| 33 | + @echo " test run tests with Octave" |
| 34 | + @echo " doctest run doctests with Octave" |
| 35 | + @echo " dist create Octave package (${OCTAVE_RELEASE_TARBALL})" |
| 36 | + @echo " html create Octave Forge website" |
| 37 | + @echo |
| 38 | + @echo " matlab_test run tests with Matlab" |
| 39 | + @echo " matlab_pkg create Matlab package (${MATLAB_PKG_ZIP})" |
| 40 | + |
| 41 | + |
| 42 | +GIT_DATE := $(shell git show -s --format=\%ci) |
| 43 | +# Follows the recommendations of https://reproducible-builds.org/docs/archives |
| 44 | +define create_tarball |
| 45 | +$(shell cd $(dir $(1)) \ |
| 46 | + && find $(notdir $(1)) -print0 \ |
| 47 | + | LC_ALL=C sort -z \ |
| 48 | + | tar c --mtime="$(GIT_DATE)" \ |
| 49 | + --owner=root --group=root --numeric-owner \ |
| 50 | + --no-recursion --null -T - -f - \ |
| 51 | + | gzip -9n > "$(2)") |
| 52 | +endef |
| 53 | + |
| 54 | +%.tar.gz: % |
| 55 | + $(call create_tarball,$<,$(notdir $@)) |
| 56 | + |
| 57 | +%.zip: % |
| 58 | + cd "$(BUILD_DIR)" ; zip -9qr - "$(notdir $<)" > "$(notdir $@)" |
| 59 | + |
| 60 | +$(OCTAVE_RELEASE): .git/index | $(BUILD_DIR) |
| 61 | + @echo "Creating package version $(VERSION) release ..." |
| 62 | + -$(RM) -r "$@" |
| 63 | + git archive --format=tar --prefix="$@/" HEAD | tar -x |
| 64 | + $(RM) "$@/README.matlab.md" \ |
| 65 | + "$@/HOWTO-release.md" \ |
| 66 | + "$@/README.bundled.md" \ |
| 67 | + "$@/TODO.md" \ |
| 68 | + "$@/.gitignore" \ |
| 69 | + "$@/.travis.yml" \ |
| 70 | + "$@/.mailmap" \ |
| 71 | + "$@/screenshot.png" \ |
| 72 | + "$@/screenshot-install.png" |
| 73 | + $(RM) -r "$@/testing" "$@/util" |
| 74 | + chmod -R a+rX,u+w,go-w "$@" |
| 75 | + |
| 76 | +$(HTML_DIR): install | $(BUILD_DIR) |
| 77 | + @echo "Generating HTML documentation. This may take a while ..." |
| 78 | + -$(RM) -r "$@" |
| 79 | + $(OCTAVE) --no-window-system --silent \ |
| 80 | + --eval "pkg load generate_html; " \ |
| 81 | + --eval "pkg load $(PACKAGE);" \ |
| 82 | + --eval "options = get_html_options ('octave-forge');" \ |
| 83 | + --eval "generate_package_html ('${PACKAGE}', '${HTML_DIR}', options)" |
| 84 | + chmod -R a+rX,u+w,go-w $@ |
| 85 | + |
| 86 | +dist: $(OCTAVE_RELEASE_TARBALL) |
| 87 | +html: $(HTML_TARBALL) |
| 88 | + |
| 89 | +${BUILD_DIR} ${MATLAB_PKG}/private ${MATLAB_PKG}/tests_matlab ${MATLAB_PKG}/@sym ${MATLAB_PKG}/@symfun ${MATLAB_PKG}/@logical ${MATLAB_PKG}/@double: |
| 90 | + mkdir -p "$@" |
| 91 | + |
| 92 | +clean: |
| 93 | + rm -rf "${BUILD_DIR}" |
| 94 | + @#rm -f fntests.log |
| 95 | + rm -f inst/octsympy_tests.log |
| 96 | + |
| 97 | +test: |
| 98 | + @echo "Testing package in GNU Octave ..." |
| 99 | + @$(OCTAVE) --no-gui --silent --path "${PWD}/inst" \ |
| 100 | + --eval "set (0, 'defaultfigurevisible', 'off'); \ |
| 101 | + anyfail = octsympy_tests; \ |
| 102 | + sympref reset; \ |
| 103 | + exit (anyfail)" |
| 104 | + @echo |
| 105 | + |
| 106 | +doctest: |
| 107 | + @# Workaround for OctSymPy issue 273, we must pre-initialize the package |
| 108 | + @# Otherwise, it will make the doctests fail |
| 109 | + @echo "Testing documentation strings ..." |
| 110 | + @$(OCTAVE) --no-gui --silent --path "${PWD}/inst" \ |
| 111 | + --eval "pkg load doctest; \ |
| 112 | + sym ('x'); \ |
| 113 | + set (0, 'defaultfigurevisible', 'off'); \ |
| 114 | + success = doctest('inst/'); \ |
| 115 | + sympref reset; \ |
| 116 | + exit (!success)" |
| 117 | + @echo |
| 118 | + |
| 119 | + |
| 120 | +## Install in Octave (locally) |
| 121 | +install: ${INSTALLED_PACKAGE} |
| 122 | +${INSTALLED_PACKAGE}: ${OCTAVE_RELEASE_TARBALL} |
| 123 | + $(OCTAVE) --silent --eval "pkg install $<" |
| 124 | + |
| 125 | +## Matlab packaging |
| 126 | +## TODO: should be written to properly use artfacts |
| 127 | +matlab_pkg: $(MATLAB_PKG_ZIP) |
| 128 | + |
| 129 | +${MATLAB_PKG}: $(BUILD_DIR) ${MATLAB_PKG}/private ml_extract_tests |
| 130 | + |
| 131 | +## Matlab: extract unit tests from Octave files, place in separate files |
| 132 | +ml_extract_tests: ${MATLAB_PKG}/tests_matlab ml_copy |
| 133 | + cp -pR misc/octassert.m ${MATLAB_PKG}/tests_matlab/ |
| 134 | + cp -pR misc/extract_tests_for_matlab.m ${MATLAB_PKG}/ |
| 135 | + cp -pR misc/octsympy_tests_matlab.m ${MATLAB_PKG}/ |
| 136 | + cd ${MATLAB_PKG}/; ${OCTAVE} -q --eval "extract_tests_for_matlab" |
| 137 | + rm -f ${MATLAB_PKG}/extract_tests_for_matlab.m |
| 138 | + rm -f ${MATLAB_PKG}/tests_matlab/tests__sympref.m # temp |
| 139 | + |
| 140 | +## Matlab: copy files |
| 141 | +ml_copy: ml_convert_comments |
| 142 | + cp -pR inst/private ${MATLAB_PKG}/ |
| 143 | + cp -pR inst/@sym/private ${MATLAB_PKG}/@sym/ |
| 144 | + cp -pR inst/@symfun/private ${MATLAB_PKG}/@symfun/ |
| 145 | + cp -pR misc/my_print_usage.m ${MATLAB_PKG}/private/print_usage.m |
| 146 | + cp -pR misc/my_print_usage.m ${MATLAB_PKG}/@sym/private/print_usage.m |
| 147 | + cp -pR misc/my_print_usage.m ${MATLAB_PKG}/@symfun/private/print_usage.m |
| 148 | + cp -fp CONTRIBUTORS ${MATLAB_PKG}/ |
| 149 | + cp -fp NEWS ${MATLAB_PKG}/ |
| 150 | + cp -fp COPYING ${MATLAB_PKG}/ |
| 151 | + cp -fp matlab_smt_differences.md ${MATLAB_PKG}/ |
| 152 | + cp -fp README.md ${MATLAB_PKG}/ |
| 153 | + cp -fp README.matlab.md ${MATLAB_PKG}/ |
| 154 | + rm -f ${MATLAB_PKG}/octsympy_tests.m |
| 155 | + |
| 156 | +## Matlab: extract and convert comments to Matlab style |
| 157 | +ml_convert_comments: ${MATLAB_PKG}/@sym ${MATLAB_PKG}/@symfun ${MATLAB_PKG}/@double ${MATLAB_PKG}/@logical |
| 158 | + $(OCTAVE) --path ${PWD}/util --silent --eval "pwd, convert_comments('inst/', '', '../${MATLAB_PKG}/')" |
| 159 | + $(OCTAVE) --path ${PWD}/util --silent --eval "pwd, convert_comments('inst/', '@symfun', '../${MATLAB_PKG}/')" |
| 160 | + $(OCTAVE) --path ${PWD}/util --silent --eval "pwd, convert_comments('inst/', '@sym', '../${MATLAB_PKG}/')" |
| 161 | + $(OCTAVE) --path ${PWD}/util --silent --eval "pwd, convert_comments('inst/', '@double', '../${MATLAB_PKG}/')" |
| 162 | + $(OCTAVE) --path ${PWD}/util --silent --eval "pwd, convert_comments('inst/', '@logical', '../${MATLAB_PKG}/')" |
| 163 | + |
| 164 | +matlab_test: |
| 165 | + ${MATLAB} -nojvm -nodisplay -nosplash -r "addpath('inst'); octsympy_tests_matlab" |
0 commit comments