Skip to content

Commit

Permalink
Merge pull request #499 from DrylandEcology/make_SOILWAT2_library
Browse files Browse the repository at this point in the history
Use SOILWAT2's makefile to compile a SOILWAT2 library
Addressing issue #483 and contribute to DrylandEcology/SOILWAT2#89
  • Loading branch information
dschlaep authored Jul 21, 2020
2 parents f2f7df6 + abc38bc commit f5b64f2
Show file tree
Hide file tree
Showing 27 changed files with 126 additions and 130 deletions.
2 changes: 1 addition & 1 deletion ST_defines.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
#ifndef STEPPE_DEF_H
#define STEPPE_DEF_H

#include "generic.h"
#include "sw_src/generic.h"

/* see #include "ST_structs.h" below */

Expand Down
2 changes: 1 addition & 1 deletion ST_environs.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
#include "ST_steppe.h"
#include "ST_globals.h"
#include "sw_src/pcg/pcg_basic.h"
#include "rands.h"
#include "sw_src/rands.h"
#include "sxw_funcs.h"
#include "sw_src/filefuncs.h"
#include "sw_src/Times.h"
Expand Down
8 changes: 4 additions & 4 deletions ST_grid.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,14 @@
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include "sw_src/generic.h"
#include "sw_src/filefuncs.h"
#include "sw_src/myMemory.h"
#include "sw_src/rands.h"
#include "ST_grid.h"
#include "ST_steppe.h"
#include "generic.h"
#include "filefuncs.h"
#include "myMemory.h"
#include "ST_globals.h"
#include "ST_stats.h"
#include "rands.h"
#include "sxw_funcs.h"
#include "ST_initialization.h"
#include "ST_progressBar.h"
Expand Down
10 changes: 5 additions & 5 deletions ST_grid.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@
#include "ST_defines.h"
#include "sw_src/pcg/pcg_basic.h"
#include "sxw_vars.h"
#include "SW_Site.h"
#include "SW_SoilWater.h"
#include "SW_VegProd.h"
#include "SW_Model.h"
#include "SW_Weather.h"
#include "sw_src/SW_Site.h"
#include "sw_src/SW_SoilWater.h"
#include "sw_src/SW_VegProd.h"
#include "sw_src/SW_Model.h"
#include "sw_src/SW_Weather.h"
#include "ST_seedDispersal.h"

/*********************** Grid Structures ****************************/
Expand Down
4 changes: 2 additions & 2 deletions ST_indivs.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
#include <memory.h>
#include "ST_steppe.h"
#include "ST_globals.h"
#include "filefuncs.h"
#include "myMemory.h"
#include "sw_src/filefuncs.h"
#include "sw_src/myMemory.h"


/******** Modular External Function Declarations ***********/
Expand Down
4 changes: 2 additions & 2 deletions ST_initialization.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
#include "sw_src/pcg/pcg_basic.h"
#include "sw_src/rands.h"
#include "sxw_funcs.h"
#include "myMemory.h"
#include "filefuncs.h"
#include "sw_src/myMemory.h"
#include "sw_src/filefuncs.h"
#include "ST_progressBar.h"
#include "ST_stats.h"

Expand Down
10 changes: 5 additions & 5 deletions ST_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@
#include <stdlib.h>
#include <stdio.h>
#include "ST_steppe.h"
#include "generic.h"
#include "filefuncs.h"
#include "myMemory.h"
#include "SW_VegProd.h"
#include "SW_Control.h"
#include "sw_src/generic.h"
#include "sw_src/filefuncs.h"
#include "sw_src/myMemory.h"
#include "sw_src/SW_VegProd.h"
#include "sw_src/SW_Control.h"
#include "sw_src/pcg/pcg_basic.h"

#include "sxw_funcs.h"
Expand Down
6 changes: 3 additions & 3 deletions ST_mortality.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@

#include "ST_mortality.h"
#include "sw_src/filefuncs.h"
#include "generic.h"
#include "rands.h"
#include "myMemory.h"
#include "sw_src/generic.h"
#include "sw_src/rands.h"
#include "sw_src/myMemory.h"
#include "ST_steppe.h"
#include "ST_globals.h"
#include "sw_src/pcg/pcg_basic.h"
Expand Down
2 changes: 1 addition & 1 deletion ST_mortality.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#ifndef MORTALITY_H
#define MORTALITY_H

#include "generic.h"
#include "sw_src/generic.h"
#include "sw_src/pcg/pcg_basic.h"

/* --------------------------- Exported Structs ---------------------------- */
Expand Down
6 changes: 3 additions & 3 deletions ST_output.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@
#include <string.h>
#include "ST_steppe.h"
#include "ST_globals.h"
#include "filefuncs.h"
#include "myMemory.h"
#include "sw_src/filefuncs.h"
#include "sw_src/myMemory.h"


