Skip to content

Instantly share code, notes, and snippets.

@jwpeterson
Created October 22, 2015 19:49
Show Gist options
  • Select an option

  • Save jwpeterson/24bda483b26db5a5759d to your computer and use it in GitHub Desktop.

Select an option

Save jwpeterson/24bda483b26db5a5759d to your computer and use it in GitHub Desktop.
Simple Makefile that can compile single file libmesh applications.
# This Makefile assumes you have libmesh built and installed in $LIBMESH_DIR.
# If the user has no environment variable
# called METHOD, he gets optimized mode.
ifeq (x$(METHOD),x)
METHOD := opt
endif
# installed libmesh location of libmesh-config script
libmesh_config := $(LIBMESH_DIR)/bin/libmesh-config
# Use the libmesh-config script to determine the usual make variables.
# Note: passing $METHOD along to the libmesh-config script handles the
# case where METHOD is not set and the user does
# make METHOD=dbg foo
# since in this case, METHOD is never set in the environment and thus
# never passed to libmesh-config correctly.
libmesh_CXX := $(shell METHOD=$(METHOD) $(libmesh_config) --cxx)
libmesh_INCLUDE := $(shell METHOD=$(METHOD) $(libmesh_config) --include)
libmesh_CPPFLAGS := $(shell METHOD=$(METHOD) $(libmesh_config) --cppflags)
libmesh_CXXFLAGS := $(shell METHOD=$(METHOD) $(libmesh_config) --cxxflags)
libmesh_LIBS := $(shell METHOD=$(METHOD) $(libmesh_config) --libs)
# File management variables.
srcfiles := $(wildcard *.cc)
opt_executables := $(patsubst %.cc, %-opt, $(srcfiles))
.PHONY: clean
# How to build executables. If you have a source file called foo.cc,
# type 'make foo' to build an executable from it.
%: %.cc
@echo "Compiling" $<
@$(libmesh_CXX) $(libmesh_INCLUDE) $(libmesh_CPPFLAGS) $(libmesh_CXXFLAGS) $< -o $@-$(METHOD) $(libmesh_LIBS) $(libmesh_LDFLAGS) $(EXTERNAL_FLAGS)
# File management rules.
clean:
@rm -f *~ $(opt_executables)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment