How I just download the source code for a port, instead of installing it?

Whenever I can, I use the pkg tool do install software, but on rare occasions, I use the ports too. I know it is a more professional way of getting the job done.

I know one can download the source code for a port and edit it to his liking and then compile it, but I have never done that so far. Now I'm trying to write a custom VFS module for samba, confiding in my basic knowledge of the C programming language. I downloaded the source code for v4.16 from Samba.org but found out that it is an intricate web of "includes", and some seem to be broken, for some reason, I'll not even get into that.

How does portmaster do its job? Where does it keep the source code?

I'm very knew to this realm and I'd appreciate if someone pointed me in the right direction.
 
Use `make patch` in the port directory.

Got this:

Code:
root@freebsd:/usr/ports/net/samba416 # make patch
===>  License GPLv3+ accepted by the user
===>   samba416-4.16.11_5 depends on file: /usr/local/sbin/pkg - found
===> Fetching all distfiles required by samba416-4.16.11_5 for building
===>  Extracting for samba416-4.16.11_5
=> SHA256 Checksum OK for samba-4.16.11.tar.gz.
===>  Patching for samba416-4.16.11_5
===>  Applying extra patch /usr/ports/net/samba416/files/0001-Compact-and-simplify-modules-build-and-config-genera.patch with -p1
===>  Applying extra patch /usr/ports/net/samba416/files/0002-Adjust-abi_gen.sh-script-to-run-under-FreeBSD-with-i.patch with -p1
===>  Applying extra patch /usr/ports/net/samba416/files/0003-Mask-CLang-prototype-warnings-in-kadm5-admin.h.patch with -p1
===>  Applying extra patch /usr/ports/net/samba416/files/0004-On-FreeBSD-date-1-has-different-semantics-than-on-Li.patch with -p1
===>  Applying extra patch /usr/ports/net/samba416/files/0005-Include-jemalloc-jemalloc.h-if-ENABLE_JEMALLOC-is-se.patch with -p1
===>  Applying extra patch /usr/ports/net/samba416/files/0006-Install-nss_-modules-into-PAMMODULESDIR-path.patch with -p1
===>  Applying extra patch /usr/ports/net/samba416/files/0007-Use-macro-value-as-a-default-backlog-size-for-the-li.patch with -p1
===>  Applying extra patch /usr/ports/net/samba416/files/0008-Brute-force-work-around-usage-of-Linux-specific-m-fl.patch with -p1
===>  Applying extra patch /usr/ports/net/samba416/files/0009-Make-sure-that-config-checks-fail-if-the-warning-is-.patch with -p1
===>  Applying extra patch /usr/ports/net/samba416/files/0010-Add-option-with-pkgconfigdir-to-specify-alternative-.patch with -p1
===>  Applying extra patch /usr/ports/net/samba416/files/0011-Use-provided-by-port-location-of-the-XML-catalog.patch with -p1
===>  Applying extra patch /usr/ports/net/samba416/files/0012-Create-shared-libraries-according-to-the-FreeBSD-spe.patch with -p1
===>  Applying extra patch /usr/ports/net/samba416/files/0013-Pass-additional-msg-parameter-to-CHECK_LIB-so-it-can.patch with -p1
===>  Applying extra patch /usr/ports/net/samba416/files/0014-Add-option-to-disable-CTDB-tests-failing-on-FreeBSD-.patch with -p1
===>  Applying extra patch /usr/ports/net/samba416/files/0015-Add-extra-debug-class-to-trck-down-DB-locking-code.patch with -p1
===>  Applying extra patch /usr/ports/net/samba416/files/0016-Make-ldb_schema_attribute_compare-a-stable-comparisi.patch with -p1
===>  Applying extra patch /usr/ports/net/samba416/files/0017-Use-arc4random-when-available-to-generate-random-tal.patch with -p1
===>  Applying extra patch /usr/ports/net/samba416/files/0018-Add-configuration-option-that-allows-to-choose-alter.patch with -p1
===>  Applying extra patch /usr/ports/net/samba416/files/0019-From-923bc7a1afeb0b920e60e14846987ae1d2d7dca4-Mon-Se.patch with -p1
===>  Applying extra patch /usr/ports/net/samba416/files/0020-FreeBSD-12-between-r336017-and-r342928-wrongfuly-ret.patch with -p1
===>  Applying extra patch /usr/ports/net/samba416/files/0021-Fix-casting-warnings-in-the-nfs_quota-debug-message.patch with -p1
===>  Applying extra patch /usr/ports/net/samba416/files/0022-Clean-up-UTMP-handling-code-and-add-FreeBSD-support..patch with -p1
===>  Applying extra patch /usr/ports/net/samba416/files/0023-Add-cmd_get_quota-test-function-into-vfstest-to-test.patch with -p1
===>  Applying extra patch /usr/ports/net/samba416/files/0024-Cherry-pick-ZFS-provisioning-code-by-iXsystems-Inc.patch with -p1
===>  Applying extra patch /usr/ports/net/samba416/files/0025-From-d9b748869a8f4018ebee302aae8246bf29f60309-Mon-Se.patch with -p1
===>  Applying extra patch /usr/ports/net/samba416/files/0026-vfs-add-a-compatibility-option-to-the-vfs_streams_xa.patch with -p1
===>  Applying extra patch /usr/ports/net/samba416/files/0027-Add-VFS-module-vfs_freebsd-that-implements-FreeBSD-s.patch with -p1
===>  Applying extra patch /usr/ports/net/samba416/files/0028-s3-lib-system-add-FreeBSD-proc_fd_pattern.patch with -p1
===>  Applying extra patch /usr/ports/net/samba416/files/0029-Fix-rl_completion_func_t.patch with -p1
===>  Applying extra patch /usr/ports/net/samba416/files/0099-s3-modules-zfsacl-fix-get-set-ACL-on-FreeBSD-13.patch with -p1
===>  Applying extra patch /usr/ports/net/samba416/files/0099-s4-mitkdc-Add-support-for-MIT-Kerberos-1.20.patch with -p1
===>  Applying FreeBSD patches for samba416-4.16.11_5 from /usr/ports/net/samba416/files
root@freebsd:/usr/ports/net/samba416 #

