did some stuff to make makefile work... it was
painful
This commit is contained in:
parent
c83129a0d5
commit
0ae37a3eba
2
cpp/.gitignore
vendored
2
cpp/.gitignore
vendored
@ -29,4 +29,4 @@
|
|||||||
# Executables
|
# Executables
|
||||||
*.exe
|
*.exe
|
||||||
*.out
|
*.out
|
||||||
*.app
|
*.appobj/
|
||||||
|
50
cpp/Makefile
50
cpp/Makefile
@ -1,32 +1,32 @@
|
|||||||
# Compiler flags (add -O2 for optimization, -g for debugging, etc.)
|
# Add .d to Make's recognized suffixes.
|
||||||
CXXFLAGS = -Wall -O3
|
SUFFIXES += .d
|
||||||
|
|
||||||
# Name of the final executable
|
#We don't need to clean up when we're making these targets
|
||||||
TARGET = stickfosh
|
NODEPS:=clean tags svn
|
||||||
|
#Find all the C++ files in the src/ directory
|
||||||
|
SOURCES:=$(shell find src/ -name "*.cpp")
|
||||||
|
OBJFILES := $(patsubst src/%.cpp,obj/%.o,$(SOURCES))
|
||||||
|
#These are the dependency files, which make will clean up after it creates them
|
||||||
|
DEPFILES:=$(patsubst %.cpp,%.d,$(SOURCES))
|
||||||
|
|
||||||
# List of source files
|
#Don't create dependencies when we're cleaning, for instance
|
||||||
SRCS = main.cpp board.cpp
|
ifeq (0, $(words $(findstring $(MAKECMDGOALS), $(NODEPS))))
|
||||||
|
#Chances are, these files don't exist. GMake will create them and
|
||||||
|
#clean up automatically afterwards
|
||||||
|
-include $(DEPFILES)
|
||||||
|
endif
|
||||||
|
|
||||||
# Automatically generate object file names from source file names
|
#This is the rule for creating the dependency files
|
||||||
OBJS = $(SRCS:.cpp=.o)
|
src/%.d: src/%.cpp
|
||||||
|
$(CXX) $(CXXFLAGS) -MM -MT '$(patsubst src/%.cpp,obj/%.o,$<)' $< -MF $@
|
||||||
|
|
||||||
# Default rule: build the target executable
|
#This rule does the compilation
|
||||||
all: $(TARGET)
|
obj/%.o:
|
||||||
|
@mkdir -p $(dir $@)
|
||||||
|
$(CXX) $(CXXFLAGS) -o $@ -c $<
|
||||||
|
|
||||||
# Link the object files into the final executable
|
main: $(OBJFILES)
|
||||||
$(TARGET): $(OBJS)
|
$(CXX) $(LDFLAGS) $(OBJFILES) $(LOADLIBES) $(LDLIBS) -o main
|
||||||
$(CXX) $(CXXFLAGS) -o $(TARGET) $(OBJS)
|
|
||||||
|
|
||||||
# Pattern rule: compile each .cpp file to a .o file
|
|
||||||
%.o: %.cpp %.hpp
|
|
||||||
$(CXX) $(CXXFLAGS) -c $< -o $@
|
|
||||||
|
|
||||||
main.o: board.o
|
|
||||||
stickfosh: main.o board.o
|
|
||||||
|
|
||||||
# Clean rule to remove built files
|
|
||||||
clean:
|
clean:
|
||||||
rm -f $(TARGET) $(OBJS)
|
rm -rf obj/* $(DEPFILES)
|
||||||
|
|
||||||
# Optional: a rule to rebuild everything from scratch
|
|
||||||
rebuild: clean all
|
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
#include "../board.cpp"
|
#include "../board.hpp"
|
||||||
#include "lib.hpp"
|
#include "lib.hpp"
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
#define ASSERT_EQUALS(expected, actual) \
|
#define ASSERT_EQUALS(expected, actual) \
|
||||||
{ \
|
{ \
|
||||||
if (expected != actual) \
|
if (expected != actual) \
|
||||||
|
Loading…
x
Reference in New Issue
Block a user