Skip to content

Instantly share code, notes, and snippets.

@JJL772
Created January 16, 2019 07:21
Show Gist options
  • Save JJL772/2e0c7219258bf0e105b155363a2175f6 to your computer and use it in GitHub Desktop.
Save JJL772/2e0c7219258bf0e105b155363a2175f6 to your computer and use it in GitHub Desktop.
#
#
# Sample makefile
#
#
# This macro just describes our java files. This is essentially an array.
# Arrays are specified differently in make, you just list the components separately. Test1 test2 test3 etc.
JAVA_FILES = HelloUser.java HelloUser2.java
# The complete list of sources, this includes the README and Makefile.
# $(JAVA_FILES) expands to HelloUser.java HelloUser2.java so in total SOURCES equals:
# README Makefile HelloUser.java HelloUser2.java
SOURCES = README Makefile $(JAVA_FILES) #$(MACRO) expands the macro, so $(JAVA_FILES) is replaced by HelloUser.java HelloUser2.java
# List of class files
CLASS_FILES = HelloUser.class HelloUser2.class
# The name of the jarfile to create
JARFILE = Hello
# The main class of the program
MAIN_CLASS = HelloUser2
#
#
# all builds everything, this is executed by default if you run make without specifying a target.
# The prerequisite is specified as build-jar, so a jar file is built
#
#
all: build-jar
#
# Targets are specified as this:
# target-name: prerequisites
#
# Targets specified as prereqs are built before the specified target is built
# In this example, build-classes is run before build-jar
#
build-jar: build-classes
# Java is retarded.
# Fucking manifest files?? fuck right off
# echo prints a message to console and the > character redirects output to a file
# So if you do echo fuck java > myfile
# the text "fuck java" will show up in myfile
# In this bullshit we print Main-Class: $(MAIN_CLASS) to the file Manifest
# $(MAIN_CLASS) just expands to HelloUser2
echo Main-Class: $(MAIN_CLASS) > Manifest
#Literally just run the command. $(JARFILE) expands to Hello and $(CLASS_FILES) expands to HelloUser.class and HelloUser2.class
jar cvfm $(JARFILE) Manifest $(CLASS_FILES)
#Removes the dumb ass Manifest file
rm Manifest
#Change permisions and shit
chmod +x $(JARFILE)
#This target runs javac to create the class files
build-classes:
# echo prints to console
echo Building class files...
#We run javac, and specify $(JAVA_FILES) which expands to HelloUser.java and HelloUser2.java
javac -Xlint $(JAVA_FILES)
echo Done!
#This target will remove build products
clean:
# Remove class files
rm $(CLASS_FILES)
#Remove jarfile
rm $(JARFILE)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment