How to Rebuild Rules.mk Config File on the IBM i HOST Side

Before we look at the manual IBM i Technique to rebuild the Rules.mk files -- I recommend using the LOCAL BUILD option from the PROJECT EXPLORER as the main alternative. You can see this in action here.

However, if you really want to continue with doing it manually on the IBM i Side then this is how you do it:

What is Rules.mk?

In VSCode IBM i Source Orbit, Rules.mk is a makefile that contains build rules and dependencies for your IBM i source code. 

Rules.mk is a crucial file that helps manage the compilation and build process of your IBM i programs.

It's an auto-generated file that's created by components of the Code for IBM i Extension when you create a new project or import an existing one.

The file contains a set of rules and dependencies that define how to compile and build your IBM i source code, including:

  • Source file dependencies: rules.mk specifies which source files depend on each other, ensuring that changes to one file trigger recompilation of dependent files.
  • Compiler options: The file defines compiler options, such as the compiler to use, optimization levels, and debugging settings.
  • Build targets: rules.mk specifies the build targets, including the output file names and locations.

When you rebuild rules.mk, VSCode regenerates the file based on the current state of your project, including any changes to source files, dependencies, or compiler options. 

This ensures that your build process is up-to-date and accurate.

Some common reasons to rebuild rules.mk include:

  • Adding or removing source files from your project
  • Changing compiler options or build settings
  • Updating dependencies between source files
  • Resolving build errors or warnings

By rebuilding rules.mk, you ensure that your IBM i project is properly configured and ready for compilation and deployment.

Rebuild rules.mk in VSCode for IBM i

It's easier than you think - but not necessarily intuitive if you are new to the VSCode world. 

I wish we could simply right click on the Rules.mk and select REBUILD... but... as of right now we cannot. Luckily, we can rebuild the Rules.mk file manually without any difficulty.

I open a QSHELL terminal against the IFS location for my workspace and use the SOURCE ORBIT command (SO) to rebuild the Rules.MK file. Then I download that to my local workspace and *boom* we are good.

A real example of rebuilding Rules.mk

Here I have manually imported, edited, deleted and renamed lots of different SQL Tables, new logicals and some other database objects on my PC.

So the idea is:

  • Sync my local folders to the IFS
  • Use Source Orbit to rebuild the *correct* Rules.mk file for the IFS folders
  • Download those Rules.mk files back to my PC to get myself all clean and smiling

1 - Sync with Project Explorer

Goto the Project Explorer Panel and click Deploy Project to sync our local code to our IFS location.

In my example below, you can see I am working with a workspace called Projex4i which is linked to /home/projex4i on my IBM i System:

sync with project explorer

Once you see the Deployment Finished message you are ready to rebuild the Rules.mk file.

How to Rebuild Rules.mk Config File on the IBM i HOST Side 1

2 - Use the IFS Browser to load a Terminal Shell

Now we are going to switch to the IFS BROWSER panel and OPEN A TERMINAL at the root of our workspace.

How to Rebuild Rules.mk Config File on the IBM i HOST Side 2

This opens a terminal CLI already based at the correct location. (Of course, you could also have just opened any existing terminal window and use the CHDIR command to jump to the correct IFS location)

Now we are going use the SO command like this:

so -bf bob

As it runs you will see the status of each program as all the Rules.MK files are rebuilt in the IFS.

In my example below, you can see it spitting out all kind of errors found some service programs I am modernizing where the rebuild is showing me that I need to pull in the correct references that are missing. Very cool 🙂

so bf bob

3 - Download the freshly generated Rules.mk files to my local PC

I use simply right click the Rules.mk files in the IFS and download back into my original PC location replacing the original faulty Rules.mk files.

How to Rebuild Rules.mk Config File on the IBM i HOST Side 3

Thats it!

When you go back to your local workspace you will see the freshly updated version of your Rules.mk

Now ready for you to deploy, compile and continue your coding adventures.

{"email":"Email address invalid","url":"Website address invalid","required":"Required field missing"}
>