summaryrefslogtreecommitdiff
path: root/openmp/Makefile
diff options
context:
space:
mode:
Diffstat (limited to 'openmp/Makefile')
-rw-r--r--openmp/Makefile57
1 files changed, 57 insertions, 0 deletions
diff --git a/openmp/Makefile b/openmp/Makefile
new file mode 100644
index 0000000..8fefe22
--- /dev/null
+++ b/openmp/Makefile
@@ -0,0 +1,57 @@
+# This is some Makefile I've been using for projects for a while and can't find
+# where I originally got it
+
+CC ?= gcc
+
+SRC_PATH = src
+BUILD_PATH = build
+BIN_PATH = $(BUILD_PATH)/bin
+
+BIN_NAME = gol
+
+SRC_EXT = c
+
+SOURCES = $(shell find $(SRC_PATH) -name '*.$(SRC_EXT)' | sort -k 1nr | cut -f2-)
+OBJECTS = $(SOURCES:$(SRC_PATH)/%.$(SRC_EXT)=$(BUILD_PATH)/%.o)
+DEPS = $(OBJECTS:.o=.d)
+
+COMPILE_FLAGS = -Wall -g -fopenmp -lm -std=c99
+INCLUDES = -I include/
+LIBS = -fopenmp -lm
+
+.PHONY: default_target
+default_target: release
+
+.PHONY: release
+release: dirs
+ @$(MAKE) all
+
+.PHONY: dirs
+dirs:
+ @echo "Creating directories"
+ @mkdir -p $(dir $(OBJECTS))
+ @mkdir -p $(BIN_PATH)
+
+.PHONY: clean
+clean:
+ @echo "Deleting $(BIN_NAME) symlink"
+ @$(RM) $(BIN_NAME)
+ @echo "Deleting directories"
+ @$(RM) -r $(BUILD_PATH)
+ @$(RM) -r $(BIN_PATH)
+
+.PHONY: all
+all: $(BIN_PATH)/$(BIN_NAME)
+ @echo "Making symlink: $(BIN_NAME) -> $<"
+ @$(RM) $(BIN_NAME)
+ @ln -s $(BIN_PATH)/$(BIN_NAME) $(BIN_NAME)
+
+$(BIN_PATH)/$(BIN_NAME): $(OBJECTS)
+ @echo "Linking: $@"
+ $(CC) $(OBJECTS) -o $@ ${LIBS}
+
+-include $(DEPS)
+
+$(BUILD_PATH)/%.o: $(SRC_PATH)/%.$(SRC_EXT)
+ @echo "Compiling: $< -> $@"
+ $(CC) $(COMPILE_FLAGS) $(INCLUDES) -MP -MMD -c $< -o $@