vim

Fork of vim, an acceptable text editor
git clone git://git.laack.co/vim.git
Log | Files | Refs | README | LICENSE

unlisted.make (1845B)


      1 # vim: ft=make
      2 SHELL = /bin/bash
      3 
      4 # List all files that are tracked in git but not listed in Filelist.
      5 # Exit code is 2 ("Make encountered an error") if any such files exist.
      6 
      7 # Filelist is a Makefile that defines many variables, so we use Make itself to
      8 # query which variables it defines, then expand them all by wrapping each name
      9 # in $(...), importing Filelist and using $(eval).
     10 
     11 include Filelist
     12 $(eval all_patterns := $(shell \
     13 	make -f Filelist --question --print-data-base --no-builtin-rules \
     14 		--no-builtin-variables 2>/dev/null \
     15 	| sed -nre \
     16 		'/^# makefile .from \x27Filelist\x27,/ { \
     17 			n; \
     18 			s/ = .*//; \
     19 			T; \
     20 			s/.*/$$(\0)/; \
     21 			p; \
     22 		}'))
     23 
     24 # In Makefile's `prepare` target, all the IN_README_DIR files are moved from
     25 # READMEdir to the root, so add those files in their Git-tracked location:
     26 all_patterns := $(all_patterns) \
     27 	$(foreach readme, $(IN_README_DIR), READMEdir/$(readme))
     28 
     29 # The result 'all_patterns' is a list of patterns (globs), which we expand with
     30 # wildcard to get actual filenames.  Note this means Filelist can list a file
     31 # that does not exist, and it will be omitted at this step.
     32 listed_files := $(wildcard $(all_patterns))
     33 
     34 # Default target to actually run the comparison:
     35 .PHONY: check
     36 check:
     37 	@# There are too many files to list on the command line, so we write
     38 	@# that to a temporary file, one per line.
     39 	$(file > Filelist-listed-files)
     40 	$(foreach filename, $(listed_files),\
     41 		$(file >> Filelist-listed-files,$(filename)))
     42 	@# Compare the sorted lists.  Delete that temporary file on both
     43 	@# success and failure, but exit with diff's exit code.
     44 	diff -u0 --label files-in-git <(git ls-files | sort) \
     45 		--label Filelist <(sort --unique Filelist-listed-files); \
     46 	RV=$$?; \
     47 	rm Filelist-listed-files; \
     48 	(($$RV != 0)) && echo "Add files to the right variable in Filelist."; \
     49 	exit $$RV