# LAMMPS shared library multiple-machine Makefile

SHELL = /bin/sh

# Subtargets for makefile auto
SUBTARGET = $@
OPTIONSPOSTFIX =
ifneq ($(origin postfix), undefined)
    ifneq (${postfix}, )
        ifneq (,$(filter $(MAKECMDGOALS), auto clean-auto))
            ifeq (${postfix}, default)
                $(error A postfix value of "default" is not allowed)
            endif
            SUBTARGET = $@"_"${postfix}
            OPTIONSPOSTFIX = _${postfix}
        endif
    endif
endif

# Definitions

ROOT =	lmp
EXE =	lib$(ROOT)_$(SUBTARGET).so

SRC := $(filter-out main.cpp,$(wildcard *cpp))

INC := $(wildcard *.h)

OBJ =	$(SRC:.cpp=.o)

# Targets

help:
	@echo 'Type "make target" where target is one of:'
	@echo ''
	@files="`ls MAKE/Makefile.*`"; \
	for file in $$files; do head -1 $$file; done

clean:
	rm -rf Obj_*

.DEFAULT:
	@test -f MAKE/Makefile.$@
	@if [ ! -d Obj_$(SUBTARGET) ]; then mkdir Obj_$(SUBTARGET); fi
	@cp -p $(SRC) $(INC) Obj_$(SUBTARGET)
	@cp MAKE/Makefile.$@ Obj_$(SUBTARGET)/Makefile
	@if [ ! -e Makefile.package ]; \
	  then cp Makefile.package.empty Makefile.package; fi
	@if [ ! -e Makefile.package.settings ]; \
	  then cp Makefile.package.settings.empty Makefile.package.settings; fi
	@cp Makefile.package Makefile.package.settings Obj_$(SUBTARGET)
	@cd Obj_$(SUBTARGET); \
	$(MAKE) $(MFLAGS) "OBJ = $(OBJ)" \
          "INC = $(INC)" "EXE = ../$(EXE)" shlib
	@if [ -d Obj_$(SUBTARGET) ]; then cd Obj_$(SUBTARGET); \
          rm -f $(SRC) $(INC) Makefile*; fi
