From e34652aa17830772f31b0145c1842bef57748081 Mon Sep 17 00:00:00 2001
From: Brandon Rodriguez <brodriguez8774@gmail.com>
Date: Tue, 20 Nov 2018 04:41:50 -0500
Subject: [PATCH] Update make files to be more standardized

---
 .gitignore                          |  9 ------
 spikes/ieee_floating_point/Makefile | 25 +++++++++------
 spikes/input_handling/Makefile      | 47 ++++++++++++++++++++++++-----
 spikes/logging/Makefile             | 32 ++++++++++++++++----
 spikes/make/Makefile                | 31 +++++++++++++++++--
 spikes/square_root/Makefile         | 25 +++++++++------
 spikes/unit_testing/Makefile        | 26 ++++++++++++++--
 spikes/variadic_macros/Makefile     | 33 ++++++++++++++++----
 src/Makefile                        | 13 +++++---
 tests/Makefile                      |  9 +++++-
 tests/integration_tests/Makefile    | 11 +++++--
 tests/unit_tests/Makefile           | 20 ++++++------
 12 files changed, 211 insertions(+), 70 deletions(-)

diff --git a/.gitignore b/.gitignore
index 114dacb..4e711f1 100644
--- a/.gitignore
+++ b/.gitignore
@@ -11,17 +11,8 @@ src/quad_solver
 spikes/ieee_floating_point/float
 spikes/ieee_floating_point/sandbox/sandbox
 spikes/square_root/sqrt
-spikes/input_handling/arg_parse
-spikes/input_handling/simple_parse
-spikes/input_handling/std_in
-spikes/logging/log_with_function
-spikes/logging/log_with_macro
 spikes/logging/log_file.txt
-spikes/make/read_from_file
-spikes/unit_testing/unit_tests
 spikes/variadic_macros/log_file.txt
-spikes/variadic_macros/variadic_macro_to_console
-spikes/variadic_macros/variadic_macro_to_file
 
 # Ignore vscode files
 .vscode
diff --git a/spikes/ieee_floating_point/Makefile b/spikes/ieee_floating_point/Makefile
index eeeddca..092f5f9 100644
--- a/spikes/ieee_floating_point/Makefile
+++ b/spikes/ieee_floating_point/Makefile
@@ -1,16 +1,22 @@
-TARGET = float 
+# Makefile for IEE Floating Point spikes.
+
+TARGET = float
 LIBS = -lm
 CC = gcc
 CFLAGS = -Wall -pedantic -std=gnu99 -g
 
+
+# Ensure that commands run as intended, even if file with same name exists.
 .PHONY: default all clean
 
+# Default command if nothing is passed.
 default: $(TARGET)
 all: default
 
-# Expect a .o for each .c file in the directory
+
+# Expect a .o for each .c file in the directory.
 OBJECTS = $(patsubst %.c, %.o, $(wildcard *.c))
-# Get all .h files in the directory
+# Get all .h files in the directory.
 HEADERS = $(wildcard *.h)
 
 %.o: %.c $(HEADERS)
@@ -21,24 +27,25 @@ HEADERS = $(wildcard *.h)
 $(TARGET): $(OBJECTS)
 	$(CC) $(OBJECTS) -Wall $(LIBS) -o $@
 
-# Remove older builds
+
+# Remove older builds and clear temp files.
 clean:
 	-rm -f $(OBJECTS)
 	-rm -f $(TARGET)
 
-# Update time of modification
+# Update time of modification.
 touch:
 	touch *.h
 	touch *.c
 
-# Advanced memory usage stats as well as crash reporting
+# Advanced memory usage stats as well as crash reporting.
 valgrind: $(TARGET)
 	valgrind --leak-check=full --show-reachable=yes ./$(TARGET)
 
-# Debug
+# Debug.
 debug:
 	gdb $(TARGET)
 
-# Run compiled code
+# Run compiled code.
 test:
-	./$(TARGET) 123456.78
\ No newline at end of file
+	./$(TARGET) 123456.78
diff --git a/spikes/input_handling/Makefile b/spikes/input_handling/Makefile
index 8261bf1..bc1807e 100644
--- a/spikes/input_handling/Makefile
+++ b/spikes/input_handling/Makefile
@@ -1,12 +1,43 @@
+# Makefile for Input Handling spikes.
 
-all:
-	Please specify spike.
+LIBS = -lm
+CC = gcc
+CFLAGS = -Wall -pedantic -std=c99 -g
+SRC_DIR = ../../src
 
-arg_parse:
-	gcc -Wall -Wpedantic -std=c99 -g arg_parse.c ../../src/argparse.c ../../src/helper.c -o arg_parse
 
-simple_parse:
-	gcc -Wall -Wpedantic -std=c99 -g simple_parse.c -o simple_parse
+# Ensure that commands run as intended, even if file with same name exists.
+.PHONY: default all clean arg_parse simple_parse std_in
 
-std_in:
-	gcc -Wall -Wpedantic -std=c99 -g std_in.c -o std_in
+# Default command if nothing is passed.
+default:
+	@echo Please specify spike: [ arg_parse, simple_parse, std_in ]
+all: default
+
+
+# Arg parse spike.
+arg_parse: spike_arg_parse.o src_arg_parse.o helper.o prompt.o
+	${CC} -o arg_parse.out $^ $(LIBS)
+spike_arg_parse.o: arg_parse.c
+	${CC} -c -o $@ $< ${CFLAGS}
+src_arg_parse.o: $(SRC_DIR)/argparse.c
+	${CC} -c -o $@ $< ${CFLAGS}
+helper.o: $(SRC_DIR)/helper.c
+	${CC} -c -o $@ $< ${CFLAGS}
+prompt.o: $(SRC_DIR)/prompt.c
+	${CC} -c -o $@ $< ${CFLAGS}
+
+# Simple parse spike.
+simple_parse: simple_parse.o
+	${CC} -o simple_parse.out $^ $(LIBS)
+simple_parse.o: simple_parse.c
+
+# Std in spike.
+std_in: std_in.o
+	${CC} -o std_in.out $^ $(LIBS)
+std_in.o: std_in.c
+
+
+# Remove older builds and clear temp files.
+clean:
+	-rm -f *.o *.out
diff --git a/spikes/logging/Makefile b/spikes/logging/Makefile
index c6c8bd6..d3e464e 100644
--- a/spikes/logging/Makefile
+++ b/spikes/logging/Makefile
@@ -1,10 +1,30 @@
+# Makefile for Logging spikes.
 
-all:
-	Please specify spike.
+LIBS = -lm
+CC = gcc
+CFLAGS = -Wall -pedantic -std=c99 -g
 
-log_with_function:
-	gcc -Wall -Wpedantic -std=c99 -g log_with_function.c -o log_with_function
 
-log_with_macro:
-	gcc -Wall -Wpedantic -std=c99 -g log_with_macro.c -o log_with_macro
+# Ensure that commands run as intended, even if file with same name exists.
+.PHONY: default all clean log_with_function log_with_macro
 
+# Default command if nothing is passed.
+default:
+	@echo Please specify spike: [ log_with_function, log_with_macro ]
+all: default
+
+
+# Log with function spike.
+log_with_function: log_with_function.o
+	${CC} -o log_with_function.out $^ $(LIBS)
+log_with_function.o: log_with_function.c
+
+# Log with macro spike.
+log_with_macro: log_with_macro.o
+	${CC} -o log_with_macro.out $^ $(LIBS)
+log_with_macro.o: log_with_macro.c
+
+
+# Remove older builds and clear temp files.
+clean:
+	-rm -f *.o *.out log_file.txt
diff --git a/spikes/make/Makefile b/spikes/make/Makefile
index 8479300..5f0452f 100644
--- a/spikes/make/Makefile
+++ b/spikes/make/Makefile
@@ -1,6 +1,31 @@
+# Makefile for Make spikes.
 
-all:
-	gcc -Wall -Wpedantic -std=c99 -g *.c -o read_from_file
+LIBS = -lm
+CC = gcc
+CFLAGS = -Wall -pedantic -std=c99 -g
+
+
+# Ensure that commands run as intended, even if file with same name exists.
+.PHONY: default all clean read_from_file
+
+# Default command if nothing is passed.
+default: read_from_file
+all: default
+
+
+# Read from file spike.
+read_from_file: read_from_file.o
+	${CC} -o read_from_file.out $^ $(LIBS)
+	make read
+read_from_file.o: read_from_file.c
 
 read:
-	./read_from_file < input.txt
+	./read_from_file.out < input.txt
+
+
+# Remove older builds and clear temp files.
+clean:
+	-rm -f *.o *.out
+
+
+
diff --git a/spikes/square_root/Makefile b/spikes/square_root/Makefile
index 5f116e1..e82c132 100644
--- a/spikes/square_root/Makefile
+++ b/spikes/square_root/Makefile
@@ -1,16 +1,22 @@
-TARGET = sqrt 
+# Makefile for Square Root spikes.
+
+TARGET = sqrt
 LIBS = -lm
 CC = gcc
 CFLAGS = -Wall -pedantic -std=gnu99 -g
 
+
+# Ensure that commands run as intended, even if file with same name exists.
 .PHONY: default all clean
 
+# Default command if nothing is passed.
 default: $(TARGET)
 all: default
 
-# Expect a .o for each .c file in the directory
+
+# Expect a .o for each .c file in the directory.
 OBJECTS = $(patsubst %.c, %.o, $(wildcard *.c))
