Skip to content

Commit 871d4fc

Browse files
committed
feat: add bundle target
The bundle target generates an archive of the entire Git repository, including the .git directory. The output filename can be specified with the BUNDLEFILE variable.
1 parent 921685f commit 871d4fc

2 files changed

Lines changed: 61 additions & 1 deletion

File tree

Makefile

Lines changed: 54 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,9 @@ Targets
6464
dist:
6565
Create tar-gzipped archives for arXiv submission.
6666

67+
bundle:
68+
Create an archive containing all files from the current Git repository.
69+
6770
watch:
6871
Watch the changes and automatically rebuild documents.
6972

@@ -139,6 +142,9 @@ EXTRADISTFILES =
139142
# Files to be copied in "anc" directory in a distribution.
140143
ANCILLARYFILES =
141144

145+
# Bundle filename (including extension).
146+
BUNDLEFILE = bundle.tar.gz
147+
142148
# Additional files to mostly-clean.
143149
MOSTLYCLEANFILES =
144150

@@ -893,6 +899,7 @@ cleanfiles_impl = $(wildcard $(strip \
893899
$(srcltxfiles:.ltx=.fmt) \
894900
$(srcdtxfiles:.dtx=.cls) \
895901
$(srcdtxfiles:.dtx=.sty) \
902+
$(BUNDLEFILE) \
896903
$(CLEANFILES) \
897904
$(mostlycleanfiles) \
898905
))
@@ -1377,6 +1384,52 @@ _check_rule = \
13771384
$(MAKE) --no-print-directory $1 1="$(call TESTS_OPT,$1)" || exit 1; \
13781385
)
13791386

1387+
bundle:
1388+
@$(if $(strip $(BUNDLEFILE)), \
1389+
$(if $(or $(filter %.tar.gz,$(BUNDLEFILE)),$(filter %.tgz,$(BUNDLEFILE))), \
1390+
$(call _make_bundle,$(_make_bundle_tar_gz)) \
1391+
,$(if $(filter %.zip,$(BUNDLEFILE)), \
1392+
$(call _make_bundle,$(_make_bundle_zip)) \
1393+
, \
1394+
$(error unsupported BUNDLEFILE extension: $(BUNDLEFILE)) \
1395+
)) \
1396+
, \
1397+
$(error BUNDLEFILE is not set) \
1398+
)
1399+
1400+
_make_bundle = \
1401+
temp_dir=.tmp_$$$$_$$(awk 'BEGIN {srand(); print srand()}') \
1402+
&& mkdir "$$temp_dir" \
1403+
&& cd "$$temp_dir" \
1404+
&& git clone .. "$(_bundle_name)" \
1405+
&& cd "$(_bundle_name)" \
1406+
&& git remote remove origin \
1407+
&& git reflog expire --expire=now --expire-unreachable=now --all \
1408+
&& git prune --expire=now \
1409+
&& git pack-refs --all --prune \
1410+
&& git gc --aggressive --prune=now \
1411+
&& cd .. \
1412+
&& $1 \
1413+
&& cd .. \
1414+
&& mv "$$temp_dir/$(notdir $(BUNDLEFILE))" "$(BUNDLEFILE)" \
1415+
&& rm -rf "$$temp_dir"
1416+
1417+
_make_bundle_tar_gz = \
1418+
$(call exec,tar cfv - --exclude $(notdir $(BUNDLEFILE)) * | gzip -9 -n >$(notdir $(BUNDLEFILE)))
1419+
1420+
_make_bundle_zip = \
1421+
$(call exec,TZ=UTC zip -X -9 -r $(notdir $(BUNDLEFILE)) *)
1422+
1423+
_bundle_name = $(strip \
1424+
$(if $(filter %.tar.gz,$(BUNDLEFILE)), \
1425+
$(basename $(basename $(notdir $(BUNDLEFILE)))) \
1426+
,$(if $(or $(filter %.tgz,$(BUNDLEFILE)),$(filter %.zip,$(BUNDLEFILE))), \
1427+
$(basename $(notdir $(BUNDLEFILE))) \
1428+
, \
1429+
$(notdir $(BUNDLEFILE)) \
1430+
)) \
1431+
)
1432+
13801433
# The "watch" mode. Try to update .log files instead of .pdf/.dvi files,
13811434
# otherwise make would continuously try to typeset for sources previously
13821435
# failed.
@@ -1516,7 +1569,7 @@ _FORCE:
15161569
_run_testsuite:
15171570
@$(run_testsuite)
15181571

1519-
.PHONY : all all-recursive check clean dist dvi eps fmt help jpg lint mostlyclean pdf png pretty ps prerequisite postprocess svg upgrade watch _FORCE _run_testsuite
1572+
.PHONY : all all-recursive bundle check clean dist dvi eps fmt help jpg lint mostlyclean pdf png pretty ps prerequisite postprocess svg upgrade watch _FORCE _run_testsuite
15201573

15211574
# $(call typeset,LATEX-COMMAND) tries to typeset the document.
15221575
# $(call typeset,LATEX-COMMAND,false) doesn't delete the output file on failure.

README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,8 @@ Targets
8181
Run linters for source files in the current directory.
8282
- `dist`:
8383
Create tar-gzipped archives for [arXiv](https://arxiv.org/) submission.
84+
- `bundle`:
85+
Create an archive containing all files from the current Git repository.
8486
- `watch`:
8587
Watch the changes and automatically rebuild documents in the current
8688
directory.
@@ -183,6 +185,11 @@ Variables
183185
the [`anc` directory](https://arxiv.org/help/ancillary_files) inside
184186
the resultant file.
185187

188+
- `BUNDLEFILE`:
189+
Specify the archive filename generated by `make bundle`.
190+
The valid file extensions are `.tar.gz`, `.tgz` and `.zip`.
191+
The default value is `bundle.tar.gz`.
192+
186193
- `MOSTLYCLEANFILES`, `CLEANFILES`:
187194
Specify files to be deleted for `make mostlyclean` and `make clean`, respectively.
188195
Given on the command line or in the user configuration files.

0 commit comments

Comments
 (0)