Skip to content

Instantly share code, notes, and snippets.

@tinyplasticgreyknight
Last active September 30, 2017 19:34
Show Gist options
  • Save tinyplasticgreyknight/f4344c3e82f9df9c7a6471e15805500d to your computer and use it in GitHub Desktop.
Save tinyplasticgreyknight/f4344c3e82f9df9c7a6471e15805500d to your computer and use it in GitHub Desktop.
ComputerCraft Makefile
DELETE=rm -rf
PERM_X=chmod +x
PERM_RW=chmod -R +rw
MKDIR=mkdir -p
COPY=cp -r
RENAME=mv
ZIPADD=zip -r
LUAJ_SRC=luaj-2.0.3
LUAJ_JAR=luaj-jse-2.0.3.jar
APISRC=main/java/dan200/computercraft/api
APIDIR=api/src/dan200/computercraft
APIDOC=api/doc
WORKINGJAR=working.jar
DWORKSPACE=deploy/_workspace
INPUTJAR=$(shell ls -1 build/libs | grep -v sources)
OUTPUTJAR=$(subst -,,$(INPUTJAR))
FRIENDLYNAME=$(subst .jar,,$(OUTPUTJAR))
all: fix-perms gradlejar deployjar clean-workspace
deploy-only: deployjar
gradlejar:
./gradlew build
clean: clean-workspace
-$(DELETE) build/libs
-$(DELETE) build/resources
-$(DELETE) build/classes
-$(DELETE) deploy
clean-workspace:
-$(DELETE) $(DWORKSPACE)
fix-perms:
$(PERM_RW) src/main/resources
$(PERM_X) gradlew
deployjar: $(DWORKSPACE)/$(WORKINGJAR) $(DWORKSPACE)/$(APIDIR) $(DWORKSPACE)/$(APIDOC) $(DWORKSPACE)/luaj
-$(MKDIR) deploy
(cd $(DWORKSPACE); $(ZIPADD) $(WORKINGJAR) $(APIDOC) > /dev/null)
(cd $(DWORKSPACE); $(ZIPADD) $(WORKINGJAR) $(APIDIR) > /dev/null)
(cd $(DWORKSPACE)/luaj; $(ZIPADD) ../$(WORKINGJAR) org > /dev/null)
$(RENAME) $(DWORKSPACE)/$(WORKINGJAR) deploy/$(OUTPUTJAR)
$(DWORKSPACE)/$(APIDIR):
$(MKDIR) $(DWORKSPACE)/$(APIDIR)
$(COPY) build/sources/$(APISRC) $(DWORKSPACE)/$(APIDIR)/api
$(DWORKSPACE)/$(APIDOC):
$(MKDIR) $(DWORKSPACE)/$(APIDOC)
find src/$(APISRC) -type f -name "*.java" | xargs javadoc -d $(DWORKSPACE)/$(APIDOC) -windowtitle "$(FRIENDLYNAME)"
$(DWORKSPACE)/luaj: libs/$(LUAJ_JAR)
$(MKDIR) __luaj
(cd __luaj; jar xf ../libs/$(LUAJ_JAR))
$(RENAME) __luaj $(DWORKSPACE)/luaj
build/libs/:
# can only happen when doing a deploy-only
-echo "gradle jar hasn't been build yet, try (make gradlejar) or (make all)"
false
$(DWORKSPACE)/$(WORKINGJAR): build/libs/
-$(MKDIR) $(DWORKSPACE)
$(COPY) build/libs/$(INPUTJAR) $@
libs/$(LUAJ_JAR):
(cd $(LUAJ_SRC); ant clean; ant)
$(COPY) $(LUAJ_SRC)/$(LUAJ_JAR) libs/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment