Skip to content

Commit

Permalink
[pp->ttgg] Start refactoring the Makefiles.
Browse files Browse the repository at this point in the history
- Separate internal from external flags for every language.
  • Loading branch information
hageboeck committed Aug 17, 2023
1 parent db953e1 commit 79267cc
Show file tree
Hide file tree
Showing 5 changed files with 187 additions and 216 deletions.
68 changes: 37 additions & 31 deletions epochX/cudacpp/pp_tt012j.mad/Source/make_opts
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,6 @@ DEFAULT_F2PY_COMPILER=f2py3
BIASLIBDIR=../../../lib/
BIASLIBRARY=libbias.$(libext)

# Rest of the makefile
ifeq ($(origin FFLAGS),undefined)
FFLAGS= -w -fPIC
#FFLAGS+= -g -fbounds-check -ffpe-trap=invalid,zero,overflow,underflow,denormal -Wall -fimplicit-none
endif

FFLAGS += $(GLOBAL_FLAG)

# REMOVE MACFLAG IF NOT ON MAC OR FOR F2PY
UNAME := $(shell uname -s)
Expand All @@ -35,14 +28,38 @@ MACFLAG=
endif
endif

############################################################
# Default compiler flags
# To change optimisation level, override these as follows:
# make CXXFLAGS="-O0 -g"
# or export them as environment variables
# For debugging Fortran, on could e.g. use:
# FCFLAGS="-g -fbounds-check -ffpe-trap=invalid,zero,overflow,underflow,denormal -Wall -fimplicit-none"
############################################################

ifeq ($(origin CXXFLAGS),undefined)
CXXFLAGS= -O $(STDLIB_FLAG) $(MACFLAG)
FCFLAGS ?= -O3 -ffast-math -fbounds-check
CXXFLAGS ?= -O3 -ffast-math $(STDLIB_FLAG) $(MACFLAG)
NVCCFLAGS ?= -O3 -ffast-math -use_fast_math -lineinfo
LDFLAGS ?= $(STDLIB) $(MACFLAG)

ifneq ($(FFLAGS),)
# Madgraph used to use FFLAGS, so the user probably tries to change the flags specifically for madgraph:
FCFLAGS = $(FFLAGS)
endif

ifeq ($(origin CFLAGS),undefined)
CFLAGS= -O $(STDLIB_FLAG) $(MACFLAG)
# Madgraph-specific flags:
WARNFLAGS = -Wall -Wshadow -Wextra
ifeq (,$(findstring -std=,$(CXXFLAGS)))
CXXSTANDARD= -std=c++17
endif
INTERNAL_FCFLAGS += -fPIC -w
INTERNAL_CXXFLAGS += -fPIC $(CXXSTANDARD) $(WARNFLAGS)
INTERNAL_NVCCFLAGS += -fPIC $(CXXSTANDARD) --forward-unknown-to-host-compiler $(WARNFLAGS)

ALL_FCFLAGS = $(INTERNAL_FCFLAGS) $(FCFLAGS)
ALL_CXXFLAGS = $(CPPFLAGS) $(INTERNAL_CXXFLAGS) $(CXXFLAGS)
ALL_NVCCFLAGS = $(CPPFLAGS) $(INTERNAL_NVCCFLAGS) $(NVCCFLAGS)
ALL_LDFLAGS = $(INTERNAL_LDFLAGS) $(LDFLAGS)

# Set FC unless it's defined by an environment variable
ifeq ($(origin FC),default)
Expand All @@ -54,21 +71,18 @@ endif

# Increase the number of allowed charcters in a Fortran line
ifeq ($(FC), ftn)
FFLAGS+= -extend-source # for ifort type of compiler
INTERNAL_FCFLAGS += -extend-source # for ifort type of compiler
else
VERS="$(shell $(FC) --version | grep ifort -i)"
ifeq ($(VERS), "")
FFLAGS+= -ffixed-line-length-132
INTERNAL_FCFLAGS += -ffixed-line-length-132
else
FFLAGS+= -extend-source # for ifort type of compiler
INTERNAL_FCFLAGS += -extend-source # for ifort type of compiler
endif
endif


UNAME := $(shell uname -s)
ifeq ($(origin LDFLAGS), undefined)
LDFLAGS=$(STDLIB) $(MACFLAG)
endif

# Options: dynamic, lhapdf
# Option dynamic
Expand All @@ -82,17 +96,17 @@ endif
ifdef dynamic
ifeq ($(UNAME), Darwin)
libext=dylib
FFLAGS+= -fno-common
LDFLAGS += -bundle
INTERNAL_FCFLAGS += -fno-common
INTERNAL_LDFLAGS += -bundle
define CREATELIB
$(FC) -dynamiclib -undefined dynamic_lookup -o $(1) $(2)
endef
else
libext=so
FFLAGS+= -fPIC
LDFLAGS += -shared
INTERNAL_FCFLAGS += -fPIC
INTERNAL_LDFLAGS += -shared
define CREATELIB
$(FC) $(FFLAGS) $(LDFLAGS) -o $(1) $(2)
$(FC) $(ALL_FCFLAGS) $(ALL_LDFLAGS) -o $(1) $(2)
endef
endif
else
Expand All @@ -106,17 +120,9 @@ endif
# Option lhapdf

ifneq ($(lhapdf),)
CXXFLAGS += $(shell $(lhapdf) --cppflags)
INTERNAL_CXXFLAGS += $(shell $(lhapdf) --cppflags)
alfas_functions=alfas_functions_lhapdf
llhapdf+= $(shell $(lhapdf) --cflags --libs) -lLHAPDF
# check if we need to activate c++11 (for lhapdf6.2)
ifeq ($(origin CXX),default)
ifeq ($lhapdfversion$lhapdfsubversion,62)
CXX=$(DEFAULT_CPP_COMPILER) -std=c++11
else
CXX=$(DEFAULT_CPP_COMPILER)
endif
endif
else
alfas_functions=alfas_functions
llhapdf=
Expand Down
33 changes: 17 additions & 16 deletions epochX/cudacpp/pp_tt012j.mad/Source/makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ include make_opts

# Source files

PROCESS= hfill.o matrix.o myamp.o
DSAMPLE = dsample.o ranmar.o DiscreteSampler.o StringCast.o
PROCESS = hfill.o matrix.o myamp.o
DSAMPLE = dsample.o ranmar.o DiscreteSampler.o StringCast.o
HBOOK = hfill.o hcurve.o hbook1.o hbook2.o
GENERIC = $(alfas_functions).o transpole.o invarients.o hfill.o pawgraphs.o ran1.o \
rw_events.o rw_routines.o kin_functions.o open_file.o basecode.o setrun.o \
Expand All @@ -22,7 +22,7 @@ GENSUDGRID = gensudgrid.o is-sud.o setrun_gen.o rw_routines.o open_file.o

# Locally compiled libraries

LIBRARIES=$(LIBDIR)libdsample.$(libext) $(LIBDIR)libgeneric.$(libext)
LIBRARIES=$(LIBDIR)libdsample.$(libext) $(LIBDIR)libgeneric.$(libext)

# Binaries

Expand All @@ -32,43 +32,44 @@ BINARIES = $(BINDIR)gen_ximprove $(BINDIR)gensudgrid $(BINDIR)combine_runs

all: $(LIBRARIES) $(LIBDIR)libdhelas.$(libext) $(LIBDIR)libpdf.$(libext) $(LIBDIR)libgammaUPC.$(libext) $(LIBDIR)libmodel.$(libext) $(LIBDIR)libcernlib.$(libext) $(LIBDIR)libbias.$(libext)

%.o: %.f *.inc
$(FC) -I. $(ALL_FCFLAGS) -c $< -o $@

# Libraries

$(LIBDIR)libdsample.$(libext): $(DSAMPLE)
$(call CREATELIB, $@, $^)
$(LIBDIR)libgeneric.$(libext): $(GENERIC)
$(call CREATELIB, $@, $^)
$(LIBDIR)libdhelas.$(libext): DHELAS
cd DHELAS; make; cd ..
$(MAKE) -C $< FFLAGS="$(ALL_FCFLAGS)" FCFLAGS="$(ALL_FCFLAGS)"
$(LIBDIR)libpdf.$(libext): PDF make_opts
cd PDF; make; cd ..
$(MAKE) -C $< FFLAGS="$(ALL_FCFLAGS)" FCFLAGS="$(ALL_FCFLAGS)"
ifneq (,$(filter edff chff, $(pdlabel1) $(pdlabel2)))
$(LIBDIR)libgammaUPC.$(libext): PDF/gammaUPC
cd PDF/gammaUPC; make ; cd ../../
$(MAKE) -C $< FFLAGS="$(ALL_FCFLAGS)" FCFLAGS="$(ALL_FCFLAGS)"
else
$(LIBDIR)libgammaUPC.$(libext): PDF/gammaUPC
cd PDF/gammaUPC; make -f makefile_dummy; cd ../../
endif
$(MAKE) -C $< -f makefile_dummy FFLAGS="$(ALL_FCFLAGS)" FCFLAGS="$(ALL_FCFLAGS)"
endif
$(LIBDIR)libcernlib.$(libext): CERNLIB
cd CERNLIB; make; cd ..
$(MAKE) -C $< FFLAGS="$(ALL_FCFLAGS)" FCFLAGS="$(ALL_FCFLAGS)"
# The bias library is here the dummy by default; compilation of other ones specified in the run_card will be done by MG5aMC directly.
$(LIBDIR)libbias.$(libext): BIAS/dummy
cd BIAS/dummy; make; cd ../../
$(MAKE) -C $< FFLAGS="$(ALL_FCFLAGS)" FCFLAGS="$(ALL_FCFLAGS)"

$(LIBDIR)libmodel.$(libext): MODEL param_card.inc
cd MODEL; make
$(MAKE) -C $< FFLAGS="$(ALL_FCFLAGS)" FCFLAGS="$(ALL_FCFLAGS)"
param_card.inc: ../Cards/param_card.dat
../bin/madevent treatcards param




$(BINDIR)gen_ximprove: gen_ximprove.o ranmar.o rw_routines.o open_file.o
$(FC) $(LDFLAGS) -o $@ $^
#$(BINDIR)combine_events: $(COMBINE) $(LIBDIR)libmodel.$(libext) $(LIBDIR)libpdf.$(libext) $(LIBDIR)libgammaUPC.$(libext) run_card.inc $(LIBDIR)libbias.$(libext)
# $(FC) -o $@ $(COMBINE) -L$(LIBDIR) -lmodel -lpdf -lgammaUPC $(llhapdf) $(LDFLAGS) -lbias
$(BINDIR)gen_ximprove: gen_ximprove.o ranmar.o rw_routines.o open_file.o
$(FC) $(ALL_LDFLAGS) -o $@ $^
$(BINDIR)gensudgrid: $(GENSUDGRID) $(LIBDIR)libpdf.$(libext) $(LIBDIR)libgammaUPC.$(libext) $(LIBDIR)libcernlib.$(libext)
$(FC) -o $@ $(GENSUDGRID) -L$(LIBDIR) -lmodel -lpdf -lgammaUPC -lcernlib $(llhapdf) $(LDFLAGS)
$(FC) -o $@ $(GENSUDGRID) -L$(LIBDIR) -lmodel -lpdf -lgammaUPC -lcernlib $(llhapdf) $(ALL_LDFLAGS)

# Dependencies

Expand Down
Loading

0 comments on commit 79267cc

Please sign in to comment.