Author Topic: alink linker build under Linux  (Read 15351 times)

calip45

  • Guest
alink linker build under Linux
« on: February 12, 2009, 01:54:45 AM »
I needed a cross linker to run under Linux to create a 16 bit EXE from OBJ files.  The 'alink' linker package required some work to make this happen on my system.  I put this script together that others may find useful.  I haven't fully tested the linker but it seems to link my files ok.

Code: [Select]
#!/bin/bash
#
# Download, modify and build script to make the 'alink' linker compile under
# Linux. The web page for the linker is here: [url=http://alink.sourceforge.net/]http://alink.sourceforge.net/[/url]
# SJK 12/02/09

# Directory where the package will be built
APP_DIR=alink

# Check if we have a build directory and exit if the 'alink' binary file
# already exists. If not create the directory, download, modify and build
# the package.
if [ -d $APP_DIR ]; then
   if [ -f $APP_DIR/alink ]; then
      echo "'alink' binary exists. To rebuild remove it or the build directory."
      exit 0
   else
      rm -f $APP_DIR/*
   fi
else
   mkdir $APP_DIR
fi  

cd $APP_DIR

# Download and unzip the package files
wget [url=http://alink.sourceforge.net/files/alinksrc.zip]http://alink.sourceforge.net/files/alinksrc.zip[/url]
unzip alinksrc.zip

# Rename all source and header files to use lower case
mv ALINK.C alink.c
mv ALINK.H alink.h
mv COFF.C coff.c
mv COFFLIB.C cofflib.c
mv COMBINE.C combine.c
mv OBJLOAD.C objload.c
mv OUTPUT.C output.c
mv UTIL.C util.c

# Create a new Makefile for Linux (note escaped dollar characters)
echo "
%.o: %.c
    gcc -c -o \$@ $<

all: alink

alink.o combine.o util.o output.o objload.o coff.o cofflib.o : alink.h

alink: alink.o combine.o util.o output.o objload.o coff.o cofflib.o
    gcc -o \$@ $^
" > Makefile_linux

# Append this to the alink.h file
echo "
/* Added SJK 12/02/09 */
#ifdef __linux__
#define stricmp strcasecmp
char *strupr (char *a);
char *strdup (const char *string);
#endif
" >> alink.h

# Append this to the util.c file
echo "
/* Added SJK 12/02/09 */
#ifdef __linux__
char *strupr (char *a)
{
 char *ret = a;

while (*a != '\0')
    {
     if (islower(*a))
        *a = toupper(*a);
     ++a;
    }
 return ret;
}

char *strdup (const char *string)
{
 char *new;

if (NULL != (new = malloc(strlen(string) + 1)))
    strcpy(new, string);
 return new;
}
#endif
" >> util.c

# Compile the program
make -f Makefile_linux

Offline Frank Kotler

  • NASM Developer
  • Hero Member
  • *****
  • Posts: 2667
  • Country: us
Re: alink linker build under Linux
« Reply #1 on: February 12, 2009, 07:08:10 PM »
Only an "interim report" so far...

Jeez, "cross-linked files" sounds like a really bad bug! :)

I have to admit that I meddled with your script a bit. I've got a "dir2lower" that I needed an excuse to test, so I did the d/l - and directory creation - and unzip (I used the "-a" switch - "by hand", and snipped that out of your script. I think the trouble I've been having is more related to the forum software "improving" your formatting. For example, make hollers "missing separator!"... tabs have helpfully been replaced by spaces. Getting by that, I'm getting complaints about "NULL" not being defined (replaced 'em with 0 "by hand"). Discovered that the additions to alink.c and utils.c were failing... Ummm, looking closer, I've got alink/alink/ with the latest Makefile_linux and some partial files in it - my fault. I'm going to have to go back to square zero and have another shot at it. I attempted to fix it by cut/pasting the additions by hand... C's still yelling at me about strdup... I thought this C-cruft was supposed to be portable!!! :)

Attempting to port Alink has been on my long-term TODO list for a long time, so your tips on how to get it to build are most welcome! I'm not sure the "one big script" is the best approach, but I think I can get it to work, with a little more fiddling.

I should note that there's a "patched" version of Alink in the files section of the Yahoo win32-nasm-users group. I don't recall what it's supposed to fix, and I don't know whether Anthony's incorporated these changes into his latest version (looks like some pretty old file dates, so maybe not...). I'll look into that if I can get the "regular" version working...

As a potential alternative, Japheth's got a Linux binary of OpenWatcom's Wlink available for download:

http://www.japheth.de/JWasm.html

Dunno what its capabilities are, but it might be something for those interested in "cross-linked files" to look into...

Maybe more later... (anyone interested in that "dir2lower"? "Seems to work" for those pesky uppercase dos filenames. Very rudimentary.)

Best,
Frank

Offline Frank Kotler

  • NASM Developer
  • Hero Member
  • *****
  • Posts: 2667
  • Country: us
Re: alink linker build under Linux
« Reply #2 on: February 12, 2009, 09:01:33 PM »
Bingo! All errors were the result of my trying to tweak your method. Not so much as a warning out of gcc!

Thanks!

Best,
Frank

calip45

  • Guest
Re: alink linker build under Linux
« Reply #3 on: February 13, 2009, 01:35:13 AM »
Thanks for your feedback Frank,  please tweak it as you see fit.  I have since changed a few things myself.  For my use the script will be called from a Makefile for a project I'm planning on releasing on SF soon so I wanted an easy way to get a linker happening without the user having to compile something separately and using patch files.  A modified script without the downloading might be more practical for general use.

When I placed the script in a make file the echoing to the files was being truncated in one place on the escape character found in this bit off added code, adding another escape did not fix the problem for both cases when the script was run under bash directly or from a Makefile.

while (*a != '\0')

I've made some changes using 'cat' that seems to work ok for both.  I could also have changed the testing for the 0.

Also I should be defining the strupr() and strdup() functions with my own names as the leading 'str' in function names is reserved for use by 'C' programs.

I'll post back my changes when I've finished.

Stewart