diff --git a/.gitignore b/.gitignore index 39fa3a9..ff18145 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,8 @@ # ---> C++ # Prerequisites *.d +dep/ +obj/ # Compiled Object files *.slo diff --git a/Makefile b/Makefile index 5fb4ec5..9de0d73 100644 --- a/Makefile +++ b/Makefile @@ -1,19 +1,48 @@ +# Executable +TARGET := main.out +# Paths to source, dependency, object files +SPATH = src +IPATH = inc +DPATH = dep +OPATH = obj + +VPATH = $(SPATH) $(OPATH) $(IPATH) $(DPATH) + +# compiler and compiler flags CC = g++ -CFLAGS = -Iinc -pthread -lrt -VPATH = src +CFLAGS = -MMD -I$(IPATH) -pthread -lrt -OBJECTS := %.o list.o producer.o transformer.o consumer.o -EXECUTE := main.out #test.out +# list of object files +SOURCES = $(wildcard $(SPATH)/*.cpp) +OBJECTS = $(addprefix $(OPATH)/,$(notdir $(SOURCES:.cpp=.o))) -.PHONY: all clean +.PHONY: all clean dump -all: $(EXECUTE) +all: $(DPATH) $(OPATH) $(TARGET) + +dump: + @echo SOURCES: $(SOURCES) + @echo OBJECTS: $(OBJECTS) + @echo TARGET: $(TARGET) + @echo VPATH: $(VPATH) clean: - rm $(EXECUTE) + -rm $(TARGET) + -rm -r dep obj +$(DPATH) $(OPATH): + mkdir -p $@ + +# Make the executable(s) %.out: $(OBJECTS) $(CC) $(CFLAGS) -o $@ $^ -%.o: %.cpp - $(CC) $(CFLAGS) -c $< +# Make the object and dependency files +$(OPATH)/%.o $(DPATH)/%.d: $(SPATH)/%.cpp + $(CC) $(CFLAGS) -MF $(DPATH)/$(@F:.o=.d) -o $@ -c $< + +# Don't delete object files: +.PRECIOUS: $(OPATH)/%.o $(DPATH)/%.d + +# use dependencies when rebuilding +-include $(addprefix $(DPATH)/,$(wildcard *.d)) diff --git a/src/test.cpp b/src/test.cpp deleted file mode 100644 index 7f32713..0000000 --- a/src/test.cpp +++ /dev/null @@ -1,89 +0,0 @@ -#include -#include -#include -#include "list.hpp" -#include "globals.hpp" -#include "producer.hpp" -#include "consumer.hpp" -#include "transformer.hpp" - -// Create all of memory -block memory[N] = {0}; -// create the three lists -list lists[3] = {0}; -list *freelist = &lists[0], - *list1 = &lists[1], - *list2 = &lists[2]; - -// count semaphores -sem_t sem_freelist, sem_list1, sem_list2; -// binary semaphores -sem_t mut_freelist, mut_list1, mut_list2; - -void producer_test(); -void transfer_test(); -void consumer_test(); - -int main(int argc, char *argv[]) { - list_init(freelist, memory, N); - list_print(freelist); - //producer_test(); - //transfer_test(); - //consumer_test(); -} - -void producer_test() { - printf("Starting producer_test:\n");\ - producer(NULL); - list_print(freelist); - list_print(list1); - list_print(list2); - printf("Ending producer_test\n"); -} - -void transfer_test() { - printf("Starting transfer_test:\n"); - transformer(NULL); - list_print(freelist); - list_print(list1); - list_print(list2); - printf("Ending transfer_test\n"); -} - -void consumer_test() { - printf("Starting consumer_test:\n"); - consumer(NULL); - list_print(freelist); - list_print(list1); - list_print(list2); - printf("Ending consumer_test\n"); -} - -/* -int movement_test () { - - // Create all of memory - block memory[N] = {0}; - // create the three lists - list freelist = {0}, list1 = {0}; - // initialize the freelist - list_init(&freelist, memory, N); - - // print the lists - std::printf("Lists:\n"); - list_print(&freelist); - list_print(&list1); - - // move a block - block *b; - while (b = list_unlink(&freelist)) - { - list_link(&list1, b); - } - // print the lists again (should be reversed order) - std::printf("Lists, again:\n"); - list_print(&freelist); - list_print(&list1); - return 1; -} -*/ \ No newline at end of file