Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Slightly more aggressive packing #98

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions library/Makefile
Original file line number Diff line number Diff line change
@@ -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 $< $@;
14 changes: 7 additions & 7 deletions stripper/pack.sh
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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