diff --git a/library/Makefile b/library/Makefile new file mode 100644 index 0000000..0a87882 --- /dev/null +++ b/library/Makefile @@ -0,0 +1,37 @@ +# This file is distributed under the terms of the MIT license, (c) the KSLib team + +# The purpose of this Makefile is to decrease size of .ks files for the final flight. However, please upload +# UNPACKED versions of programs to KSLib. + +# This version mostly works in Unix and cygwin environments. + +# This is where your live KSP script archive is located. +INSTALLDIR = ~/Desktop/Kerbal\\\ Space\\\ Program/Ships/Script +# This is where you want the packed/stripped versions to go (for now, you'll have to create the directory) +STAGEDIR = packed + +# list all of your .ks files +files := $(wildcard *.ks) +# create a list of .ksp files, homed in your staging directory +packed := $(foreach file, $(files:.ks=.ksp), $(STAGEDIR)/$(file)) +# create a list of all your .ks files, homed in your live archive +installed := $(foreach file, $(files), $(INSTALLDIR)/$(file)) + +# By default, pack up all your .ks files as .ksp files in your staging directory +all : $(packed) + +# make install to copy your packed files to your live directory (and rename them back to .ks files) +install : $(installed) + +# empty out your staging directory +clean : + rm $(packed); + +### +# How to convert .ks files to staged .ksp files, and how to convert staged .ksp files to installed .ks files +### +$(STAGEDIR)/%.ksp : %.ks + /bin/sed -e 's|^\(\([^"]*\)\("[^"]*"[^"]*\)*\)\s*//.*$$|\1|g' -e 's|^\(\([^"]*\)\("[^"]*"[^"]*\)*\)\s*//.*$$|\1|g' -e 's|^\s*\(.*\)\s*$$|\1|g' -e '/^$$/d' $< > $@; + +$(INSTALLDIR)/%.ks : $(STAGEDIR)/%.ksp + cp $< $@; diff --git a/stripper/pack.sh b/stripper/pack.sh index e4f3634..62dd659 100644 --- a/stripper/pack.sh +++ b/stripper/pack.sh @@ -1,6 +1,6 @@ # This file is distributed under the terms of the MIT license, (c) the KSLib team -# The purpose of this file is to decrease size of .ks files for the final flight. However, please upload +# The purpose of this file is to decrease size of .ks files for the final flight. However, please upload # UNPACKED versions of programs to KSLib. # This version works in Unix environments. @@ -12,11 +12,11 @@ FILES=`ls *.ks` echo $FILES for f in $FILES; do sed \ - -e 's/^\(\([^"]*\)\("[^"]*"[^"]*\)*\)\/\/.*/\1/g' \ - -e 's/^\( \|\t\)*//g' \ - -e 's/\( \|\t\)*$//g' \ + -e 's|^\(\([^"]*\)\("[^"]*"[^"]*\)*\)\s*//.*$$|\1|g' -e 's|^\(\([^"]*\)\("[^"]*"[^"]*\)*\)\s*//.*$$|\1|g' \ + -e 's|^\s*\(.*)\s*$|\1|g' \ + -e '/^$/d' $f > packed/$f; - # the first line strips comments - # the second line strips leading whitespace - # the third line strips trailing whitespace + # the first line strips comments (doubled to catch pesky URLs in comments) + # the second line strips leading and trailing whitespace + # the third line removes all empty lines (which should be stripped down by the second line) done