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.
#!/bin/bash
#
# Download, modify and build script to make the 'alink' linker compile under
# Linux. The web page for the linker is here: http://alink.sourceforge.net/
# 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
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:
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
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Anonymous
-
2009-02-13
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
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Anonymous
-
2009-02-13
This will make unzip force all the files to lower case so no need to rename:
unzip -LL alinksrc.zip
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Ah! I figured there was probably a switch for that. Well, I had fun with "dir2lower" anyway...
Best,
Frank
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Anonymous
-
2009-02-13
Changes:
- Unzip files to lower case and remove the renaming stuff.
- Changed all 'linux' references to 'unix' so should compile on FreeBSD, etc.
- Used 'cat' command for concatenating files.
- Changed 'while (*a != '\0')' to 'while (*a)'.
- Changed the added strupr() function to xstrupr() and add a define for it.
- The strdup function was being redefined to _strdup stopping it compiling. I defined it back to strdup and removed the added strdup code.
Stewart
#!/bin/bash
#
# Download, modify and build script to make the 'alink' linker compile under
# Unix. The web page for the linker is here: http://alink.sourceforge.net/
# SJK 13 Feb 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
# Append this to the alink.h file
cat >> alink.h << EOT
/* Added SJK 13 Feb 09 */
#ifdef __unix__
#ifndef alink_mod
#define alink_mod
#define stricmp strcasecmp
#define strupr xstrupr
/* strdup got redefined! put this back to strdup */
#define _strdup strdup
char *xstrupr (char *a);
#endif
#endif
EOT
# Append this to the util.c file (note double escape characters)
cat >> util.c << EOT
/* Added SJK 13 Feb 09 */
#ifdef __unix__
char *xstrupr (char *a)
{
char *ret = a;
while (*a)
{
if (islower(*a))
*a = toupper(*a);
++a;
}
return ret;
}
#endif
EOT
# Compile the program
make -f Makefile_unix
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Anonymous
-
2009-02-27
An improved script making use of parameters and ALINK version checking can be found in the scripts directory in the source .gz file for my project that required it:
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.
#!/bin/bash
#
# Download, modify and build script to make the 'alink' linker compile under
# Linux. The web page for the linker is here: http://alink.sourceforge.net/
# 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 http://alink.sourceforge.net/files/alinksrc.zip
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
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
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
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
This will make unzip force all the files to lower case so no need to rename:
unzip -LL alinksrc.zip
Ah! I figured there was probably a switch for that. Well, I had fun with "dir2lower" anyway...
Best,
Frank
Changes:
- Unzip files to lower case and remove the renaming stuff.
- Changed all 'linux' references to 'unix' so should compile on FreeBSD, etc.
- Used 'cat' command for concatenating files.
- Changed 'while (*a != '\0')' to 'while (*a)'.
- Changed the added strupr() function to xstrupr() and add a define for it.
- The strdup function was being redefined to _strdup stopping it compiling. I defined it back to strdup and removed the added strdup code.
Stewart
#!/bin/bash
#
# Download, modify and build script to make the 'alink' linker compile under
# Unix. The web page for the linker is here: http://alink.sourceforge.net/
# SJK 13 Feb 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 http://alink.sourceforge.net/files/alinksrc.zip
#cp ../../alinksrc.zip .
# extract all files forcing names to lower case
unzip -LL alinksrc.zip
# Create a new Makefile for Unix (note escaped dollar characters)
cat >> Makefile_unix << EOT
%.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 \$@ $^
EOT
# Append this to the alink.h file
cat >> alink.h << EOT
/* Added SJK 13 Feb 09 */
#ifdef __unix__
#ifndef alink_mod
#define alink_mod
#define stricmp strcasecmp
#define strupr xstrupr
/* strdup got redefined! put this back to strdup */
#define _strdup strdup
char *xstrupr (char *a);
#endif
#endif
EOT
# Append this to the util.c file (note double escape characters)
cat >> util.c << EOT
/* Added SJK 13 Feb 09 */
#ifdef __unix__
char *xstrupr (char *a)
{
char *ret = a;
while (*a)
{
if (islower(*a))
*a = toupper(*a);
++a;
}
return ret;
}
#endif
EOT
# Compile the program
make -f Makefile_unix
An improved script making use of parameters and ALINK version checking can be found in the scripts directory in the source .gz file for my project that required it:
http://sourceforge.net/projects/z80em86/
Stewart