/******** Modular External Function Declarations ***********/
/* -- truly global functions are declared in functions.h --*/
/***********************************************************/
#include "SW_Model.h"
#include "sw_src/SW_Model.h"
extern SW_MODEL SW_Model;

/*------------------------------------------------------*/
Expand Down
10 changes: 5 additions & 5 deletions ST_params.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@
#include <ctype.h>
#include <errno.h>
#include "ST_steppe.h"
#include "generic.h"
#include "filefuncs.h"
#include "myMemory.h"
#include "rands.h"
#include "sw_src/generic.h"
#include "sw_src/filefuncs.h"
#include "sw_src/myMemory.h"
#include "sw_src/rands.h"
#include "sxw_funcs.h"


Expand Down Expand Up @@ -1242,7 +1242,7 @@ void parm_free_memory( void ) {


#ifdef DEBUG_MEM
#include "myMemory.h"
#include "sw_src/myMemory.h"
/**************************************************************/
void Parm_SetMemoryRefs( void) {
/*======================================================*/
Expand Down
8 changes: 4 additions & 4 deletions ST_resgroups.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@
#include <stdio.h>
#include "ST_steppe.h"
#include "ST_globals.h"
#include "myMemory.h"
#include "rands.h"
#include "generic.h"
#include "sw_src/myMemory.h"
#include "sw_src/rands.h"
#include "sw_src/generic.h"
#include "sw_src/filefuncs.h"
#include "ST_functions.h"
#include "sxw_funcs.h"
Expand Down Expand Up @@ -1254,7 +1254,7 @@ IndivType **RGroup_GetIndivs(GrpIndex rg, const char sort, IntS *num)
}

#ifdef DEBUG_MEM
#include "myMemory.h"
#include "sw_src/myMemory.h"
/*======================================================*/
void RGroup_SetMemoryRefs( void)
{
Expand Down
4 changes: 2 additions & 2 deletions ST_seedDispersal.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
#include "ST_defines.h"
#include "ST_grid.h"
#include "ST_seedDispersal.h"
#include "rands.h"
#include "myMemory.h"
#include "sw_src/rands.h"
#include "sw_src/myMemory.h"

int _do_bulk_dispersal(SppIndex sp);
void _do_precise_dispersal(int leftoverSeeds, SppIndex sp);
Expand Down
6 changes: 3 additions & 3 deletions ST_species.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@
#include "ST_steppe.h"
#include "ST_globals.h"
#include "sw_src/filefuncs.h"
#include "myMemory.h"
#include "rands.h"
#include "sw_src/myMemory.h"
#include "sw_src/rands.h"
#include "sw_src/pcg/pcg_basic.h"
#include "ST_initialization.h"
#include "ST_seedDispersal.h"
Expand Down Expand Up @@ -628,7 +628,7 @@ void save_annual_species_relsize() {
}

#ifdef DEBUG_MEM
#include "myMemory.h"
#include "sw_src/myMemory.h"
/*======================================================*/
void Species_SetMemoryRefs( void)
{
Expand Down
4 changes: 2 additions & 2 deletions ST_stats.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@
#include <string.h>
#include <math.h>
#include "ST_steppe.h"
#include "filefuncs.h"
#include "myMemory.h"
#include "sw_src/filefuncs.h"
#include "sw_src/myMemory.h"
#include "ST_structs.h"
#include "ST_stats.h" // Contains most of the function declarations.
#include "ST_seedDispersal.h"
Expand Down
2 changes: 1 addition & 1 deletion ST_steppe.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
#include "ST_defines.h"
#include "ST_functions.h"

#include "generic.h"
#include "sw_src/generic.h"

#define DFLT_FIRSTFILE "files.in"

Expand Down
2 changes: 1 addition & 1 deletion ST_structs.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
#ifndef STEPPE_STRUCT_DEF
#define STEPPE_STRUCT_DEF

#include "generic.h"
#include "sw_src/generic.h"
#include "ST_mortality.h"

/**
Expand Down
82 changes: 39 additions & 43 deletions makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
CC = gcc
CXX = g++

CFLAGS = \
-std=c99 \
Expand All @@ -17,16 +18,17 @@ CFLAGS = \
-Wstrict-prototypes \
-Wunused

sw2 = SOILWAT2
lib_sw2 = lib$(sw2).a
path_sw2 = sw_src

INC_DIRS = \
-I. \
-Isqlite-amalgamation \
-Isw_src \
-Isw_src/googletest/googletest \
-Isw_src/googletest/googletest/include \
-I$(path_sw2)/googletest/googletest \
-I$(path_sw2)/googletest/googletest/include \
-Itest

LIBS = -lm

sources_core = \
sqlite-amalgamation/sqlite3.c \
ST_environs.c \
Expand All @@ -40,29 +42,6 @@ sources_core = \
ST_species.c \
ST_sql.c \
ST_stats.c \
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 \
sxw.c \
sxw_environs.c \
sxw_resource.c \
Expand All @@ -73,25 +52,39 @@ sources_core = \
ST_seedDispersal.c

sources_test = \
sw_src/googletest/googletest/src/gtest-all.cc \
sw_src/googletest/googletest/src/gtest_main.cc \
$(path_sw2)/googletest/googletest/src/gtest-all.cc \
$(path_sw2)/googletest/googletest/src/gtest_main.cc \
test/test_ST_mortality.cc

sw2_sources = \
SW_Output_outarray.c \
SW_Output_outtext.c


objects_core = $(sources_core:%.c=obj/%.o)
objects_core_test = $(sources_core:%.c=obj/%_TEST.o)
objects_test = $(sources_test:%.cc=obj/%.o)

all: stepwat stepwat_test

stepwat: $(objects_core)
$(CC) $(objects_core) $(CFLAGS) $(CPPFLAGS) $(LIBS) -o stepwat
sw_LDFLAGS = $(LDFLAGS) -L. -L$(path_sw2)
sw_LDLIBS = -l$(sw2) $(LDLIBS) -lm



all: $(path_sw2)/$(lib_sw2) stepwat stepwat_test

$(path_sw2)/$(lib_sw2):
@(cd $(path_sw2) && $(MAKE) $(lib_sw2) \
CC="$(CC)" CPPFLAGS="$(CPPFLAGS)" CFLAGS="$(CFLAGS)" AR="$(AR)" \
sw_sources="$(sw2_sources)")

stepwat: $(path_sw2)/$(lib_sw2) $(objects_core)
$(CC) $(objects_core) $(CFLAGS) $(CPPFLAGS) $(sw_LDLIBS) $(sw_LDFLAGS) -o stepwat
-@cp stepwat testing.sagebrush.master
-@cp stepwat testing.sagebrush.master/Stepwat_Inputs

stepwat_test: $(objects_core_test) $(objects_test)
$(CXX) $(objects_core_test) $(objects_test) $(CFLAGS) $(CPPFLAGS) $(LIBS) -o stepwat_test
-@cp stepwat_test testing.sagebrush.master
-@cp stepwat_test testing.sagebrush.master/Stepwat_Inputs
stepwat_test: $(path_sw2)/$(lib_sw2) $(objects_core_test) $(objects_test)
$(CXX) $(objects_core_test) $(objects_test) $(CFLAGS) $(CPPFLAGS) $(sw_LDLIBS) $(sw_LDFLAGS) -o stepwat_test

obj/%.o: %.c
$(CC) $(CFLAGS) $(CPPFLAGS) $(INC_DIRS) -c $< -o $@
Expand All @@ -102,12 +95,16 @@ obj/%.o: %.cc
obj/%_TEST.o: %.c
$(CC) $(CFLAGS) $(CPPFLAGS) $(INC_DIRS) -DSTDEBUG -c $< -o $@

.PHONY: run_tests
run_tests: stepwat_test
./stepwat_test

.PHONY: bint_testing_nongridded
bint_testing_nongridded: stepwat stepwat_test
bint_testing_nongridded: stepwat
testing.sagebrush.master/Stepwat_Inputs/stepwat -d testing.sagebrush.master/Stepwat_Inputs -f files.in -o -i

.PHONY: bint_testing_gridded
bint_testing_gridded: stepwat stepwat_test
bint_testing_gridded: stepwat
testing.sagebrush.master/stepwat -d testing.sagebrush.master -f files.in -g

.PHONY: cleanall
Expand All @@ -119,27 +116,26 @@ clean: cleanobjs cleanbin documentation_clean
.PHONY: cleanobjs
cleanobjs:
-@find . -type f -name '*.o' -delete
-@$(RM) -f $(path_sw2)/$(lib_sw2)

.PHONY: cleanbin
cleanbin:
-@rm -f stepwat
-@rm -f stepwat_test
-@rm -f testing.sagebrush.master/stepwat
-@rm -f testing.sagebrush.master/stepwat_test
-@rm -f testing.sagebrush.master/Stepwat_Inputs/stepwat
-@rm -f testing.sagebrush.master/Stepwat_Inputs/stepwat_test

.PHONY: output_clean
output_clean:
-@rm -rf testing.sagebrush.master/Output/*
-@rm -rf testing.sagebrush.master/Stepwat_Inputs/Output/*

.PHONY : documentation_clean
documentation_clean :
documentation_clean :
@rm -rf Documentation/html

.PHONY : documentation
documentation:
documentation:
@doxygen doxyfile
@if open Documentation/html/index.html; \
then echo "Success"; \
Expand Down
Loading

0 comments on commit f5b64f2

Please sign in to comment.