-
Notifications
You must be signed in to change notification settings - Fork 155
Build system improvements #354
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
b998b83
eb05a26
01f3873
a73ac1f
0559c8e
6858fc5
1e6e144
fe243ff
818e6b6
eab1b65
ba03da0
cb33be4
f9c6eff
aa25e7f
d412599
ea27839
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,7 +8,6 @@ | |
| # SRCS=<files> ~ list of src files, default is all .c .F .F90 files in VPATH | ||
| # VPFILE=<file> ~ file with list of dirs, used to create VPATH | ||
| # SRCFILE=<file> ~ file with list of src files, used to create SRCS | ||
| # DEPGEN=<exec> ~ dependency generator utility, default is makdep | ||
| # | ||
| # <macro defns> ~ any macro definitions found in this file or the included | ||
| # MACFILE will be over-riden by cmd-line macro definitions | ||
|
|
@@ -31,7 +30,9 @@ VPFILE := NONE | |
| VPATH := . | ||
| SRCFILE := NONE | ||
| SRCS := NONE | ||
| DEPGEN := ./makdep # an externally provided dependency generator | ||
|
|
||
| # dependency generator | ||
| DEPGEN := ./makdep | ||
|
|
||
| ifneq ($(VPATH),.) | ||
| # this variable was specified on cmd line or in an env var | ||
|
|
@@ -58,26 +59,33 @@ endif | |
| OBJS := $(addsuffix .o, $(sort $(basename $(notdir $(SRCS))))) | ||
| DEPS := $(addsuffix .d, $(sort $(basename $(notdir $(SRCS))))) | ||
| INCS := $(patsubst %,-I%, $(VPATH) ) | ||
| OBJS_DEPGEN := $(addprefix $(ICE_CASEDIR)/,$(addsuffix .c, $(notdir $(DEPGEN)))) | ||
| MODDIR:= -I. | ||
| RM := rm | ||
|
|
||
| .SUFFIXES: | ||
| .SUFFIXES: .F90 .F .c .o | ||
|
|
||
| .PHONY: all cice targets target db_files db_flags clean realclean | ||
| all: $(EXEC) | ||
|
|
||
| cice: $(EXEC) | ||
|
|
||
| #------------------------------------------------------------------------------- | ||
| # include the file that provides macro definitions required by build rules | ||
| # note: the MACFILE may not be needed for certain goals | ||
| #------------------------------------------------------------------------------- | ||
|
|
||
| ifneq ($(MAKECMDGOALS), db_files) | ||
| -include $(MACFILE) | ||
| endif | ||
| -include $(MACFILE) | ||
|
|
||
| #------------------------------------------------------------------------------- | ||
| # echo file names, paths, compile flags, etc. used during build | ||
| # echo supported targets, file names, paths, compile flags, etc. used during build | ||
| #------------------------------------------------------------------------------- | ||
|
|
||
| targets: | ||
| @echo " " | ||
| @echo "Supported Makefile Targets are: cice, makdep, depends, clean, realclean, targets, db_files, db_flags" | ||
| target: targets | ||
|
|
||
| db_files: | ||
| @echo " " | ||
| @echo "* EXEC := $(EXEC)" | ||
|
|
@@ -89,12 +97,22 @@ db_files: | |
| @echo "* SRCS := $(SRCS)" | ||
| @echo "* OBJS := $(OBJS)" | ||
| @echo "* DEPS := $(DEPS)" | ||
| @echo "* ULIBS := $(ULIBS)" | ||
| @echo "* SLIBS := $(SLIBS)" | ||
| @echo "* INCLDIR := $(INCLDIR)" | ||
| @echo "* OBJS_DEPGEN := $(OBJS_DEPGEN)" | ||
| db_flags: | ||
| @echo " " | ||
| @echo "* cpp := $(CPP) $(CPPFLAGS) $(CPPDEFS) $(INCS) $(INCLDIR)" | ||
| @echo "* cc := $(CC) -c $(CFLAGS) $(INCS) $(INCLDIR)" | ||
| @echo "* .F.o := $(FC) -c $(FFLAGS) $(FIXEDFLAGS) $(INCS) $(INCLDIR)" | ||
| @echo "* .F90.o := $(FC) -c $(FFLAGS) $(FREEFLAGS) $(INCS) $(INCLDIR)" | ||
| @echo "* $(DEPGEN) := $(SCC) $(CFLAGS_HOST)" | ||
| @echo "* %.d : %.c := $(DEPGEN) $(INCS)" | ||
| @echo "* %.d : %.F := $(DEPGEN) $(INCS)" | ||
| @echo "* %.d : %.F90 := $(DEPGEN) $(INCS)" | ||
| @echo "* %.d : %.H := $(DEPGEN) $(INCS)" | ||
| @echo "* cpp := $(CPP) $(CPPFLAGS) $(CPPDEFS) $(INCLDIR)" | ||
| @echo "* .c.o := $(CC) $(CFLAGS) $(CPPDEFS) $(INCLDIR)" | ||
| @echo "* .F.o := $(FC) -c $(FFLAGS) $(FIXEDFLAGS) $(CPPDEFS) $(INCLDIR)" | ||
| @echo "* .F90.o := $(FC) -c $(FFLAGS) $(FREEFLAGS) $(CPPDEFS) $(MODDIR) $(INCLDIR)" | ||
| @echo "* $(notdir $(EXEC)) := $(LD) $(LDFLAGS) $(ULIBS) $(SLIBS)" | ||
|
|
||
| #------------------------------------------------------------------------------- | ||
| # build rule for makdep: MACFILE, cmd-line, or env vars must provide | ||
|
|
@@ -105,7 +123,8 @@ ifndef $(CFLAGS_HOST) | |
| CFLAGS_HOST := | ||
| endif | ||
|
|
||
| $(DEPGEN): $(ICE_CASEDIR)/makdep.c | ||
| $(DEPGEN): $(OBJS_DEPGEN) | ||
| @ echo "Building makdep" | ||
| $(SCC) -o $@ $(CFLAGS_HOST) $< | ||
|
|
||
| #------------------------------------------------------------------------------- | ||
|
|
@@ -116,58 +135,62 @@ $(EXEC): $(OBJS) | |
| $(LD) -o $(EXEC) $(LDFLAGS) $(OBJS) $(ULIBS) $(SLIBS) | ||
|
|
||
| .c.o: | ||
| $(CC) $(CFLAGS) $(CPPDEFS) $(INCS) $(INCLDIR) $< | ||
| $(CC) $(CFLAGS) $(CPPDEFS) $(INCLDIR) $< | ||
|
|
||
| .F.o: | ||
| $(FC) -c $(FFLAGS) $(FIXEDFLAGS) $(CPPDEFS) $(INCS) $(INCLDIR) $< | ||
| $(FC) -c $(FFLAGS) $(FIXEDFLAGS) $(CPPDEFS) $(INCLDIR) $< | ||
|
|
||
| .F90.o: | ||
| $(FC) -c $(FFLAGS) $(FREEFLAGS) $(CPPDEFS) $(INCS) $(INCLDIR) $< | ||
|
|
||
| mostlyclean: | ||
| $(RM) -f *.f *.f90 | ||
| $(FC) -c $(FFLAGS) $(FREEFLAGS) $(CPPDEFS) $(MODDIR) $(INCLDIR) $< | ||
|
|
||
| clean: | ||
| $(RM) -f *.f *.f90 *.d *.mod *.o $(EXEC) | ||
| # $(RM) -f *.f *.f90 *.d *.$(MOD_SUFFIX) $(OBJS) | ||
| $(RM) -f *.o *.d *.mod $(EXEC) | ||
|
|
||
| realclean: | ||
| $(RM) -f *.f *.f90 *.d *.$(MOD_SUFFIX) $(OBJS) $(EXEC) | ||
| realclean: clean | ||
| $(RM) -f $(DEPGEN) | ||
|
|
||
| #------------------------------------------------------------------------------- | ||
| # Build & include dependency files | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we could also take this opportunity to clean up what is uneeded here : all our files are *.F90 or *.c so the dependency generation for *.F and *.H can be removed. .F.o:
$(FC) -c $(FFLAGS) $(FIXEDFLAGS) $(CPPDEFS) $(INCLDIR) $<
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it's OK to leave the other make rules in the Makefile for now. It could be that future development will need them. I don't think it hurts to have them there. I don't think folks actually look at the Makefile all that much. But I could be convinced otherwise. For now, I think I'll leave them as is. |
||
| #------------------------------------------------------------------------------- | ||
| # ASSUMPTIONS: | ||
| # o an externally provided dependency generator, $(DEPGEN), is available, | ||
| # o the dependency generator, $(DEPGEN), can be built, | ||
| # its cmd line syntax is compatible with the build rules below. Eg, for | ||
| # each .o file, there is a corresponding .d (dependency) file, and both | ||
| # will be dependent on the same src file, eg. foo.o foo.d : foo.F90 | ||
| # Also, the dependancy genorator's capabilities, limitations, and assumptions | ||
| # are understood & accepted. | ||
| #------------------------------------------------------------------------------- | ||
|
|
||
| %.d : %.c | ||
| depends: $(DEPS) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure the 'depends' target is needed... it's only use would be to manually recreate the dependencies by calling
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think you're right that we may not need depends. I don't think it hurts to have it. Maybe someone wants to just generate the depends without building the rest of the code?
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You are right that it does not hurt to have it. Although in that case I would mention somewhere in the documentation that the dependencies are usually automatically generated. |
||
|
|
||
| %.d : %.c $(DEPGEN) | ||
| @ echo "Building dependency for $@" | ||
| @ $(DEPGEN) -f $(INCS) $< | head -3 > $@ | ||
| %.d : %.F | ||
| %.d : %.F $(DEPGEN) | ||
| @ echo "Building dependency for $@" | ||
| @ $(DEPGEN) -f $(INCS) $< > $@ | ||
| %.d : %.F90 | ||
| %.d : %.F90 $(DEPGEN) | ||
| @ echo "Building dependency for $@" | ||
| @ $(DEPGEN) -f $(INCS) $< > $@ | ||
| %.d : %.H | ||
| %.d : %.H $(DEPGEN) | ||
| @ echo "Building dependency for $@" | ||
| @ $(DEPGEN) -f $(INCS) $< > $@ | ||
|
|
||
| # the if-tests prevent DEPS files from being created when they're not needed | ||
| ifneq ($(MAKECMDGOALS), db_files) | ||
| ifneq ($(MAKECMDGOALS), db_flags) | ||
| ifneq ($(MAKECMDGOALS), mostlyclean) | ||
| ifneq ($(MAKECMDGOALS), clean) | ||
| ifneq ($(MAKECMDGOALS), realclean) | ||
| ifneq ($(MAKECMDGOALS), targets) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the new target 'target' should also have it's line here :
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. good catch |
||
| ifneq ($(MAKECMDGOALS), target) | ||
| ifneq ($(MAKECMDGOALS), makdep) | ||
| ifneq ($(MAKECMDGOALS), depends) | ||
| -include $(DEPS) | ||
| endif | ||
| endif | ||
| endif | ||
| endif | ||
| endif | ||
| endif | ||
| endif | ||
| endif | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,29 +4,93 @@ | |
| # If the cice binary is passed as an argument and the file exists, | ||
| # copy it into the run directory and don't build the model. | ||
|
|
||
| set dohelp = 0 | ||
| set directmake = 0 | ||
| set target = "UnDEFineD" | ||
| set ciceexe = "UnDEFineD" | ||
| if ($#argv == 1) then | ||
| set ciceexe = $1 | ||
| echo "${0}: ciceexe = ${ciceexe}" | ||
| if (-e ${ciceexe}) then | ||
|
|
||
| source ./cice.settings | ||
| source ${ICE_CASEDIR}/env.${ICE_MACHCOMP} -nomodules || exit 2 | ||
| if !(-d ${ICE_RUNDIR}) mkdir -p ${ICE_RUNDIR} | ||
| cp -p ${ciceexe} ${ICE_RUNDIR}/cice | ||
|
|
||
| echo "`date` ${0}:${ICE_CASENAME} build copied ${ciceexe}" >> ${ICE_CASEDIR}/README.case | ||
| if ( ${ICE_TEST} != ${ICE_SPVAL} ) then | ||
| echo "#---" >! ${ICE_CASEDIR}/test_output | ||
| echo "COPY ${ICE_TESTNAME} build" >> ${ICE_CASEDIR}/test_output | ||
| echo "PEND ${ICE_TESTNAME} run" >> ${ICE_CASEDIR}/test_output | ||
| if ($#argv == 0) then | ||
| # continue, standard way to build | ||
| else | ||
| # -h, --help | ||
| if ("$1" == "-h" || "$1" == "--help") then | ||
| set dohelp = 1 | ||
|
|
||
| # --exe | ||
| else if ("$1" == "--exe") then | ||
| if ($#argv > 2) then | ||
| echo "${0}: ERROR: --exe ciceexe without other arguments is required" | ||
| exit -99 | ||
| endif | ||
| set ciceexe = $2 | ||
| echo "${0}: ciceexe = ${ciceexe}" | ||
| if (-e ${ciceexe}) then | ||
|
|
||
| source ./cice.settings | ||
| source ${ICE_CASEDIR}/env.${ICE_MACHCOMP} -nomodules || exit 2 | ||
| if !(-d ${ICE_RUNDIR}) mkdir -p ${ICE_RUNDIR} | ||
| cp -p ${ciceexe} ${ICE_RUNDIR}/cice | ||
|
|
||
| echo "`date` ${0}:${ICE_CASENAME} build copied ${ciceexe}" >> ${ICE_CASEDIR}/README.case | ||
| if ( ${ICE_TEST} != ${ICE_SPVAL} ) then | ||
| echo "#---" >! ${ICE_CASEDIR}/test_output | ||
| echo "COPY ${ICE_TESTNAME} build" >> ${ICE_CASEDIR}/test_output | ||
| echo "PEND ${ICE_TESTNAME} run" >> ${ICE_CASEDIR}/test_output | ||
| endif | ||
|
|
||
| exit 0 | ||
| endif | ||
|
|
||
| exit 0 | ||
|
|
||
| # direct make with target | ||
| else | ||
| set directmake = 1 | ||
| set target = "$*" | ||
| endif | ||
| endif | ||
|
|
||
| if (${dohelp} == 1) then | ||
| cat << EOF1 | ||
|
|
||
| NAME | ||
| cice.build [-h,--help] [make arguments] [target] | ||
|
|
||
| SYNOPSIS | ||
| -h || --help | ||
| [make arguments] [target] | ||
|
|
||
| DESCRIPTION | ||
| --help, -h : help | ||
| [make arguments] [target] : specify make arguments and target | ||
|
|
||
| EXAMPLES | ||
| cice.build | ||
| will build the model using the standard approach with all the bells and whistles. | ||
| This is recommended. | ||
| cice.build --help | ||
| will show cice.build help | ||
| cice.build [target] | ||
| will call gmake directly and make the target | ||
| cice.build clean | ||
| is an example of a targeted build | ||
| cice.build targets | ||
| is an example of a targeted build that shows the valid Makefile targets | ||
| cice.build --version | ||
| will call make directly and pass --version as an argument to make | ||
| cice.build [make arguments] [target] | ||
| will call make directly and pass arguments and/or a target to make | ||
|
|
||
| ADDITIONAL INFORMATION | ||
| The argument implementation supports -h or --help as a first argument. Otherwise, | ||
| it passes all other arguments directly to make and calls it directly. In this | ||
| mode, most of the cice.build script features are by-passed. The recommended | ||
| way to run the script is without arguments. | ||
|
|
||
| SEE ALSO | ||
| User Documentation at https://github.com/cice-consortium/cice/ | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we want to link to read-the-docs here instead ?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The problem is what version of readthedocs? Almost certainly whatever version we might link in the help output is incorrect. Master documentation is only correct for the current master. For released versions, would we need to manually change the link for each release? This is a case where it's easy for things to get out of sync. While pointing to the general cice repo isn't particularly useful either, at least I feel like it's never incorrect.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I understand. |
||
|
|
||
| EOF1 | ||
| exit -99 | ||
| endif | ||
|
|
||
| #==================================== | ||
|
|
||
| source ./cice.settings | ||
|
|
@@ -47,10 +111,7 @@ set stamp = `date '+%y%m%d-%H%M%S'` | |
| set ICE_BLDLOG_FILE = "cice.bldlog.${stamp}" | ||
| set quiet = ${ICE_QUIETMODE} | ||
|
|
||
| if (${ICE_CLEANBUILD} == 'true') then | ||
| echo "cleaning objdir" | ||
| rm -r -f ${ICE_OBJDIR} | ||
| endif | ||
| if !(-d ${ICE_RUNDIR}) mkdir -p ${ICE_RUNDIR} | ||
| if !(-d ${ICE_OBJDIR}) mkdir -p ${ICE_OBJDIR} | ||
| cd ${ICE_OBJDIR} | ||
|
|
||
|
|
@@ -79,6 +140,22 @@ ${ICE_SANDBOX}/cicecore/shared | |
| ${ICE_SANDBOX}/icepack/columnphysics | ||
| EOF | ||
|
|
||
| if !($?ICE_MACHINE_BLDTHRDS) then | ||
| set ICE_MACHINE_BLDTHRDS = 1 | ||
| endif | ||
|
|
||
| if (${directmake} == 1) then | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good catch, I am making those changes.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. On the second point, I think we decided for a direct make to avoid all the fluff. I think writing the make output to a bldlog file is part of that. I guess I view the circular dependencies as part of the fluff you get if you use the scripts the standard way. Also, the quietmode should not generally be used except by travis. For whatever reason, if we don't use the quiet mode with travis, it creates problems. it either concatenates the raw log file or it makes it very hard to find the errors. this was added just for travis and serves a purpose.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ok, I guess I viewed the 'fluff' as only the README.case file. But I don't feel strongly about that. So either way is fine. |
||
| echo "make ${target}" | ||
| ${ICE_MACHINE_MAKE} -j ${ICE_MACHINE_BLDTHRDS} VPFILE=Filepath EXEC=${ICE_RUNDIR}/cice \ | ||
| -f ${ICE_CASEDIR}/Makefile MACFILE=${ICE_CASEDIR}/Macros.${ICE_MACHCOMP} ${target} | ||
| set bldstat = ${status} | ||
| if (${bldstat} != 0) then | ||
| echo "${0}: targeted make FAILED" | ||
| exit -99 | ||
| endif | ||
| exit 0 | ||
| endif | ||
|
|
||
| echo " " | ||
| echo ICE_GRID = ${ICE_GRID} | ||
| echo ICE_NTASK = ${ICE_NTASKS} | ||
|
|
@@ -88,16 +165,7 @@ echo "Filepath = " | |
| cat ${ICE_OBJDIR}/Filepath | ||
| echo " " | ||
|
|
||
| echo "building makdep" | ||
| ${ICE_MACHINE_MAKE} \ | ||
| -f ${ICE_CASEDIR}/Makefile MACFILE=${ICE_CASEDIR}/Macros.${ICE_MACHCOMP} makdep || exit 2 | ||
|
|
||
| echo "building cice > ${ICE_OBJDIR}/${ICE_BLDLOG_FILE}" | ||
|
|
||
| if !(-d ${ICE_RUNDIR}) mkdir -p ${ICE_RUNDIR} | ||
| if !($?ICE_MACHINE_BLDTHRDS) then | ||
| set ICE_MACHINE_BLDTHRDS = 1 | ||
| endif | ||
| if (-e ${ICE_BLDLOG_FILE}) rm ${ICE_BLDLOG_FILE} | ||
|
|
||
| if (${ICE_CLEANBUILD} == 'true') then | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the new target 'target' should be added to the .PHONY line
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good catch.