Here is what according to me might be a portable way to catch the source pathname: 

```
 (defmacro source-pathname ()
  `,(or *compile-file-truename* *load-truename*))
```


Then at the top of your file that you want to know what was the source directory:


```
(defparameter *project-dir*
  (make-pathname :name nil :type nil :defaults (source-pathname)))

```

This source-pathname is a standard function or macro defined for Gendl in its so-called "glisp" portability layer.  I use that actual macro for SBCL because I couldn't find a built in thing to do it. Most of the other CLs have a built-in way e.g. Allegro's excl:*source-pathname* or CCL's ccl:*loading-file-source-file*. 

I think the macro should be portable though so maybe I should just be using it across the board.  



Dave Cooper


>
> On Sat, Dec 13, 2025 at 4:16 PM Marco Antoniotti <marco.antoniotti@unimib.it> wrote:
>>
>> Thanks but no.
>>
>> That would create a dependency from ASDF in the code.
>>
>> MA
>>
>>
>>
>> On Sat, Dec 13, 2025 at 1:50 PM Robert P. Goldman <rpgoldman@sift.net> wrote:
>>>
>>> ASDF:SYSTEM-RELATIVE-PATHNAME is probably what you want
>>> Sent from my iPhone
>>>
>>> > On Dec 13, 2025, at 06:11, Marco Antoniotti <marco.antoniotti@unimib.it> wrote:
>>> >
>>> > 
>>> > Hi
>>> >
>>> > I am getting old and I get confused.
>>> >
>>> > Here is the thing (a followup to the "wild" ASDF module question).
>>> >
>>> > I am writing something that will have, at run time, a variable *the-directory-where-stuff-is*.
>>> >
>>> > Now, I want to initialize this variable automagically, with no "outside" references.  I thought I could do something like
>>> >
>>> > (defvar the-directory-where-stuff-is*
>>> >    (merge-pathnames (make-pathname :directory '(:relative "stuff")
>>> >                                    :name nil :type nil)
>>> >                     (make-pathname :name nil :type nil
>>> >                                    :defaults *load-pathname*)))
>>> >
>>> > Alas, ASDF and other things may move the compiled file to a cache folder, which, in the end misaligns *load-pathname* w.r.t. where "stuff" actually is (and should be).
>>> >
>>> > This is something that build systems like cmake achieve with the notion of "source", "install", etc folders.
>>> >
>>> > Any ideas, suggestions, incantations, workarounds, even at the ASDF level to get this done?
>>> >
>>> > Thanks
>>> >
>>> >
>>> > --
>>> > Marco Antoniotti
>>>
>>
>>
>> --
>> Marco Antoniotti, Professor, Director         tel. +39 - 02 64 48 79 01
>> DISCo, University of Milan-Bicocca U14 2043   http://dcb.disco.unimib.it
>> Viale Sarca 336
>> I-20126 Milan (MI) ITALY
>>
>> REGAINS: https://regains.disco.unimib.it/
>
>
>
> --
> Marco Antoniotti, Professor, Director         tel. +39 - 02 64 48 79 01
> DISCo, University of Milan-Bicocca U14 2043   http://dcb.disco.unimib.it
> Viale Sarca 336
> I-20126 Milan (MI) ITALY
>
> REGAINS: https://regains.disco.unimib.it/