-# Get all .h files in the directory
+# Get all .h files in the directory.
 HEADERS = $(wildcard *.h)
 
 %.o: %.c $(HEADERS)
@@ -21,24 +27,25 @@ HEADERS = $(wildcard *.h)
 $(TARGET): $(OBJECTS)
 	$(CC) $(OBJECTS) -Wall $(LIBS) -o $@
 
-# Remove older builds
+
+# Remove older builds and clear temp files.
 clean:
 	-rm -f $(OBJECTS)
 	-rm -f $(TARGET)
 
-# Update time of modification
+# Update time of modification.
 touch:
 	touch *.h
 	touch *.c
 
-# Advanced memory usage stats as well as crash reporting
+# Advanced memory usage stats as well as crash reporting.
 valgrind: $(TARGET)
 	valgrind --leak-check=full --show-reachable=yes ./$(TARGET)
 
-# Debug
+# Debug.
 debug:
 	gdb $(TARGET)
 
-# Run compiled code
+# Run compiled code.
 test:
-	./$(TARGET) 123456.78
\ No newline at end of file
+	./$(TARGET) 123456.78
diff --git a/spikes/unit_testing/Makefile b/spikes/unit_testing/Makefile
index 6ce1a28..9599a47 100644
--- a/spikes/unit_testing/Makefile
+++ b/spikes/unit_testing/Makefile
@@ -1,3 +1,25 @@
+# Makefile for Unit Testing spikes.
 
-all:
-	gcc -Wall -Wpedantic -std=c99 -g *.c -o unit_tests -lcunit
+LIBS = -lm -lcunit
+CC = gcc
+CFLAGS = -Wall -pedantic -std=c99 -g
+
+
+# Ensure that commands run as intended, even if file with same name exists.
+.PHONY: default all clean unit_tests
+
+# Default command if nothing is passed.
+default: unit_tests
+all: default
+
+
+# Unit test spike.
+unit_tests: unit_tests.o dummy_functions.o
+	${CC} -o unit_tests.out $^ $(LIBS)
+unit_tests.o: unit_tests.c
+dummy_functions.o: dummy_functions.c
+
+
+# Remove older builds and clear temp files.
+clean:
+	-rm -f *.o *.out
diff --git a/spikes/variadic_macros/Makefile b/spikes/variadic_macros/Makefile
index f0b07ac..cf34c09 100644
--- a/spikes/variadic_macros/Makefile
+++ b/spikes/variadic_macros/Makefile
@@ -1,9 +1,30 @@
+# Makefile for Variadic Macro spikes.
 
-all:
-	Please specify spike: [ to_console, to_file ]
+LIBS = -lm
+CC = gcc
+CFLAGS = -Wall -pedantic -std=c99 -g
 
-to_console:
-	gcc -Wall -Wpedantic -std=c99 -g variadic_macro_to_console.c -o variadic_macro_to_console
 
-to_file:
-	gcc -Wall -Wpedantic -std=c99 -g variadic_macro_to_file.c -o variadic_macro_to_file
+# Ensure that commands run as intended, even if file with same name exists.
+.PHONY: default all clean to_console to_file
+
+# Default command if nothing is passed.
+default:
+	@echo Please specify spike: [ to_console, to_file ]
+all: default
+
+
+# Variadic Macro To console spike.
+to_console: variadic_macro_to_console.o
+	${CC} -o variadic_macro_to_console.out $^ $(LIBS)
+variadic_macro_to_console.o: variadic_macro_to_console.c
+
+# Variadic Macro To file spike.
+to_file: variadic_macro_to_file.o
+	${CC} -o variadic_macro_to_file.out $^ $(LIBS)
+variadic_macro_to_file.o: variadic_macro_to_file.c
+
+
+# Remove older builds and clear temp files.
+clean:
+	-rm -f *.o *.out log_file.txt
diff --git a/src/Makefile b/src/Makefile
index 7df17e8..cecdfec 100644
--- a/src/Makefile
+++ b/src/Makefile
@@ -1,3 +1,4 @@
+# Makefile for Quad Solver.
 # Made from http://stackoverflow.com/questions/1484817/how-do-i-make-a-simple-makefile-for-gcc-on-linux
 
 TARGET = quad_solver
@@ -5,31 +6,33 @@ LIBS = -lm
 CC = gcc
 CFLAGS = -Wall -pedantic -std=c99 -g
 
+
+# Ensure that commands run as intended, even if file with same name exists.
 .PHONY: default all clean
 
+# Default command if nothing is passed.
 default: $(TARGET)
 all: default
 