Now I've go these in the files directory:

Code:
root@freebsd:/usr/ports/net/samba416/files # ls -l
total 248
-rw-r--r--  1 root wheel 11856 Oct 17  2022 0001-Compact-and-simplify-modules-build-and-config-genera.patch
-rw-r--r--  1 root wheel  1074 Oct 17  2022 0002-Adjust-abi_gen.sh-script-to-run-under-FreeBSD-with-i.patch
-rw-r--r--  1 root wheel   929 Oct 17  2022 0003-Mask-CLang-prototype-warnings-in-kadm5-admin.h.patch
-rw-r--r--  1 root wheel  1230 Oct 17  2022 0004-On-FreeBSD-date-1-has-different-semantics-than-on-Li.patch
-rw-r--r--  1 root wheel   774 Oct 17  2022 0005-Include-jemalloc-jemalloc.h-if-ENABLE_JEMALLOC-is-se.patch
-rw-r--r--  1 root wheel   970 Oct 17  2022 0006-Install-nss_-modules-into-PAMMODULESDIR-path.patch
-rw-r--r--  1 root wheel  3243 Oct 17  2022 0007-Use-macro-value-as-a-default-backlog-size-for-the-li.patch
-rw-r--r--  1 root wheel  3376 Oct 17  2022 0008-Brute-force-work-around-usage-of-Linux-specific-m-fl.patch
-rw-r--r--  1 root wheel  1697 Oct 17  2022 0009-Make-sure-that-config-checks-fail-if-the-warning-is-.patch
-rw-r--r--  1 root wheel  1747 Oct 17  2022 0010-Add-option-with-pkgconfigdir-to-specify-alternative-.patch
-rw-r--r--  1 root wheel  1241 Oct 17  2022 0011-Use-provided-by-port-location-of-the-XML-catalog.patch
-rw-r--r--  1 root wheel  1282 Oct 17  2022 0012-Create-shared-libraries-according-to-the-FreeBSD-spe.patch
-rw-r--r--  1 root wheel  3451 Oct 17  2022 0013-Pass-additional-msg-parameter-to-CHECK_LIB-so-it-can.patch
-rw-r--r--  1 root wheel  3077 Oct 17  2022 0014-Add-option-to-disable-CTDB-tests-failing-on-FreeBSD-.patch
-rw-r--r--  1 root wheel  3807 Oct 17  2022 0015-Add-extra-debug-class-to-trck-down-DB-locking-code.patch
-rw-r--r--  1 root wheel  1078 Oct 17  2022 0016-Make-ldb_schema_attribute_compare-a-stable-comparisi.patch
-rw-r--r--  1 root wheel  1343 Oct 17  2022 0017-Use-arc4random-when-available-to-generate-random-tal.patch
-rw-r--r--  1 root wheel  2461 Oct 17  2022 0018-Add-configuration-option-that-allows-to-choose-alter.patch
-rw-r--r--  1 root wheel 15707 Oct 17  2022 0019-From-923bc7a1afeb0b920e60e14846987ae1d2d7dca4-Mon-Se.patch
-rw-r--r--  1 root wheel  1503 Oct 17  2022 0020-FreeBSD-12-between-r336017-and-r342928-wrongfuly-ret.patch
-rw-r--r--  1 root wheel  1409 Oct 17  2022 0021-Fix-casting-warnings-in-the-nfs_quota-debug-message.patch
-rw-r--r--  1 root wheel 13141 Oct 17  2022 0022-Clean-up-UTMP-handling-code-and-add-FreeBSD-support..patch
-rw-r--r--  1 root wheel  3688 Oct 17  2022 0023-Add-cmd_get_quota-test-function-into-vfstest-to-test.patch
-rw-r--r--  1 root wheel 11355 Oct 17  2022 0024-Cherry-pick-ZFS-provisioning-code-by-iXsystems-Inc.patch
-rw-r--r--  1 root wheel  3264 Oct 17  2022 0025-From-d9b748869a8f4018ebee302aae8246bf29f60309-Mon-Se.patch
-rw-r--r--  1 root wheel 10860 Oct 17  2022 0026-vfs-add-a-compatibility-option-to-the-vfs_streams_xa.patch
-rw-r--r--  1 root wheel 26196 Oct 17  2022 0027-Add-VFS-module-vfs_freebsd-that-implements-FreeBSD-s.patch
-rw-r--r--  1 root wheel  3941 Oct 17  2022 0028-s3-lib-system-add-FreeBSD-proc_fd_pattern.patch
-rw-r--r--  1 root wheel  1062 Oct  2 14:31 0029-Fix-rl_completion_func_t.patch
-rw-r--r--  1 root wheel  2820 Oct 17  2022 0099-s3-modules-zfsacl-fix-get-set-ACL-on-FreeBSD-13.patch
-rw-r--r--  1 root wheel 31266 Dec 19  2022 0099-s4-mitkdc-Add-support-for-MIT-Kerberos-1.20.patch
-rw-r--r--  1 root wheel  3132 Oct 17  2022 README.FreeBSD.in
drwxr-xr-x  2 root wheel    70 Feb 28 13:07 man
-rw-r--r--  1 root wheel   473 Oct 17  2022 patch-examples_pdb_wscript__build
-rw-r--r--  1 root wheel  2505 Oct 17  2022 patch-lib_ldb_wscript
-rw-r--r--  1 root wheel   405 Oct 17  2022 patch-lib_talloc_wscript
-rw-r--r--  1 root wheel   973 Oct 17  2022 patch-lib_tdb_wscript
-rw-r--r--  1 root wheel   407 Oct 17  2022 patch-lib_util_wscript__build
-rw-r--r--  1 root wheel   434 Oct 17  2022 patch-source3_lib_util.c
-rw-r--r--  1 root wheel   511 Oct 17  2022 patch-source3_librpc_crypto_gse.c
-rw-r--r--  1 root wheel   607 Dec 24  2023 patch-source3_modules_vfs__cap.c
-rw-r--r--  1 root wheel  1101 Oct 17  2022 patch-source3_modules_vfs__virusfilter__utils.c
-rw-r--r--  1 root wheel   260 Oct 17  2022 patch-source3_registry_tests_test__regfio.c
-rw-r--r--  1 root wheel   389 Oct 17  2022 patch-source3_winbindd_wscript__build
-rw-r--r--  1 root wheel  1631 Oct 17  2022 patch-source3_wscript__build
-rw-r--r--  1 root wheel  1092 Oct 26  2022 pkg-message.in
-rw-r--r--  1 root wheel  8469 May 26  2024 samba_server.in
root@freebsd:/usr/ports/net/samba416/files #

