all: a1 a2 a3 a4 cmake buggy

# Build the A1 lab exercise
a1:
    g++ -o hello hello.cc
    ./hello

# Build the A2 lab exercise
a2:
    g++ -std=c++11 -o separate_main separate_main.cc separate_fn.cc

# Build the A3 lab exercise
a3:
    g++ -std=c++11 -c separate_main.cc
    g++ -std=c++11 -c separate_fn.cc
    g++ -std=c++11 -o separate_main separate_main.o separate_fn.o

# Build the A4 lab exercise
a4:
    @echo "Will fail"
    -g++ -std=c++11 -o separate_main separate_main.cc

# Build the A5 lab exercise
a5:
    g++ -c -O2 -Wall -Wextra -pedantic-errors -Wold-style-cast -std=c++11 hello.cc

# Build the cmake exercise
cmake:
    rm -rf ./cmake-example/build # Start over
    cd ./cmake-example && mkdir -p build
    cd ./cmake-example/build && cmake ..
    cd ./cmake-example/build && make -j$(nproc)
    ./cmake-example/build/SimpleMain

buggy:
    cd ./buggy_programs && make -j4
    cd ./buggy_programs && mkdir -p build
    cd ./buggy_programs && cmake -B build
    cd ./buggy_programs && make -C build

valgrind: buggy
    cd ./buggy_programs/build/ && valgrind ./dangling
    cd ./buggy_programs/build/ && valgrind ./bounds
    cd ./buggy_programs/build/ && valgrind ./bounds-heap
    cd ./buggy_programs/build/ && valgrind ./leak
    cd ./buggy_programs/build/ && valgrind ./sum
    cd ./buggy_programs/build/ && valgrind ./sum_alt
    cd ./buggy_programs/build/ && valgrind ./ub

clean:
    git clean -fdx