+
 # Link given dependencies into binary named TARGET
 # $^ will be replaced with 'main.o argparse.o ...'
 $(TARGET): main.o argparse.o compute.o my_sqrt.o helper.o prompt.o
 	${CC} -o $(TARGET) $^ $(LIBS)
 
 main.o: main.c argparse.h compute.h helper.h prompt.h
-
 argparse.o: argparse.c argparse.h helper.h
-
 compute.o: compute.c compute.h helper.h
-
 my_sqrt.o: my_sqrt.c my_sqrt.h
-
 helper.o: helper.c helper.h
-
 prompt.o: prompt.c prompt.h helper.h
 
+
+# Remove older builds and clear temp files.
 clean:
 	-rm -f *.o
 	-rm -f $(TARGET)
 
+# Advanced memory usage stats as well as crash reporting.
 valgrind: $(TARGET)
 	valgrind --leak-check=full --show-reachable=yes ./$(TARGET) -n 2 4 8
diff --git a/tests/Makefile b/tests/Makefile
index cc3d6f1..0152798 100644
--- a/tests/Makefile
+++ b/tests/Makefile
@@ -1,14 +1,21 @@
-# Makefile for Unit Tests
+# Makefile for Tests.
 
+
+# Ensure that commands run as intended, even if file with same name exists.
 .PHONY: default all clean test
 
+# Default command if nothing is passed.
 default: test
 all: default
 
+
+# Run all types of tests.
 test:
 	make -C unit_tests
 	make -C integration_tests
 
+
+# Remove older builds and clear temp files.
 clean:
 	make -C unit_tests clean
 	make -C integration_tests clean
diff --git a/tests/integration_tests/Makefile b/tests/integration_tests/Makefile
index b4f8789..aea495e 100644
--- a/tests/integration_tests/Makefile
+++ b/tests/integration_tests/Makefile
@@ -1,11 +1,17 @@
+# Makefile for Integration Tests.
+
 SRC_DIR = ../../src
 
+
+# Ensure that commands run as intended, even if file with same name exists.
 .PHONY: default all clean test_int_all quad_solver
 
+# Default command if nothing is passed.
 default: test_int_all
 all: default
 
-# This will always run make in src
+
+# Run quad solver makefile found in src folder.
 quad_solver:
 	make -C $(SRC_DIR)
 
@@ -13,6 +19,7 @@ test_int_all: quad_solver
 	./test_ranges.sh $(SRC_DIR)
 	./test_examples.sh $(SRC_DIR)
 
-# Clean does nothing for now
+
+# Remove older builds and clear temp files (Does nothing for now).
 clean:
 	rm -f *.tmp
diff --git a/tests/unit_tests/Makefile b/tests/unit_tests/Makefile
index 50fb9cb..6b2535e 100644
--- a/tests/unit_tests/Makefile
+++ b/tests/unit_tests/Makefile
@@ -1,4 +1,4 @@
-# Makefile for Unit Tests
+# Makefile for Unit Tests.
 
 LIBS = -lm -lcunit
 CC = gcc
@@ -6,36 +6,36 @@ CFLAGS = -Wall -pedantic -std=c99 -g
 SRC_DIR = ../../src
 CUNIT_DIR = ../cunit
 
+
+# Ensure that commands run as intended, even if file with same name exists.
 .PHONY: default all clean test_unit_all
 
+# Default command if nothing is passed.
 default: test_unit_all
 all: default
 
+
+# Run all unit tests.
 test_unit_all: test_my_sqrt.out unit_tests.out
 	./test_my_sqrt.out
 	./unit_tests.out
 
-# Mini Cunit Library tests
-
+# Mini Cunit Library tests.
 test_my_sqrt.out: my_sqrt.o test_my_sqrt.o mock_sqrt.o cunit.o
 	${CC} -o $@ $^ $(LIBS) -Wl,--wrap=sqrt
-
 my_sqrt.o: $(SRC_DIR)/my_sqrt.c $(SRC_DIR)/my_sqrt.h
 	${CC} -c -o $@ $< ${CFLAGS}
-
 test_my_sqrt.o: test_my_sqrt.c mock_sqrt.h
-
 mock_sqrt.o: mock_sqrt.c
-
 cunit.o: $(CUNIT_DIR)/cunit.c $(CUNIT_DIR)/cunit.h
 	${CC} -c -o $@ $< ${CFLAGS}
 
-# Cunit Library tests
-
+# Cunit Library tests.
 unit_tests.out : unit_tests.o $(SRC_DIR)/argparse.o $(SRC_DIR)/compute.o $(SRC_DIR)/my_sqrt.o $(SRC_DIR)/helper.o $(SRC_DIR)/prompt.o
 	${CC} -o unit_tests.out $^ $(LIBS)
-
 unit_tests.o: unit_tests.c
 
+
+# Remove older builds and clear temp files.
 clean:
 	-rm -f *.o *.out
-- 
GitLab