How to have O2 compile my .c file each time I drop src into a folder
#1
How to have O2 compile my .c file each time I drop src into a folder
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
(This post was last modified: 01-29-2021, 08:08 PM by KayBee.)
KayBee
Octane

Trade Count: (0)
Posts: 132
Threads: 40
Joined: Feb 2020
Find Reply
01-29-2021, 08:00 PM
#2
RE: How to have O2 compile my .c file each time I drop src into a folder
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.

I'm the system admin of this site. Private security technician, licensed locksmith, hack of a c developer and vintage computer enthusiast. 

https://contrib.irixnet.org/raion/ -- contributions and pieces that I'm working on currently. 

https://codeberg.org/SolusRaion -- Code repos I control

Technical problems should be sent my way.
Raion
Chief IRIX Officer

Trade Count: (9)
Posts: 4,239
Threads: 533
Joined: Nov 2017
Location: Eastern Virginia
Website Find Reply
01-29-2021, 08:54 PM
#3
RE: How to have O2 compile my .c file each time I drop src into a folder
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...etBSD&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.

Personaliris O2 Indigo2 R10000/IMPACT Indigo2 R10000/IMPACT Indigo2 Indy   (past: 4D70GT)
robespierre
refector peritus

Trade Count: (0)
Posts: 640
Threads: 3
Joined: Nov 2020
Location: Massholium
Find Reply
01-29-2021, 10:21 PM
#4
RE: How to have O2 compile my .c file each time I drop src into a folder
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.
markh
Developer

Trade Count: (0)
Posts: 25
Threads: 4
Joined: Jan 2021
Location: The Netherlands
Find Reply
01-31-2021, 02:59 PM


Forum Jump:


Users browsing this thread: 1 Guest(s)