What do I do now?
 
You don't go into the files directory. You go into work/<portname>

Yes, I see the source code is under /usr/ports/net/samba416/work-default/samba-4.16.11.

But when I open /usr/ports/net/samba416/work-default/samba-4.16.11/source3/modules/vfs_full_audit.c, I run into the same problem:

Code:
...
#include "includes.h"
...

There is no such file as includes.h in that directory, so it must be referring some file in some other directory, right? And I guess that information is somehow passed to the compiler, and that's all fine by me.

But imagine you're trying to write aC file to create some .so file to latch onto Samba's VFS subsystem using CodeBlocks, as described here. You must include the same header file, but that file, in return, includes others, and so on, and at some point the chain is broken, because there is no such file in the hierarchy. The code I downloaded looked like it was not written to be compiled on FreeBSD. Could this one be the same?

How would you go about it?
 
`make configure` needs to be done before you can build.
But I do not want to build. I want to enjoy the convenience of using an IDE to write my custom VFS module. I want to be able to compile by just clicking a button and see the errors I've made.
 
`make configure` does not build. It just runs ./configure (or similar), and that might generate the include files you are missing while running.
 
make configure sets up variables that lead to path modifications like "when I build where do I search for include files".
 
`make configure` does not build. It just runs ./configure (or similar), and that might generate the include files you are missing while running.
So I'd have to place my C file for my custom VFS module, make some modifications to Makefile, and do make configure and then make build every time? And use CodeBlocks just as a text editor?

Is there a more convenient way of doing this?
 
So I'd have to place my C file for my custom VFS module, make some modifications to Makefile, and do make configure and then make build every time? And use CodeBlocks just as a text editor?

Is there a more convenient way of doing this?

I don't know. What does Codeblocks require for full functionality?
 
I don't know. What does Codeblocks require for full functionality?
I think it can be configured to take into account the Makefile file during compilation. On the other hand, how would I know? I've barely scratched the surface here.

Can you help me with something else, though?

If I were to create a folder, say /root/project and created my code file vfs_template.c and the source code was to remain where it is, what would have I to have in the Makefile file?
 
Back
Top