From d93aaf3dcb57b962b90f21f755b08a7aeb2434b7 Mon Sep 17 00:00:00 2001
From: Michael Blaschek <michael.blaschek@univie.ac.at>
Date: Mon, 30 Jan 2023 23:09:16 +0000
Subject: [PATCH] fixed Makefile

---
 .gitlab-ci.yml | 12 ++++++------
 src/Makefile   | 18 +++++++++++++++---
 2 files changed, 21 insertions(+), 9 deletions(-)

diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index efc8f41..f4b5cee 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -10,13 +10,13 @@ build:
     - if: $MANUALBUILD
 
   before_script:
-    - apt-get install -y -qq libnetcdf-dev libeccodes-dev
+    - apt-get install -y -qq libnetcdf-dev libnetcdff-dev libeccodes-dev netcdf-bin
 
   script:
-    - FC=gfortran
-    - LIBRARY=$(nc-config --libs)
-    - INCLUDE=$(nc-config --inlcudedir)
-    - make -C ./src
+    - export FC=gfortran
+    - export LIBRARY_PATH=/usr/local/lib/x86_64-linux-gnu:/lib/x86_64-linux-gnu:/usr/lib/x86_64-linux-gnu
+    - export INCLUDE=/usr/include
+    - make -C src
   
   artifacts:
     paths:
@@ -29,4 +29,4 @@ test:
   script:
     - ./src/main
     - test -f pres_temp_4D.nc
-    - ncdump pres_temp_4D.nc
+    - ncdump -h pres_temp_4D.nc
diff --git a/src/Makefile b/src/Makefile
index 2b735ca..059becd 100644
--- a/src/Makefile
+++ b/src/Makefile
@@ -1,7 +1,19 @@
-all: main clean
+# use the environmental variable $INCLUDE
+# split the paths separated by :
+INC = $(subst :, ,$(INCLUDE))
+# add a -I/path/to/include
+INC := $(INC:%=-I%)
+# use the environmental variable $LIBRARY_PATH
+LIBS = $(subst :, ,$(LIBRARY_PATH))
+LIBS := $(LIBS:%=-L%)
+#
+all: clean main
 
-main:
-    $FC ${INCLUDE} ${LIBRARY} -o $@
+main: main.o
+	${FC} $< $(INC) $(LIBS) -lnetcdff -o $@
+%.o %.mod %.smod: %.f90
+	${FC} ${INC} -c -o $*.o $<
 
+.PHONY: clean
 clean:
 	rm -rf main *.o
-- 
GitLab