diff --git a/.gitignore b/.gitignore index 114dacb7eb0731820f94da6cf356fa734bed8e96..4e711f1e537c0a514ff8e5f50ce5678dafe1623e 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 eeeddca2279318fd84512480517f9d665ba09c0b..092f5f95342a504c0fdac6cbeaec723b9ae4b861 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 8261bf1a82a934ba557b3b59aa37d6e42180d018..bc1807e429ed9d09743e792c83f623e667e82499 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 c6c8bd61705014497201b7a4371ab47be070963a..d3e464eeaaa676eb0086f4487f7026c1fb5c8ed8 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 8479300b6e56098d5b63be2150dae49bb1133881..5f0452f639fe4e72906abb3eeb065d93f3e6dea9 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 5f116e1cc1ab615cc1168ada9b597bc38b277eb1..e82c13203dbffa309a0fd4820d83f5f5b0d58558 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 6ce1a2879b4c3c6838a363323f29bb7a6455042f..9599a47df3faafb59963f5b975ebf7819d43deaf 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 f0b07ac203493b7fdf424ba42f5e4732fb35336b..cf34c09ddaad4463b57fef08211c0b8c3db46135 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 7df17e8bf81e70168ceab07832394f23ab4df3db..cecdfec8e930024ed8af43d67bc0e470ad26d462 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 cc3d6f1999f92bcc064101d603d8d8de70217993..01527982974a6786b27561108e7d56314eb59ae8 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 b4f8789d0b485fb4d0fbe6b7e6d202dfeffef17a..aea495e08d357a003efde6606e5fa4c98f1150cc 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 50fb9cbd447a2eb2b521f7d6a82d6bd1cf5a9a04..6b2535ecce1053e0d42c0c56cd608ab85290ae96 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