Jump to content
IGNORED

MADS: Include all in a directory?


snicklin

Recommended Posts

Is it possible in MADS to include everything in a directory?

 

I want to do something like this:

 

icl 'lib/macros/*.mac'

 

I could write some build script to sort it all out, but if there is any built-in way to do this, I'd rather use this.

 

If it isn't technically possible, TeBe, could this be added in a future version?

 

Link to comment
Share on other sites

I think that if it is not technically possible, Tebe can't add it in future version :)

 

Ooh you cheeky monkey!

 

OK, I'll rephrase that - "If it isn't technically possible in the current version of MADS, TeBe, could this be added in a future version?".

 

It'd be a useful feature. Every time that I add a new macro to a directory, I don't really want to have to update another file to say to include it.

Link to comment
Share on other sites

It's quite simple using gnu make tool.

When you place your macros in ./macros/ subdirectory and sources in ./ directory you can create ./Makefile file:

MACRODIR=macros
OBJS=test1.xex test2.xex

all: macros.asm $(OBJS)

%.xex: %.asm
        mads -m:macros.asm -o:$@ $<

macros.asm: $(MACRODIR)/*
        cat $^ >$@

clean:
        rm -f macros.asm $(OBJS)

.PHONY: all clean

This buildfile makes ./macros.asm file as concatenation of all ./macros/* files and finally calls mads assembler for each OBJS with -m:macros.asm.

 

OBJS contains space separated names of executables for your sources (test1.xex for test1.asm, test2.xex for test2.asm etc.).

No macro file in ./macros/ subdir can't ends with 'end' directive.

 

Now doing

make

will build your project, but

make clean

will clean generated files (macros.asm and all .xex files).

 

Concatenation all macro files into one is required by mads because only one -m parameter is allowed.

If multiple -m would be allowed (maybe in the future) then Makefile could be:

MACRODIR=macros
OBJS=test1.xex test2.xex

all: $(OBJS)

%.xex: %.asm
       for m in $(MACRODIR)/*; do echo "-m:$$m"; done | xargs mads -o:$@ $<

clean:
        rm -f $(OBJS)

.PHONY: all clean

and temporary macros.asm woudln't be created.

 

I recommend make tool for automatic management of project and do many jobs without waiting for new mads feature requests will be implemented.

  • Like 1
Link to comment
Share on other sites

It's quite simple using gnu make tool.

 

Thank you for your input into this. The only issue that I have here is that it will require me to rewrite the whole build system which I've created (and it is pretty elaborate). I've used 'make' before, but it's too much of an upheaval to do this.

 

I've added all my macros into an include file and this brings them all in. I think even that if MADS was to support *.mac then it would also need to be able to recursively go downwards into subdirectories.

 

I may just write a short Perl script to list all the .mac files underneath a directory and then write them to a file in a format that I can include that output file into the project. This won't be a big deal but isn't as neat as if the functionality was there.

 

Thank you though, I'm grateful for your input here.

Link to comment
Share on other sites

Although I am running Linux Mint, I've got a Windows VM booted up for my development environment, so the 'find' command can't be used in this case. I cannot revert this because other tools in the build chain rely on Windows.

 

When I first started this thread, I had all my macros in one directory. Since then I've split them up into different directories underneath a 'macro' directory.

 

@Heaven/TQA, not to copy the files, just to list them all out so that they can be included in MADS. Currently I have code like below and I have to add a new line to it every time that I add a new macro. If I could just do - icl -R 'lib/macros' '*.mac' then this could pick up all of the macros below this directory.

 

icl 'lib/macros/stack/@call.mac'
icl 'lib/macros/stack/@pull.mac'
icl 'lib/macros/stack/@exit.mac'
icl 'lib/macros/stack/pushAll.mac'
icl 'lib/macros/stack/pullAll.mac'
icl 'lib/macros/mSetGameStage.mac'

etc etc

 

No worries anyway, I'll write a little Perl script, won't take long.

Link to comment
Share on other sites

Just in-case anyone else is interested (and uses Perl on Windows), I've got a quick hack solution to this. It's not that neat in that it calls 'dir' in Windows, but it does the job.

use Cwd;

sub writeAllFilesOfTypeRecursive
{
    my $direc=shift;
    my $qualifier=shift;
    my $output=shift;

    if("$direc" eq "" || "$qualifier" eq "")
    {
        die("Error: writeAllFilesOfType ($dir) ($qualifier) called without 'directory' or 'qualifier'\n");
    }
    $ori_wd=cwd();
    chdir "$direc";

    @files=`dir /N /s /B $qualifier`;
    chdir "$ori_wd";

    $prwd=cwd();
    print "File list: $prwd\n";
    print @files;
    open(FILE,">$output");
        foreach $entry (@files)
        {
             chomp($entry);
             print FILE "    icl \'$entry\'\n";   
        }
    close(FILE);
}
writeAllFilesOfTypeRecursive("lib/macros","*.mac","macroList.asm");

Then you just need to include 'macroList.asm' into your build.

Edited by snicklin
  • Like 1
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...