# | # o---------------------------------------------------------------------o # | # | MAD makefile - config # | # o---------------------------------------------------------------------o # | # | Methodical Accelerator Design # | # | Copyright (c) 2011+ CERN, mad@cern.ch # | # | For more information, see http://cern.ch/mad # | # o---------------------------------------------------------------------o # | # | $Id$ # | # detect operating system # OSTYPE = Linux, Darwin, Cygwin, Windows (or empty) # OSARCH = i386, i686, x86, x86_64, amd64, ia64 (or empty) ifeq ($(windir),) OSTYPE := $(shell uname -s) OSARCH := $(shell uname -m) OSTYPE := $(patsubst CYGWIN%,Cygwin,$(OSTYPE)) else OSTYPE := $(findstring Windows,$(shell ver)) OSARCH := $(if $(PROCESSOR_ARCHITEW6432),$(PROCESSOR_ARCHITEW6432) \ ,$(PROCESSOR_ARCHITECTURE)) endif # some useful command and variables ifeq ($(OSTYPE),Windows) / := $(strip \ ) LS := dir /L /B CP := copy /Y MV := move RM := del /f RMDIR := rmdir /s /q FIND := find_cmd_not_found CAT := more HOME := $(HOMEDRIVE)$(HOMEPATH) else / := / LS := ls -1 CP := cp -f MV := mv -f RM := rm -f RMDIR := rm -fr FIND := find CAT := cat endif # set command echo (SHOW=yes -> trace commands & remove echo) ifneq ($(OSTYPE),Windows) _ := $(if $(call eq,$(SHOW),yes),,@) E := $(if $(call eq,$(SHOW),yes),@ \#,@ echo) else _ := $(if $(call eq,$(SHOW),yes),,@) E := $(if $(call eq,$(SHOW),yes),@ rem,@ echo) endif # backward slash manip ifeq ($(OSTYPE),Windows) / := \$(EMPTY) ; := & f1bs = $(subst /,\,$1) f2bs = $(subst /,\\,$1) s1bs = $(subst $(SPACE),\ ,$1) else / := / ; := ; f1bs = $1 f2bs = $1 s1bs = $(subst $(SPACE),\ ,$1) endif # detect ARCH if requested ifeq ($(ARCH),detect) ARCH := $(if $(findstring 64,$(OSARCH)),64,32) endif # detect TESTS if requested or provided ifeq ($(TESTS),detect) override TESTS := $(notdir $(wildcard tests/test-*)) endif # default optimization level ifeq ($(NOPT),) NOPT := 3 endif # destination directory ifeq ($(DESTDIR),) DESTDIR := build$/ else override DESTDIR := $(subst $/$/,$/,$(strip $(DESTDIR))$/) endif # build directory ifeq ($(APPENDLD),yes) OBJDIR = $(DESTDIR)$(OSTYPE)$(ARCH)_$(LDNAME) else OBJDIR := $(DESTDIR)$(OSTYPE)$(ARCH) endif # project's name PRJNAME := $(PROJECT)$(ARCH) # list of build targets BUILDGOALS := $(PROJECT) # default target (immediate!) .DEFAULT_GOAL := $(PROJECT) # add default target to make commands ifeq ($(MAKECMDGOALS),) MAKECMDGOALS := $(.DEFAULT_GOAL) endif # shortcut for Intel compilers familly ifeq ($(Intel),yes) ifeq ($(OSTYPE),Windows) CC := $(if $(CC),icl,) CXX := $(if $(CXX),icl,) else CC := $(if $(CC),icc,) CXX := $(if $(CXX),icc,) endif FC := $(if $(FC),ifort,) endif # shortcut for GNU compilers familly ifeq ($(GNU),yes) CC := $(if $(CC),gcc,) CXX := $(if $(CXX),g++,) FC := $(if $(FC),gfortran,) endif # cleanup default make settings ifeq ($(origin CC),default) CC := endif ifeq ($(origin CXX),default) CXX := endif ifeq ($(origin FC),default) FC := endif ifeq ($(origin LD),default) LD := endif ifeq ($(origin AR),default) AR := endif ifeq ($(origin ND),default) ND := endif # standard included settings ifndef CCNAME CCNAME := $(CC) endif ifndef CXXNAME CXXNAME := $(CXX) endif ifndef FCNAME FCNAME := $(FC) endif ifndef LDNAME LDNAME := $(LD) endif ifndef ARNAME ARNAME := $(AR) endif ifndef NDNAME NDNAME := $(ND) endif # standard included makefiles ifndef FILE_PRE FILE_PRE := Makefile_pre # user's preprocessing extra stuff endif ifndef FILE_VER FILE_VER := VERSION # setup project VERSION and VERSION_DATE endif ifndef FILE_CPP FILE_CPP := Makefile_cpp # setup project specific CPPFLAGS defines endif ifndef FILE_C FILE_C := Makefile_c # setup project CC_SRC and CC_HDR endif ifndef FILE_CXX FILE_CXX := Makefile_cxx # setup project CXX_SRC and CXX_HDR endif ifndef FILE_F90 FILE_F90 := Makefile_f90 # setup project FC_SRC endif ifndef FILE_LIB FILE_LIB := Makefile_lib # setup project LIBS paths and libs endif ifndef FILE_SYS FILE_SYS := Makefile_sys # setup project System specific stuffs endif ifndef FILE_TEST FILE_TEST := Makefile_test # setup project tests endif ifndef FILE_POST FILE_POST := Makefile_post # user's postprocessing extra stuff endif # standard translation settings CC_tr = $(strip $1) CXX_tr = $(strip $1) FC_tr = $(strip $1) LD_tr = $(strip $1) AR_tr = $(strip $1) ND_tr = $(strip $1) # standard build defines ifeq ($(origin CPPFLAGS),default) CPPFLAGS = endif ifeq ($(DEBUG),yes) CPPFLAGS += -D_DEBUG endif ifeq ($(PROFILE),yes) CPPFLAGS += -D_PROFILE endif ifeq ($(STATIC),yes) CPPFLAGS += -D_STATIC endif ifeq ($(SHARED),yes) CPPFLAGS += -D_SHARED endif ifeq ($(PLUGIN),yes) CPPFLAGS += -D_PLUGIN endif # gnu libs directory (if needed, lazy) GNULIBDIR = $(dir $(shell $(CC) $(CFLAGS) -print-file-name=libgcc.a)) # clear suffixes (avoid misbehavior) .SUFFIXES: # clear search path (avoid misbehavior) VPATH = vpath # end of makefile