<div dir="ltr">Thanks,<div>This came up because a Chombo user, who has a makefile system that is working on other platforms, failed on Spock because it did not find a library. My make of an example worked and I had that lib and a -L path to a directory with that lib.</div><div>So I wanted to double check the recommended lib variable. I think he has PETSC_KSP_LIB, but I am waiting to hear back from him.</div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Fri, Jan 14, 2022 at 10:46 AM Barry Smith <<a href="mailto:bsmith@petsc.dev">bsmith@petsc.dev</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><br>
  I'll take a stab at fixing up the description of possible makefile approaches in the user's manual documentation and put it in an MR. I agree with Mark it is weak.<br>
<br>
  Barry<br>
<br>
<br>
> On Jan 14, 2022, at 10:41 AM, Jed Brown <<a href="mailto:jed@jedbrown.org" target="_blank">jed@jedbrown.org</a>> wrote:<br>
> <br>
> Makefile.user is meant to be the example that doesn't import a zillion variables and in which you can readily add other packages that provide pkg-config. (Just add them to one line.) If you already use pkg-config for other dependencies, it also makes clear how to add PETSc. This is symmetric, where as including PETSc makefiles is fundamentally nonsymmetric (they're full of rules and non-namespaced variables likely to conflict with other packages).<br>
> <br>
> While we could create a makefile that defines only namespaced variables and does not define rules, that would actually require more effort per package because you'd be needing CPPFLAGS = $(PETSC_CPPFLAGS) $(X_CPPFLAGS) $(Y_CPPFLAGS). In Makefile.user, you can add additional packages with one line.<br>
> <br>
> PACKAGES := $(petsc.pc) $(x.pc) $(y.pc)<br>
> <br>
> where the x.pc variable can either be the plain package name (to look for it in default locations) or a path to the x.pc file.<br>
> <br>
> Mark Adams <<a href="mailto:mfadams@lbl.gov" target="_blank">mfadams@lbl.gov</a>> writes:<br>
> <br>
>> I want an example that I can clone for an existing makefile. I don't even<br>
>> see PETSC_LIB in Makefile.user<br>
>> <br>
>> Makefile.user is where you start if 0) you are starting from scratch and<br>
>> are all-in on PETSc.<br>
>> <br>
>> I think the vast majority of our users either 1) have a makefile and want<br>
>> to add PETSc or 2) want to keep more control than this turn-key method.<br>
>> <br>
>> I think something like Victor's material is useful even if it goes out of<br>
>> date (<br>
>> <a href="https://pages.tacc.utexas.edu/~eijkhout/taccnotes/petsclinking/petsclinking.html" rel="noreferrer" target="_blank">https://pages.tacc.utexas.edu/~eijkhout/taccnotes/petsclinking/petsclinking.html</a><br>
>> ).<br>
>> <br>
>> Barry's "Writing Application Codes with PETSc" addresses (0) and then jumps<br>
>> to 3) no makefile just cut and paste (nice, not what I'm looking for, but<br>
>> cleaner than making an example).<br>
>> <br>
>> (I have literally never done any of the methods, shown in the PETSc docs,<br>
>> before. I have alway owned the makefile with my targets, and all of my<br>
>> current users do this now.)<br>
>> <br>
>> The first thing I googled was "petsc user makefile" and found and<br>
>> interesting stackoverflow post (<br>
>> <a href="https://stackoverflow.com/questions/21338718/using-petsc-on-makefile-within-my-user-defined-makefile" rel="noreferrer" target="_blank">https://stackoverflow.com/questions/21338718/using-petsc-on-makefile-within-my-user-defined-makefile</a><br>
>> )<br>
>> <br>
>> Maybe just a FAQ "Adding PETSc to a user Makefile" and you could just have<br>
>> a link to Victor's page (and have him update the include path line)<br>
>> <br>
>> <br>
>> On Thu, Jan 13, 2022 at 11:15 PM Jed Brown <<a href="mailto:jed@jedbrown.org" target="_blank">jed@jedbrown.org</a>> wrote:<br>
>> <br>
>>> No makefile is needed to build foo from foo.c.<br>
>>> <br>
>>> $ make -f $PETSC_DIR/share/petsc/Makefile.user foo<br>
>>> <br>
>>> <br>
>>> In the example below, you don't have to write the recipe (the ${CLINKER}<br>
>>> line). It's enough to write<br>
>>> <br>
>>> foo: foo.o baz.o<br>
>>> <br>
>>> Matthew Knepley <<a href="mailto:knepley@gmail.com" target="_blank">knepley@gmail.com</a>> writes:<br>
>>> <br>
>>>> foo: foo .o<br>
>>>>      ${CLINKER} -o $@ $^ ${PETSC_LIB}<br>
>>>> <br>
>>>>   Matt<br>
>>>> <br>
>>>> On Thu, Jan 13, 2022 at 9:54 PM Jacob Faibussowitsch <<br>
>>> <a href="mailto:jacob.fai@gmail.com" target="_blank">jacob.fai@gmail.com</a>><br>
>>>> wrote:<br>
>>>> <br>
>>>>> Is share/petsc/Makefile.user what you are looking for?<br>
>>>>> <br>
>>>>> Best regards,<br>
>>>>> <br>
>>>>> Jacob Faibussowitsch<br>
>>>>> (Jacob Fai - booss - oh - vitch)<br>
>>>>> <br>
>>>>> On Jan 13, 2022, at 21:49, Barry Smith <<a href="mailto:bsmith@petsc.dev" target="_blank">bsmith@petsc.dev</a>> wrote:<br>
>>>>> <br>
>>>>> <br>
>>>>> <br>
>>>>> <br>
>>> <a href="https://petsc.org/release/docs/manual/getting_started/?highlight=user%20makefile" rel="noreferrer" target="_blank">https://petsc.org/release/docs/manual/getting_started/?highlight=user%20makefile</a><br>
>>>>> <br>
>>>>> Search for Writing Application Codes with PETSc<br>
>>>>> <br>
>>>>> Perhaps this needs to clearer or have links to it from the FAQ.<br>
>>>>> <br>
>>>>> <br>
>>>>> <br>
>>>>> On Jan 13, 2022, at 9:38 PM, Mark Adams <<a href="mailto:mfadams@lbl.gov" target="_blank">mfadams@lbl.gov</a>> wrote:<br>
>>>>> <br>
>>>>> I am finding it pretty hard to find an example of a makefile target to<br>
>>>>> build an app with PETSc.<br>
>>>>> <br>
>>>>> I can not find it on the docs page.<br>
>>>>> <br>
>>>>> With Google:<br>
>>>>> <br>
>>>>> Victor has a little example that looks fine ($PETSC_LIB). (sort of, see<br>
>>>>> below)<br>
>>>>> <br>
>>>>> Another one is bigger and has this at the end:<br>
>>>>> <br>
>>>>>    -${CLINKER} $< -o bin.x $(OBJ_FILES) ${PETSC_KSP_LIB}<br>
>>>>> -I$(PETSC_DIR)/include<br>
>>>>> <br>
>>>>> I recall using PETSC_KSP_LIB the last time I wrote a makefile 20 years<br>
>>> ago.<br>
>>>>> <br>
>>>>> Maybe there should be a FAQ that a search would find like "Example of<br>
>>> user<br>
>>>>> makefile" with something like Victor's (dropping v2 and updating it,<br>
>>> this<br>
>>>>> looks wrong):<br>
>>>>> <br>
>>>>> <br>
>>>>> <br>
>>>>> <br>
>>>>> <br>
>>>>> <br>
>>>>> <br>
>>>>> <br>
>>>>> <br>
>>>>> <br>
>>>>> <br>
>>>>> <br>
>>>>> <br>
>>>>> <br>
>>>>> <br>
>>>>> <br>
>>>>> <br>
>>>>> <br>
>>>>> <br>
>>>>> <br>
>>>>> <br>
>>>>> <br>
>>>>> <br>
>>>>> <br>
>>>>> <br>
>>>>> <br>
>>>>> <br>
>>>>> <br>
>>>>> <br>
>>>>> <br>
>>>>> <br>
>>>>> <br>
>>>>> *PETSc linkingThe easiest way to link PETSc to your code is to have this<br>
>>>>> line in your makefile:include ${PETSC_DIR}/conf/baseThis will<br>
>>> automatically<br>
>>>>> give you the compilation rules. For linking you then do:${CLINKER} -o<br>
>>> ex1<br>
>>>>> ex1.o ${PETSC_LIB}(or FLINKER for fortran)You can also use this include<br>
>>>>> line:include ${PETSC_DIR}/conf/variablesand then you have to give the<br>
>>>>> compile rules yourself. In this case, dosomething like${CC} -c ex1.c<br>
>>>>> ${PETSC_INCLUDE}to compile. (This is for petsc version 3, for version 2<br>
>>>>> useinclude ${PETSC_DIR}/bmake/common/baseand replace base by variables<br>
>>> to<br>
>>>>> omit petsc’s make rules.)If you insist on having all the libraries and<br>
>>>>> includes explicitly, usemake getlinklibsmake getincludedirs*<br>
>>>>> <br>
>>>>> <br>
>>>>> <br>
>>>>> <br>
>>>>> <br>
>>>> <br>
>>>> --<br>
>>>> What most experimenters take for granted before they begin their<br>
>>>> experiments is infinitely more interesting than any results to which<br>
>>> their<br>
>>>> experiments lead.<br>
>>>> -- Norbert Wiener<br>
>>>> <br>
>>>> <a href="https://www.cse.buffalo.edu/~knepley/" rel="noreferrer" target="_blank">https://www.cse.buffalo.edu/~knepley/</a> <<br>
>>> <a href="http://www.cse.buffalo.edu/~knepley/" rel="noreferrer" target="_blank">http://www.cse.buffalo.edu/~knepley/</a>><br>
>>> <br>
<br>
</blockquote></div>