Skip to content

Instantly share code, notes, and snippets.

@BlameOmar BlameOmar/Makefile
Last active Aug 29, 2015

Embed
What would you like to do?
Sample Makefile for Hunter CS Students
CXX = g++
CXXFLAGS = -Wall
DOCUMENTATION =
BUILD_SYSTEM_FILES = Makefile
DATA_FILES =
SOURCE_FILES = main1.cpp main2.cpp ClassA.h ClassA.cpp ClassB.h ClassB.cpp
EXECUTABLE_1_OBJECT_FILES = main1.o ClassA.o
EXECUTABLE_1 = i-need-a-name
EXECUTABLE_2_OBJECT_FILES = main2.o ClassB.o
EXECUTABLE_2 = i-need-a-name-too
PACKAGER = your-user-name-goes-here
PACKAGE_NAME = hwk1
PACKAGE_DIRECTORY = $(PACKAGER)_$(PACKAGE_NAME)
PACKAGE_FILES = $(BUILD_SYSTEM_FILES) $(SOURCE_FILES) $(DOCUMENTATION) $(DATA_FILES)
PACKAGE_FILE = $(PACKAGE_DIRECTORY).zip
.DEFAULT_GOAL = all
$(EXECUTABLE_1): $(OBJECT_FILES)
$(CXX) $(CXXFLAGS) -o $(EXECUTABLE_1) $(EXECUTABLE_1_OBJECT_FILES)
$(EXECUTABLE_2): $(OBJECT_FILES)
$(CXX) $(CXXFLAGS) -o $(EXECUTABLE_2) $(EXECUTABLE_2_OBJECT_FILES)
%.o: %.cpp
$(CXX) $(CXXFLAGS) -c $<
%.cpp: %.h
touch $@
$(PACKAGE_FILE): $(PACKAGE_FILES) | $(PACKAGE_DIRECTORY)
cp $(PACKAGE_FILES) $(PACKAGE_DIRECTORY)
zip -r $(PACKAGE_FILE) ./$(PACKAGE_DIRECTORY)
chmod 600 $(PACKAGE_FILE)
$(PACKAGE_DIRECTORY):
mkdir -p $(PACKAGE_DIRECTORY)
chmod 700 $(PACKAGE_DIRECTORY)
all: $(EXECUTABLE_1) $(EXECUTABLE_2) package
clean:
rm -rf $(OBJECT_FILES) $(EXECUTABLE_1) $(EXECUTABLE_2) $(PACKAGE_DIRECTORY) $(PACKAGE_FILE)
package: $(PACKAGE_FILE)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.