-
Notifications
You must be signed in to change notification settings - Fork 0
/
makefile
161 lines (118 loc) · 4.93 KB
/
makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
# -*- mode: makefile -*-
# This SAMPLE GNU Makefile can be used to compile PETSc applications
# It relies on pkg_config tool (see $PETSC_DIR/share/petsc/Makefile.basic.user if you cannot use pkg_config)
# Copy this file to your source directory as "Makefile" and MODIFY AS NEEDED (see the comment above CFLAGS below).
#
# You must set the environmental variable(s) PETSC_DIR (and PETSC_ARCH if PETSc was not configured with the --prefix option)
# See also share/petsc/Makefile.basic.user for a makefile that does not require pkg_config
#
# For example - a single source file (ex1.c or ex1.F90) can be compiled with:
#
# make ex1
#
# You do not need to edit this makefile at all.
#
# For a multi-file case, suppose you have the source files a.c, b.c, and c.cxx
# This can be built by uncommenting the following two lines.
#
# app : a.o b.o c.o
# $(LINK.C) -o $@ $^ $(LDLIBS)
#
# When linking in a multi-files with Fortran source files a.F90, b.c, and c.cxx
# You may need to use
#
# app : a.o b.o c.o
# $(LINK.F) -o $@ $^ $(LDLIBS)
# If the file c.cxx needs to link with a C++ standard library -lstdc++ , then
# you'll need to add it explicitly. It can go in the rule above or be added to
# a target-specific variable by uncommenting the line below.
#
# app : LDLIBS += -lstdc++
#
# The following variable must either be a path to petsc.pc or just "petsc" if petsc.pc
# has been installed to a system location or can be found in PKG_CONFIG_PATH.
petsc.pc := $(PETSC_DIR)/$(PETSC_ARCH)/lib/pkgconfig/petsc.pc
# Additional libraries that support pkg-config can be added to the list of PACKAGES below.
PACKAGES := $(petsc.pc)
# The following variables may be removed if desired
# They pass all the flags that were used to compile PETSc to compile your code, they are generally not needed
CFLAGS_OTHER := $(shell pkg-config --cflags-only-other $(PACKAGES))
CFLAGS := $(shell pkg-config --variable=cflags_extra $(PACKAGES)) $(CFLAGS_OTHER)
CXXFLAGS := $(shell pkg-config --variable=cxxflags_extra $(PACKAGES)) $(CFLAGS_OTHER)
FFLAGS := $(shell pkg-config --variable=fflags_extra $(PACKAGES))
CPPFLAGS := $(shell pkg-config --cflags-only-I $(PACKAGES))
CC := $(shell pkg-config --variable=ccompiler $(PACKAGES))
CXX := $(shell pkg-config --variable=cxxcompiler $(PACKAGES))
FC := $(shell pkg-config --variable=fcompiler $(PACKAGES))
LDFLAGS := $(shell pkg-config --libs-only-L --libs-only-other $(PACKAGES))
LDFLAGS += $(patsubst -L%, $(shell pkg-config --variable=ldflag_rpath $(PACKAGES))%, $(shell pkg-config --libs-only-L $(PACKAGES)))
LDLIBS := $(shell pkg-config --libs-only-l $(PACKAGES)) -lm
CUDAC := $(shell pkg-config --variable=cudacompiler $(PACKAGES))
CUDAC_FLAGS := $(shell pkg-config --variable=cudaflags_extra $(PACKAGES))
CUDA_LIB := $(shell pkg-config --variable=cudalib $(PACKAGES))
CUDA_INCLUDE := $(shell pkg-config --variable=cudainclude $(PACKAGES))
print:
@echo CC=$(CC)
@echo CXX=$(CXX)
@echo FC=$(FC)
@echo CFLAGS=$(CFLAGS)
@echo CXXFLAGS=$(CXXFLAGS)
@echo FFLAGS=$(FFLAGS)
@echo CPPFLAGS=$(CPPFLAGS)
@echo LDFLAGS=$(LDFLAGS)
@echo LDLIBS=$(LDLIBS)
@echo CUDAC=$(CUDAC)
@echo CUDAC_FLAGS=$(CUDAC_FLAGS)
@echo CUDA_LIB=$(CUDA_LIB)
@echo CUDA_INCLUDE=$(CUDA_INCLUDE)
# Many suffixes are covered by implicit rules, but you may need to write custom rules
# such as these if you use suffixes that do not have implicit rules.
# https://www.gnu.org/software/make/manual/html_node/Catalogue-of-Rules.html#Catalogue-of-Rules
% : %.F90
$(LINK.F) -o $@ $^ $(LDLIBS)
%.o: %.F90
$(COMPILE.F) $(OUTPUT_OPTION) $<
% : %.cxx
$(LINK.cc) -o $@ $^ $(LDLIBS)
%.o: %.cxx
$(COMPILE.cc) $(OUTPUT_OPTION) $<
%.o : %.cu
$(CUDAC) -c $(CPPFLAGS) $(CUDAC_FLAGS) $(CUDA_INCLUDE) -o $@ $<
# %: %.c
# $(LINK.c) $^ $(LOADLIBES) $(LDLIBS) -o $@
.PHONY: all clean build help
.DEFAULT_GOAL:= all
# List the source directories you want to compile from
SRC_DIRS := src/synchronous-multisplitting src/synchronous-multisplitting-synchronous-minimization src/asynchronous-multisplitting src/asynchronous-multisplitting-asynchronous-minimization
# Define the directory where binaries will be stored
BIN_DIR := bin
# List of source files in chosen directories
SOURCES := $(wildcard $(foreach dir, $(SRC_DIRS), $(dir)/*.c))
# Corresponding binaries in the bin directory
#BINARIES := $(patsubst src/%.c, $(BIN_DIR)/% , $(SOURCES))
BINARIES := $(patsubst src/%.c, $(BIN_DIR)/%, $(SOURCES))
# Default rule to build all binaries
all: $(BINARIES)
@echo Build finish!
build: all
# Rule to compile each binary
$(BIN_DIR)/%: src/%.c | $(BIN_DIR)
@$(LINK.c) $^ $(LOADLIBES) $(LDLIBS) -o $(BIN_DIR)/$(notdir $@)
# Ensure the bin directory exists
$(BIN_DIR):
@mkdir -p $(BIN_DIR)
run:
@echo Not implemented yet...
@echo Future feature
check:
@echo Not implemented yet...
@echo Future feature
docs:
@echo Not implemented yet...
@echo Future feature
rebuild: clean all
# Clean up all binaries
clean:
@echo Removing all build files from bin...
@rm -rf $(BIN_DIR)/*
@echo Finish!