[petsc-users] Petsc makefile and PETSC_COMPILE variable

Barry Smith bsmith at petsc.dev
Tue Dec 15 21:41:26 CST 2020


  Alex,

   Since you are explicitly defining your rules you might as well just do it completely, so use something like

>> objects/%.o: src/%.c $(DEP)
>>                ${PCC} -c $< -o $@ ${PCC_FLAGS} ${PFLAGS} ${CCPPFLAGS}

The P indicates either C and C flags or C++ compiler and its  flags if configure was run with --with-clanguage=c++ (not recommended).

So if your code is C you can use 


>> ${CC} -c $< -o $@ ${CC_FLAGS} ${CPP_FLAGS}

if C++ use

>> ${CXX} -c $< -o $@ ${CXXPP_FLAGS} ${CXX_FLAGS}
> 

With this you don't need the COMPILE macros that are really internal for PETSc's use.


  Barry

  We have not been completely successful at getting share/petsc/Makefile.user to be bullet proof yet, but if you can get it to work in your case great.



> On Dec 15, 2020, at 11:46 AM, Alex Koshkarov <okoshkarov at tae.com> wrote:
> 
> Thank you! 
> 
> It makes sense to use share/petsc/Makefile.user - I will try to understand it. However, can you please tell me what is the meaning of "_SINGLE" in "PETSC_COMPILE_SINGLE"? Does it mean compile only one source file?
> 
> Best regards,
> Alex Koshkarov.
> 
> On 12/15/20, 9:25 AM, "Satish Balay" <balay at mcs.anl.gov> wrote:
> 
>    On Tue, 15 Dec 2020, Alex Koshkarov wrote:
> 
>> Hi All,
>> 
>> I have been using trivial makefile (see below) for the code which uses petsc. The makefile relies on variable PETSC_COMPILE which disappeared in new petsc version (absent in 3.14.2, but present in 3.13.4). What would be the right way to fix the makefile? (should I use something like PETSC_COMPILE_SINGLE ?).
> 
>    Yes - this change was a bugfix.
> 
>> Is it a very bad practice to use such makefile?
> 
>    For most use cases the default targets work. However this usage [where sources and obj files are in different dirs] is not covered by them.
> 
>    So - I think using such targets is appropriate.
> 
>    There is also share/petsc/Makefile.user - which attempts to provide a portable way to create user makefiles [that don't rely on internals like PETSC_COMPILE_SINGLE] - but requires gnumake and pkgconfig
> 
>    Satish
> 
> 
>> 
>> p.s. sorry if this is a duplicate message, I believe I sent the first one to the wrong address.
>> 
>> Thank you very much,
>> Alex Koshkarov.
>> 
>> 
>> Example of makefile, it assumes sources in “src” and creats objects in “objects”:
>> 
>> CPP := $(wildcard src/*.c)
>> DEP := $(wildcard src/*.h)
>> OBJ := $(addprefix objects/,$(notdir $(CPP:.c=.o)))
>> 
>> include ${PETSC_DIR}/lib/petsc/conf/variables
>> include ${PETSC_DIR}/lib/petsc/conf/rules
>> 
>> driver: $(OBJ)
>>                -${CLINKER} -o $@ $^ ${PETSC_LIB} ${EXTRALIBS} ${CFLAGS}
>> 
>> objects/%.o: src/%.c $(DEP)
>>                ${PETSC_COMPILE} -c $< -o $@
>> 
>> 
> 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20201215/2be45a7e/attachment.html>


More information about the petsc-users mailing list