我使用的是一般的makefile,如下所示:
public GroupChatFragment(){}
String[] names;
String[] presence;
String[] available;
String[] images;
@Override
protected void initView(LayoutInflater inflater) {
super.initView(inflater);
Resources resources = getResources();
names = resources.getStringArray(R.array.group_names);
presence = resources.getStringArray(R.array.users_presence);
available = resources.getStringArray(R.array.users_available);
images = resources.getStringArray(R.array.group_images);
}
@Override
protected void addDataToAdapter(SectionedRecyclerAdapter adapter) {
for (char alphabet = 'A'; alphabet <= 'Z'; alphabet++) {
ArrayList<Group> groups = getHeadersWithLetter(alphabet);
if (groups.size() > 0) {
adapter.addSection(new GroupChatSection(String.valueOf(alphabet), groups));
}
}
}
private ArrayList<Group> getHeadersWithLetter(char letter) {
ArrayList<Group> groupArrayList = new ArrayList<>();
for (String contact : names) {
if (contact.charAt(0) == letter) {
Group group = new Group();
group.setGroupName(contact);
for (int i = 0; i < 18; i++){
group.setAvailableUsers(available[i]);
group.setGroupImage(images[i]);
group.setNumUsers(presence[i]);
}
groupArrayList.add(group);
}
Collections.sort(groupArrayList, new Comparator<Group>() {
@Override
public int compare(final Group object1, final Group object2) {
return object1.getGroupName().compareTo(object2.getGroupName());
}
});
}
return groupArrayList;
}
目录结构如下所有 .cpp文件包含在目录src /中,相应的头文件( .h)文件存在于目录include /中。现在我想添加PETSc库。我该怎么做?
答案 0 :(得分:0)
我明白了。如果有人在将来遇到困难,我会发布涉及PETSc的项目的通用Makefile。
include ${PETSC_DIR}/lib/petsc/conf/variables
include ${PETSC_DIR}/lib/petsc/conf/rules
# Determine the platform
UNAME_S := $(shell uname -s)
# CC
CC := ${PETSC_DIR}/${PETSC_ARCH}/bin/mpicxx -Wall -Wwrite-strings -Wno-strict-aliasing -Wno-unknown-pragmas -fvisibility=hidden -g3 -std=c++11
# Folders
SRCDIR := src
BUILDDIR := build
TARGETDIR := bin
# Targets
EXECUTABLE := dg_petsc
TARGET := $(TARGETDIR)/$(EXECUTABLE)
# Final Paths
INSTALLBINDIR := /usr/local/bin
# Code Lists
SRCEXT := cpp
SOURCES := $(shell find $(SRCDIR) -type f -name *.$(SRCEXT))
OBJECTS := $(patsubst $(SRCDIR)/%,$(BUILDDIR)/%,$(SOURCES:.$(SRCEXT)=.o))
# Folder Lists
# Note: Intentionally excludes the root of the include folder so the lists are clean
INCDIRS := $(shell find includes/**/* -name '*.h' -exec dirname {} \; | sort | uniq)
INCLIST := $(patsubst includes/%,-I include/%,$(INCDIRS))
BUILDLIST := $(patsubst includes/%,$(BUILDDIR)/%,$(INCDIRS))
# Shared Compiler Flags
CFLAGS := -c
INC := -I include $(INCLIST) -I /usr/local/include -I ${PETSC_DIR}/include -I ${PETSC_DIR}/${PETSC_ARCH}/include
LIB := -L /usr/local/lib ${PETSC_SYS_LIB}
# Platform Specific Compiler Flags
CFLAGS += -std=c++11
$(TARGET): $(OBJECTS)
@mkdir -p $(TARGETDIR)
@echo "Linking..."
@echo " Linking $(TARGET)"; $(CC) $^ -o $(TARGET) $(LIB)
$(BUILDDIR)/%.o: $(SRCDIR)/%.$(SRCEXT)
@mkdir -p $(BUILDLIST)
@echo "Compiling $<..."; $(CC) $(CFLAGS) $(INC) -c -o $@ $<
clean_project:
@echo "Cleaning $(TARGET)..."; $(RM) -r $(BUILDDIR) $(TARGET)
install:
@echo "Installing $(EXECUTABLE)..."; cp $(TARGET) $(INSTALLBINDIR)
distclean:
@echo "Removing $(EXECUTABLE)"; rm $(INSTALLBINDIR)/$(EXECUTABLE)
.PHONY: clean