Skip to content
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

Decouple the Makefile from the SOILWAT2 file structure #483

Open
chaukap opened this issue Mar 10, 2020 · 3 comments
Open

Decouple the Makefile from the SOILWAT2 file structure #483

chaukap opened this issue Mar 10, 2020 · 3 comments

Comments

@chaukap
Copy link
Contributor

chaukap commented Mar 10, 2020

Currently the STEPWAT2 makefile is tightly coupled to the file structure of SOILWAT2. there are 23 points of contact:

	sw_src/filefuncs.c 
	sw_src/generic.c 
	sw_src/mymemory.c 
	sw_src/pcg/pcg_basic.c 
	sw_src/rands.c 
	sw_src/SW_Carbon.c 
	sw_src/SW_Control.c 
	sw_src/SW_Files.c 
	sw_src/SW_Flow.c 
	sw_src/SW_Flow_lib.c 
	sw_src/SW_Markov.c 
	sw_src/SW_Model.c 
	sw_src/SW_Output.c 
	sw_src/SW_Output_get_functions.c 
	sw_src/SW_Output_outarray.c 
	sw_src/SW_Output_outtext.c 
	sw_src/SW_Site.c 
	sw_src/SW_Sky.c 
	sw_src/SW_SoilWater.c 
	sw_src/SW_VegEstab.c 
	sw_src/SW_VegProd.c 
	sw_src/SW_Weather.c 
	sw_src/Times.c 

If any one of these files is moved STEPWAT2 will not compile.

Solution

We can reduce the points of contact to 2:

sw_src/makefile
sw_src/libSOILWAT2.a

SOILWAT2's makefile has a rule to create a library file. As long as we know where the makefile and the library file are located the rest of SOILWAT2 can be abstracted away.

However, there are a few caveats. Variables can no longer be externed across the two codebases. This means variables like SXW and SuperGlobals must be declared in header files. This should be fairly easy to do.

Unfortunately, the other change must be done on the SOILWAT2 side. There are 2 source files that are currently not compiled into the SOILWAT2 library: SW_Output_outtext.c and SW_Output_outarray.c. These must be added to the sources_lib variable in the SOILWAT2 makefile.

@chaukap
Copy link
Contributor Author

chaukap commented Mar 11, 2020

To elaborate on the externed variables issue, we will need to move the declaration of the following variables:

From ST_main.c to ST_globals.h:

  • Species
  • RGroup
  • Succulent
  • Env
  • Plot
  • Globals
  • BmassFlags
  • MortFlags
  • SuperGlobals

Technically we only need to move SuperGlobals and Globals, but while we're at it we might as well move the rest of them for the sake of clean code.

From sxw.c to sxw.h:

  • SXW

As a side effect of moving SXW to sxw.h the file sxw_vars.h will be rendered completely useless. It should probably be removed.

@dschlaep
Copy link
Member

Re:

Unfortunately, the other change must be done on the SOILWAT2 side. There are 2 source files that are currently not compiled into the SOILWAT2 library: SW_Output_outtext.c and SW_Output_outarray.c. These must be added to the sources_lib variable in the SOILWAT2 makefile.

--> The SOILWAT2 makefile accounts for this issue because the output needs are so different for SOILWAT2-standalone, rSOILWAT2, and STEPWAT2: the makefile accepts sw_sources to add additional source files to be compiled into the SOILWAT2 library. See the example in rSOILWAT2 https://github.com/DrylandEcology/rSOILWAT2/blob/master/src/Makevars

...
sw_sources = SW_Output_outarray.c
...
$(path_target)/$(lib_target):
	@(cd $(path_target) && $(MAKE) $(lib_target) \
		CC="$(CC)" CPPFLAGS="$(ALL_CPPFLAGS)" CFLAGS="$(ALL_CFLAGS)" AR="$(AR)" \
		sw_sources="$(sw_sources)")
...

so for STEPWAT2, this could then be adjusted to something like

sw_sources = SW_Output_outtext.c SW_Output_outarray.c

@chaukap
Copy link
Contributor Author

chaukap commented Mar 13, 2020

@dschlaep Thanks for the help! This should make the implementation very easy for the person that implements it.

dschlaep added a commit that referenced this issue Jul 14, 2020
dschlaep added a commit that referenced this issue Jul 14, 2020
…LWAT2

- address #483
- contribute to DrylandEcology/SOILWAT2#89

--> the subfolder path of SOILWAT2 occurs now consistently on the STEPWAT2 side:
1) makefile variable "path_sw2"
2) in the include header directives (see previous commit)
--> if SOILWAT2 changes its file organization, then search/replace of "sw_src" with the new value can now be done

Other changes:
- since CC is hard-coded to gcc, I defined CXX to g++ so that compilation occurs only within compiler families (and not potentially across, e.g., in case CXX would be defined as clang++)
- helper targets to run STEPWAT2 executable in example folder, i.e., `bint_testing_nongridded` and `bint_testing_gridded`, also compiled unit tests, but never run the unit tests
--> removed dependency on unit test target
--> added a separate make target "run_tests" which compiles and runs the STEPWAT2 unit tests

Note:
The warning "SW_Main_lib.c:56:6: warning: no previous prototype for function 'usage' [-Wmissing-prototypes]" is fixed with SOILWAT2 commit a44e5688e7799c44b72b017a724ee7ee857531cc (dev-branch enhance_petfunc)
dschlaep added a commit that referenced this issue Jul 21, 2020
Use SOILWAT2's makefile to compile a SOILWAT2 library
Addressing issue #483 and contribute to DrylandEcology/SOILWAT2#89
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants