IRIX Network Forums
How to have O2 compile my .c file each time I drop src into a folder - Printable Version

+- IRIX Network Forums (//forums.irixnet.org)
+-- Forum: SGI/MIPS (//forums.irixnet.org/forum-3.html)
+--- Forum: Development/Porting (//forums.irixnet.org/forum-9.html)
+--- Thread: How to have O2 compile my .c file each time I drop src into a folder (/thread-2685.html)



How to have O2 compile my .c file each time I drop src into a folder - KayBee - 01-29-2021

Hi Irixians, I need some advice.

Learning C and IRISGL on my O2 is super fun, but now I want to automate the compilation process a bit, since I am doing it so much manually from the command line. 
I am using the built-in IRIX compiler. I'd like to have IRIX watch a folder and when I drop a .c file in  it is compiled with the usual flags I use, overwriting the previous version.

Is anyone doing this with scripting or some other method? I am not sure where to start. This would also allow me to write code on the Mac, and drop it to the networked O2.

Thank you.

KB


RE: How to have O2 compile my .c file each time I drop src into a folder - Raion - 01-29-2021

Ok , so this is gonna be really clunky, really tricky, etc.

First off, there's no real way to do this other than a cron job, which basically is a task that runs at a specified interval.

https://ostechnix.com/a-beginners-guide-to-cron-jobs/

As for the script, you could have it do something like:

ls /directory/path/goes/here | grep "*.c" | xargs c99 -c

Or else you could customize it further. These will compile your files into "object files" which you then need to link

There are some downsides to this:

1. It can't tell if a file is complete or not, so you may end up with partially compiled trash, and if you miss the interval, you need to come around again on the next one.
2. Crons are very CPU intensive, so at best I'd run this every 2 mins or so to give the CPU some time to rest - doing something stupid like every 30 seconds is wasteful compute-wise.
3. You are limited to single .c files, no libraries, no h files etc.

libxg is a pretty simple project:

http://gitea.irixce.org/Raion/libxg

notice that the Makefile has to build each obj file, compile static libs (.a files) and shared files (.so files), and clean up and handle things. These are not things you can just idly hand off to automation, especially on an OS that's a bit more primitive.

You may be able to pull something off more clever and less clunky using Python, but that's even less efficient on IRIX.

I can't say I recommend this.


RE: How to have O2 compile my .c file each time I drop src into a folder - robespierre - 01-29-2021

I think there is a way to track files using the File Alteration Monitor (fam(3) and famd(8)). You could use them to run a daemon that wakes on files dropped into a directory.
See the documentation for fam: http://www.polarhome.com/service/man/?qf=fam&tf=2&of=NetBSD&sf=3

Your program would run in the background, creating a connection to the FAM daemon with FAMOpen(), then monitor a directory with FAMMonitorDirectory().
By calling FAMNextEvent(), you get info whenever something touches the directory. If the event was FAMCreated, you can use the filename in the event to pass to system() to run gcc.

cron is another option, but it can only run scripts periodically, not in response to files moved.


RE: How to have O2 compile my .c file each time I drop src into a folder - markh - 01-31-2021

If you are open to another way of doing this, you might consider storing your code in a version management system (for example subversion) and have a cron job that polls the repository each time. You should be able to detect if you got any new files and use that information to determine that you need to recompile your software.
This does get close to what a build server does, but I am not sure if there are any that are easy to setup and have a client that runs on Irix.
Setting up a subversion repository is easy and gives you history for your coding changes. It also avoids point 1 and 3 Raion mentioned.
I find that really handy even if I am the only person committing changes to it.