# Adding a patch to a port with multiple distribution files



## jonyepsilon (Nov 6, 2022)

Hi,

 I'm trying to add a patch to a port (databases/postgresql-promscale). The port downloads multiple distribution files from github (using this mechanism). The patch I want to create applies to a file not in the main port distfile (promscale_extension) but in the secondary distfile (pgx, which is assigned the pgx group in the Makefile). I can't for the life of me figure out how to create/apply the patch!

If I `make extract`, copy an `.orig` file and edit, then `make makepatch` ... nothing happens. If I create the patch by hand and put it in `files` then `make patch` fails, and debugging with `DEBUG_MK_SCRIPTS_DO_PATCH` shows that the make script is trying to apply the patch to the main wrksrc directory, which of course doesn't work because that's not where the file is.

Any clues on how to make this work?

Thanks,

Jony


----------



## zirias@ (Nov 7, 2022)

Set `PATCH_WRKSRC` accordingly. If you only need to patch in one extracted directory, e.g. `bundled-foo-1.0`, set it to `${WRKDIR}/bundled-foo-1.0`. If you need patches in multiple extracted directories, just setting it to `${WRKDIR}` should work (which of course requires regenerating already existing patches because the paths change...)


----------



## jonyepsilon (Nov 8, 2022)

Thanks! I got it working with the blunt:


```
@${PATCH} -d ${WRKDIR} ${PATCH_ARGS} < ${PATCHDIR}/pgx-include-patch
```

in a pre-configure target, but I think your suggestion is more elegant


----------

