# Creating a simple fortran Autotools based project

**URL:** <https://fortran-lang.discourse.group/t/creating-a-simple-fortran-autotools-based-project/4938>\
**Category:** Uncategorized\
**Created:** [December 23, 2022, 7:28pm UTC](https://fortran-lang.discourse.group/t/creating-a-simple-fortran-autotools-based-project/4938 "2022-12-23T19:28:44Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![mary](https://avatars.discourse-cdn.com/v4/letter/m/e99b99/32.png) [@mary](https://fortran-lang.discourse.group/u/mary)\
**Post date:** [December 23, 2022, 7:28pm UTC](https://fortran-lang.discourse.group/t/creating-a-simple-fortran-autotools-based-project/4938/1 "2022-12-23T19:28:45Z")

</div>

My objective is to include my modules in a big library written in Fortran. To compile and install this library, the autotools suits are used. I can see that including my modules into the source codes of this library (by writing: use myModule) leads to errors indicating that myModule cannot be read. So, this means that I have probably to change other files (such as Makefile.am, Makefile.in, Makefile.mk, Makefile, etc.). So in order to **understand** the steps and not changing blindly the contents of these files by trial and error, I would like to ask you if you could possibly provide me with some **tutorials/videos/PDFs** on how to create a simple **fortran** autotools based project.

P.S.: I posted a question yesterday about “[How to make a Fortran Makefiles with object files (.o) and a shared library (.so)?](https://stackoverflow.com/questions/74893823/how-to-make-a-fortran-makefiles-with-object-files-o-and-a-share-library-so/74893878?noredirect=1#comment132170028_74893878)”. This is now clear to me. I don’t know if the next step is reading about Autotools or before that I should learn and read about other tools. But please do not hesitate to provide me with what you think to be useful to achieve my goal which is changing a big library by including my own modules.

---

<div class="post-metadata">

**Author:** ![Arjen](https://avatars.discourse-cdn.com/v4/letter/a/b9bd4f/32.png) [@Arjen](https://fortran-lang.discourse.group/u/Arjen)\
**Post date:** [December 27, 2022, 9:57am UTC](https://fortran-lang.discourse.group/t/creating-a-simple-fortran-autotools-based-project/4938/2 "2022-12-27T09:57:36Z")

</div>

Welcome to the Forum!

I have a small demo project that might be of some use. It does not cover all the features you mention, nor is there much in the way of explanatory text. I know of no specific tutorials or the like. Unfortunately, uploading a zip file is not allowed, so I attach a shell archive instead.  
[autofort.sh.txt](https://fortran-lang.discourse.group/uploads/short-url/m4cXIpq48GYxWFFbd4rezZpYPdW.txt) (52.3 KB)

---

<div class="post-metadata">

**Author:** ![ivanpribec](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/ivanpribec/32/3290_2.png) [@ivanpribec](https://fortran-lang.discourse.group/u/ivanpribec)\
**Post date:** [December 30, 2022, 11:02am UTC](https://fortran-lang.discourse.group/t/creating-a-simple-fortran-autotools-based-project/4938/3 "2022-12-30T11:02:14Z")

</div>

Hi Mary, welcome to Discourse!

The book [21st Century C](https://www.oreilly.com/library/view/21st-century-c/9781491904428/) by Ben Klemens has a section titled “Packaging Your Code with Autotools” (pg. 79) which offers a short introduction. The Autotools workflow is summarized by the following chart:

 ![image](https://global.discourse-cdn.com/free1/uploads/fortran_lang/original/2X/b/bce4edea5022352ecae895955c448f924d4d0bee.png)

Another source of information could be looking at existing Fortran projects using Autotools. One I’m aware of is [PSBLAS](https://github.com/sfilippone/psblas3). A Google search has also led me to [AstroBEAR](https://www.pas.rochester.edu/astrobear/), which offers some materials on the [Use [of] GNU Autotools](http://www.pas.rochester.edu/~bliu/Documents/configure.pdf) (PDF, 305 kB).

Generally speaking, the issue you encounter with GNU Autotools and Fortran is how to capture the module dependencies. We’ve had a few discussions on that topic already including

- [Module dependencies](https://fortran-lang.discourse.group/t/module-dependencies/1194), and
- [How do you generate file dependence when writing Makefile?](https://fortran-lang.discourse.group/t/how-do-you-generate-file-dependence-when-writing-makefile/2125).

Several tools exist to automate generation of these dependencies in the makefile rule format, including compiler built-in ones, [makedepf90](https://linux.die.net/man/1/makedepf90) or [fdep](https://gitlab.mpcdf.mpg.de/elpa/elpa/-/tree/master/fdep) (Autotools specific), however YMMV. Since you say your are contributing to an (existing) big library, it is likely your project already has some mechanisms/conventions for capturing module dependencies (either automated or manually/explicitly).

---

<div class="post-metadata">

**Author:** ![mary](https://avatars.discourse-cdn.com/v4/letter/m/e99b99/32.png) [@mary](https://fortran-lang.discourse.group/u/mary)\
**Post date:** [December 30, 2022, 4:44pm UTC](https://fortran-lang.discourse.group/t/creating-a-simple-fortran-autotools-based-project/4938/4 "2022-12-30T16:44:13Z")

</div>

Thank you so much Arjen

---

<div class="post-metadata">

**Author:** ![mary](https://avatars.discourse-cdn.com/v4/letter/m/e99b99/32.png) [@mary](https://fortran-lang.discourse.group/u/mary)\
**Post date:** [December 30, 2022, 5:02pm UTC](https://fortran-lang.discourse.group/t/creating-a-simple-fortran-autotools-based-project/4938/5 "2022-12-30T17:02:34Z")

</div>

Thank you Ivan for taking the time to answer me. In meantime, I found AstroBEAR and PSBLAS and did some tests. The book that you mentioned is what I was really looking for; lots of explanation and very intuitive. Thank you.
