From 907b549d585c74537b300c188b00d3a56d36cc7f Mon Sep 17 00:00:00 2001 From: hpa Date: Wed, 15 Dec 2004 10:28:29 +0000 Subject: Change the win32 build procedure to match the new world; installer not yet ported --- win32/Makefile | 56 +++++------- win32/syslinux-mingw.c | 234 ------------------------------------------------- win32/syslinux.c | 234 +++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 258 insertions(+), 266 deletions(-) delete mode 100644 win32/syslinux-mingw.c create mode 100644 win32/syslinux.c (limited to 'win32') diff --git a/win32/Makefile b/win32/Makefile index bd957fa4..f01369ab 100644 --- a/win32/Makefile +++ b/win32/Makefile @@ -36,54 +36,46 @@ CC = mingw-gcc AR = mingw-ar RANLIB = mingw-ranlib endif -CC_IS_GOOD := $(shell $(CC) $(CFLAGS) $(LDFLAGS) -o hello.exe hello.c >/dev/null 2>&1 ; echo $$?) CFLAGS = -W -Wall -O2 -fomit-frame-pointer -D_FILE_OFFSET_BITS=64 PIC = LDFLAGS = -O2 -s endif -INCLUDE += -I.. +CFLAGS += -I. -I.. -I../libfat -PERL = perl +CC_IS_GOOD := $(shell $(CC) $(CFLAGS) $(LDFLAGS) -o hello.exe hello.c >/dev/null 2>&1 ; echo $$?) -VERSION = $(shell cat ../version) +.SUFFIXES: .c .o .i .s .S -.c.o: - $(CC) $(INCLUDE) $(CFLAGS) -c -o $@ $< +SRCS = syslinux.c ../syslxmod.c ../bootsect_bin.c ../ldlinux_bin.c $(wildcard ../libfat/*.c) +OBJS = $(patsubst %.c,%.o,$(notdir $(SRCS))) -.c.i: - $(CC) $(INCLUDE) $(CFLAGS) -E -o $@ $< +VPATH = .:..:../libfat -ifeq ($(CC_IS_GOOD),0) -all: ../syslinux.exe -else -all: # We don't have a working win32 compiler - rm -f ../syslinux.exe -endif +all: installer -libsyslinux.a: bootsect_bin.o ldlinux_bin.o syslxmod.o - rm -f $@ - $(AR) cq $@ $^ - $(RANLIB) $@ +tidy: + -rm -f *.o *.i *.s *.a .*.d -../syslinux.exe: syslinux-mingw.o libsyslinux.a - $(CC) $(LDFLAGS) -o $@ $^ +clean: tidy + -rm -f syslinux.exe -syslxmod.o: ../syslxmod.c ../patch.offset - $(CC) $(INCLUDE) $(CFLAGS) $(PIC) -DPATCH_OFFSET=`cat ../patch.offset` \ - -c -o $@ $< +spotless: clean + -rm -f *~ -bootsect_bin.o: ../bootsect_bin.c - $(CC) $(INCLUDE) $(CFLAGS) -c -o $@ $< +installer: syslinux.exe -ldlinux_bin.o: ../ldlinux_bin.c - $(CC) $(INCLUDE) $(CFLAGS) -c -o $@ $< +syslinux.exe: $(OBJS) + $(CC) $(LDFLAGS) -o $@ $^ -tidy: - rm -f *.o *.a hello.exe +%.o: %.c + $(CC) -Wp,-MT,$@,-MMD,.$@.d $(CFLAGS) -c -o $@ $< +%.i: %.c + $(CC) $(CFLAGS) -E -o $@ $< +%.s: %.c + $(CC) $(CFLAGS) -S -o $@ $< + +-include .*.d -clean: tidy -spotless: clean - rm -f ../syslinux.exe *~ diff --git a/win32/syslinux-mingw.c b/win32/syslinux-mingw.c deleted file mode 100644 index 0b6b1926..00000000 --- a/win32/syslinux-mingw.c +++ /dev/null @@ -1,234 +0,0 @@ -/* ----------------------------------------------------------------------- * - * - * Copyright 2003 Lars Munch Christensen - All Rights Reserved - * - * Based on the Linux installer program for SYSLINUX by H. Peter Anvin - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, Inc., 53 Temple Place Ste 330, - * Boston MA 02111-1307, USA; either version 2 of the License, or - * (at your option) any later version; incorporated herein by reference. - * - * ----------------------------------------------------------------------- */ - -/* - * syslinux-mingw.c - Win2k/WinXP installer program for SYSLINUX - */ - -#include -#include -#include - -#include "syslinux.h" - -char *program; /* Name of program */ -char *drive; /* Drive to install to */ - -/* - * Check Windows version. - * - * On Windows Me/98/95 you cannot open a directory, physical disk, or - * volume using CreateFile. - */ -int checkver() -{ - OSVERSIONINFO osvi; - - osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO); - GetVersionEx(&osvi); - - return (osvi.dwPlatformId == VER_PLATFORM_WIN32_NT) && - ((osvi.dwMajorVersion > 4) || - ((osvi.dwMajorVersion == 4) && (osvi.dwMinorVersion == 0))); -} - -/* - * Windows error function - */ -void error(char* msg) -{ - LPVOID lpMsgBuf; - - /* Format the Windows error message */ - FormatMessage( - FORMAT_MESSAGE_ALLOCATE_BUFFER | - FORMAT_MESSAGE_FROM_SYSTEM | - FORMAT_MESSAGE_IGNORE_INSERTS, - NULL, GetLastError(), - MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language - (LPTSTR) &lpMsgBuf, 0, NULL ); - - /* Print it */ - fprintf(stderr, "%s: %s", msg, (char*) lpMsgBuf); - - /* Free the buffer */ - LocalFree(lpMsgBuf); -} - -void usage(void) -{ - fprintf(stderr, "Usage: syslinux.exe [-sf] :\n"); - exit(1); -} - -int main(int argc, char *argv[]) -{ - HANDLE f_handle; - DWORD bytes_read; - DWORD bytes_written; - DWORD drives; - UINT drive_type; - - static unsigned char sectbuf[512]; - char **argp, *opt; - char drive_name[128]; - char ldlinux_name[128]; - - int force = 0; /* -f (force) option */ - - if (!checkver()) { - fprintf(stderr, "You need to be running at least Windows NT\n"); - exit(1); - } - - program = argv[0]; - drive = NULL; - - for ( argp = argv+1 ; *argp ; argp++ ) { - if ( **argp == '-' ) { - opt = *argp + 1; - if ( !*opt ) - usage(); - - while ( *opt ) { - if ( *opt == 's' ) { - syslinux_make_stupid(); /* Use "safe, slow and stupid" code */ - } else if ( *opt == 'f' ) { - force = 1; /* Force install */ - } else { - usage(); - } - opt++; - } - } else { - if ( drive ) - usage(); - drive = *argp; - } - } - - if ( !drive ) - usage(); - - /* Test if drive exists */ - drives = GetLogicalDrives(); - if(!(drives & ( 1 << (tolower(drive[0]) - 'a')))) { - fprintf(stderr, "No such drive %c:\n", drive[0]); - exit(1); - } - - /* Determines the drive type */ - sprintf(drive_name, "%c:\\", drive[0]); - drive_type = GetDriveType(drive_name); - - /* Test for removeable media */ - if ((drive_type == DRIVE_FIXED) && (force == 0)) { - fprintf(stderr, "Not a removable drive (use -f to override) \n"); - exit(1); - } - - /* Test for unsupported media */ - if ((drive_type != DRIVE_FIXED) && (drive_type != DRIVE_REMOVABLE)) { - fprintf(stderr, "Unsupported media\n"); - exit(1); - } - - /* - * First open the drive - */ - sprintf(drive_name, "\\\\.\\%c:", drive[0]); - f_handle = CreateFile(drive_name, GENERIC_READ | GENERIC_WRITE, - FILE_SHARE_READ | FILE_SHARE_WRITE, - NULL, OPEN_EXISTING, 0, NULL ); - - if(f_handle == INVALID_HANDLE_VALUE) { - error("Could not open drive"); - exit(1); - } - - /* - * Read the boot sector - */ - ReadFile(f_handle, sectbuf, 512, &bytes_read, NULL); - if(bytes_read != 512) { - fprintf(stderr, "Could not read the whole boot sector\n"); - exit(1); - } - - /* Check to see that what we got was indeed an MS-DOS boot sector/superblock */ - if(!syslinux_check_bootsect(sectbuf,drive)) { - exit(1); - } - - /* Make the syslinux boot sector */ - syslinux_make_bootsect(sectbuf); - - /* Write the syslinux boot sector into the boot sector */ - SetFilePointer(f_handle, 0, NULL, FILE_BEGIN); - WriteFile( (HANDLE) f_handle, sectbuf, 512, &bytes_written, NULL ) ; - - if(bytes_written != 512) { - fprintf(stderr, "Could not write the whole boot sector\n"); - exit(1); - } - - /* Close file */ - CloseHandle(f_handle); - - /* Create the filename */ - sprintf(ldlinux_name, "%s%s", drive_name, "\\ldlinux.sys"); - - /* Change to normal attributes to enable deletion */ - /* Just ignore error if the file do not exists */ - SetFileAttributes(ldlinux_name, FILE_ATTRIBUTE_NORMAL); - - /* Delete the file */ - /* Just ignore error if the file do not exists */ - DeleteFile(ldlinux_name); - - /* Create ldlinux.sys file */ - f_handle = CreateFile(ldlinux_name, GENERIC_READ | GENERIC_WRITE, - FILE_SHARE_READ | FILE_SHARE_WRITE, - NULL, CREATE_ALWAYS, - FILE_ATTRIBUTE_ARCHIVE | FILE_ATTRIBUTE_READONLY, - NULL ); - - if(f_handle == INVALID_HANDLE_VALUE) { - error("Unable to create ldlinux.sys"); - exit(1); - } - - /* Write ldlinux.sys file */ - if (!WriteFile(f_handle, syslinux_ldlinux, syslinux_ldlinux_len, &bytes_written, NULL)) { - error("Could not write ldlinux.sys"); - exit(1); - } - - if (bytes_written != syslinux_ldlinux_len) { - fprintf(stderr, "Could not write whole ldlinux.sys\n"); - exit(1); - } - - /* Now flush the media */ - if(!FlushFileBuffers(f_handle)) { - error("FlushFileBuffers failed"); - exit(1); - } - - /* Close file */ - CloseHandle(f_handle); - - /* Done! */ - return 0; -} diff --git a/win32/syslinux.c b/win32/syslinux.c new file mode 100644 index 00000000..0b6b1926 --- /dev/null +++ b/win32/syslinux.c @@ -0,0 +1,234 @@ +/* ----------------------------------------------------------------------- * + * + * Copyright 2003 Lars Munch Christensen - All Rights Reserved + * + * Based on the Linux installer program for SYSLINUX by H. Peter Anvin + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, Inc., 53 Temple Place Ste 330, + * Boston MA 02111-1307, USA; either version 2 of the License, or + * (at your option) any later version; incorporated herein by reference. + * + * ----------------------------------------------------------------------- */ + +/* + * syslinux-mingw.c - Win2k/WinXP installer program for SYSLINUX + */ + +#include +#include +#include + +#include "syslinux.h" + +char *program; /* Name of program */ +char *drive; /* Drive to install to */ + +/* + * Check Windows version. + * + * On Windows Me/98/95 you cannot open a directory, physical disk, or + * volume using CreateFile. + */ +int checkver() +{ + OSVERSIONINFO osvi; + + osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO); + GetVersionEx(&osvi); + + return (osvi.dwPlatformId == VER_PLATFORM_WIN32_NT) && + ((osvi.dwMajorVersion > 4) || + ((osvi.dwMajorVersion == 4) && (osvi.dwMinorVersion == 0))); +} + +/* + * Windows error function + */ +void error(char* msg) +{ + LPVOID lpMsgBuf; + + /* Format the Windows error message */ + FormatMessage( + FORMAT_MESSAGE_ALLOCATE_BUFFER | + FORMAT_MESSAGE_FROM_SYSTEM | + FORMAT_MESSAGE_IGNORE_INSERTS, + NULL, GetLastError(), + MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language + (LPTSTR) &lpMsgBuf, 0, NULL ); + + /* Print it */ + fprintf(stderr, "%s: %s", msg, (char*) lpMsgBuf); + + /* Free the buffer */ + LocalFree(lpMsgBuf); +} + +void usage(void) +{ + fprintf(stderr, "Usage: syslinux.exe [-sf] :\n"); + exit(1); +} + +int main(int argc, char *argv[]) +{ + HANDLE f_handle; + DWORD bytes_read; + DWORD bytes_written; + DWORD drives; + UINT drive_type; + + static unsigned char sectbuf[512]; + char **argp, *opt; + char drive_name[128]; + char ldlinux_name[128]; + + int force = 0; /* -f (force) option */ + + if (!checkver()) { + fprintf(stderr, "You need to be running at least Windows NT\n"); + exit(1); + } + + program = argv[0]; + drive = NULL; + + for ( argp = argv+1 ; *argp ; argp++ ) { + if ( **argp == '-' ) { + opt = *argp + 1; + if ( !*opt ) + usage(); + + while ( *opt ) { + if ( *opt == 's' ) { + syslinux_make_stupid(); /* Use "safe, slow and stupid" code */ + } else if ( *opt == 'f' ) { + force = 1; /* Force install */ + } else { + usage(); + } + opt++; + } + } else { + if ( drive ) + usage(); + drive = *argp; + } + } + + if ( !drive ) + usage(); + + /* Test if drive exists */ + drives = GetLogicalDrives(); + if(!(drives & ( 1 << (tolower(drive[0]) - 'a')))) { + fprintf(stderr, "No such drive %c:\n", drive[0]); + exit(1); + } + + /* Determines the drive type */ + sprintf(drive_name, "%c:\\", drive[0]); + drive_type = GetDriveType(drive_name); + + /* Test for removeable media */ + if ((drive_type == DRIVE_FIXED) && (force == 0)) { + fprintf(stderr, "Not a removable drive (use -f to override) \n"); + exit(1); + } + + /* Test for unsupported media */ + if ((drive_type != DRIVE_FIXED) && (drive_type != DRIVE_REMOVABLE)) { + fprintf(stderr, "Unsupported media\n"); + exit(1); + } + + /* + * First open the drive + */ + sprintf(drive_name, "\\\\.\\%c:", drive[0]); + f_handle = CreateFile(drive_name, GENERIC_READ | GENERIC_WRITE, + FILE_SHARE_READ | FILE_SHARE_WRITE, + NULL, OPEN_EXISTING, 0, NULL ); + + if(f_handle == INVALID_HANDLE_VALUE) { + error("Could not open drive"); + exit(1); + } + + /* + * Read the boot sector + */ + ReadFile(f_handle, sectbuf, 512, &bytes_read, NULL); + if(bytes_read != 512) { + fprintf(stderr, "Could not read the whole boot sector\n"); + exit(1); + } + + /* Check to see that what we got was indeed an MS-DOS boot sector/superblock */ + if(!syslinux_check_bootsect(sectbuf,drive)) { + exit(1); + } + + /* Make the syslinux boot sector */ + syslinux_make_bootsect(sectbuf); + + /* Write the syslinux boot sector into the boot sector */ + SetFilePointer(f_handle, 0, NULL, FILE_BEGIN); + WriteFile( (HANDLE) f_handle, sectbuf, 512, &bytes_written, NULL ) ; + + if(bytes_written != 512) { + fprintf(stderr, "Could not write the whole boot sector\n"); + exit(1); + } + + /* Close file */ + CloseHandle(f_handle); + + /* Create the filename */ + sprintf(ldlinux_name, "%s%s", drive_name, "\\ldlinux.sys"); + + /* Change to normal attributes to enable deletion */ + /* Just ignore error if the file do not exists */ + SetFileAttributes(ldlinux_name, FILE_ATTRIBUTE_NORMAL); + + /* Delete the file */ + /* Just ignore error if the file do not exists */ + DeleteFile(ldlinux_name); + + /* Create ldlinux.sys file */ + f_handle = CreateFile(ldlinux_name, GENERIC_READ | GENERIC_WRITE, + FILE_SHARE_READ | FILE_SHARE_WRITE, + NULL, CREATE_ALWAYS, + FILE_ATTRIBUTE_ARCHIVE | FILE_ATTRIBUTE_READONLY, + NULL ); + + if(f_handle == INVALID_HANDLE_VALUE) { + error("Unable to create ldlinux.sys"); + exit(1); + } + + /* Write ldlinux.sys file */ + if (!WriteFile(f_handle, syslinux_ldlinux, syslinux_ldlinux_len, &bytes_written, NULL)) { + error("Could not write ldlinux.sys"); + exit(1); + } + + if (bytes_written != syslinux_ldlinux_len) { + fprintf(stderr, "Could not write whole ldlinux.sys\n"); + exit(1); + } + + /* Now flush the media */ + if(!FlushFileBuffers(f_handle)) { + error("FlushFileBuffers failed"); + exit(1); + } + + /* Close file */ + CloseHandle(f_handle); + + /* Done! */ + return 0; +} -- cgit v1.2.1