Update Makefile to produce dependencies & objects

This commit is contained in:
John 2022-04-05 17:56:11 -05:00
parent 478778841e
commit ef916835e8
3 changed files with 40 additions and 98 deletions

2
.gitignore vendored
View File

@ -1,6 +1,8 @@
# ---> C++ # ---> C++
# Prerequisites # Prerequisites
*.d *.d
dep/
obj/
# Compiled Object files # Compiled Object files
*.slo *.slo

View File

@ -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++ CC = g++
CFLAGS = -Iinc -pthread -lrt CFLAGS = -MMD -I$(IPATH) -pthread -lrt
VPATH = src
OBJECTS := %.o list.o producer.o transformer.o consumer.o # list of object files
EXECUTE := main.out #test.out 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: clean:
rm $(EXECUTE) -rm $(TARGET)
-rm -r dep obj
$(DPATH) $(OPATH):
mkdir -p $@
# Make the executable(s)
%.out: $(OBJECTS) %.out: $(OBJECTS)
$(CC) $(CFLAGS) -o $@ $^ $(CC) $(CFLAGS) -o $@ $^
%.o: %.cpp # Make the object and dependency files
$(CC) $(CFLAGS) -c $< $(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))

View File

@ -1,89 +0,0 @@
#include <semaphore.h>
#include <stdint.h>
#include <stdio.h>
#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;
}
*/