@echo off REM rugxulo at gmail dot com REM http://rugxulo.googlepages.com REM REM Thursday, April 24, 2008 6:33pm REM REM N.B. UPX'd DJGPP binaries run slower on XP or Vista! REM For faster speed (if it affects you), unpack 'em. if not "%DJGPP%"=="" goto c99 :err echo. echo No DJGPP/GCC C99 compiler found! Check http://www.delorie.com/djgpp/ echo. goto adios :c99 if exist c99.c if exist c99.exe goto start echo #include "stdio.h" >c99.c echo int main() { >>c99.c echo #if __STDC_VERSION__ == 199901L >>c99.c echo printf("\nC99 compiler found!\n"); >>c99.c echo return 0; >>c99.c echo #else >>c99.c echo return 1; >>c99.c echo #endif >>c99.c echo } >>c99.c if exist c99.c gcc -std=c99 c99.c -o c99.exe if exist c99.c if not exist c99.exe goto err if not exist *.o if exist c99.exe c99.exe if exist c99.exe if errorlevel 1 goto err :start if not exist %0 %0.bat %1 %2 %3 %4 %5 %6 %7 %8 %9 if "%1"=="/gcc" goto gcc if "%1"=="clean" if exist *.o del *.o if "%1"=="clean" if exist c99.* del c99.* if "%1"=="cleanall" for %%a in (nasm ndisasm) do if exist %%a.exe del %%a.exe if "%1"=="cleanall" call %0 clean if "%1"=="clean" goto end if "%1"=="cleanall" goto end if not "%DEBUG%"=="" if "%NASMMAKE%"=="" set NASMMAKE=-O0 set ME=%0 for %%a in (nasm preproc ndisasm hashtbl) do if not exist %%a.c goto end REM This makes the smallest .EXE with all output formats available for use REM set N1=-Os -march=i386 REM Only do simple optimizations for faster compile (e.g. slow machines) REM set N1=-O REM This is to compile w/ all speed optimizations (makes NASM runs faster) set N1=-O2 set N1=%N1% %NASMMAKE% REM set N2=-Wall -Wextra -pedantic -I. -I.\inttypes set N2=-Wall -I. -I.\inttypes REM let .BAT options affect compilation (easier than modifying manually) REM e.g. "-O0" here overrides all optimizations previously requested :opts if "%1"=="" goto setup set N1=%N1% %1 shift goto opts :setup shift if exist config.h goto begin echo. echo Making NASM 2.02 via DJGPP 2.03p2 or 2.04 (no ./configure needed!) echo (Tested with GCC 3.2.3, 3.4.4, and 4.2.3) echo. if not "%DEBUG%"=="" goto config if not "%OS%"=="Windows_NT" choice /n /t:n,10 Do you wish to continue? if errorlevel 2 goto end :: commented lines here are only for DJGPP 2.04 beta (yet unnecessary) :config echo #define HAVE_DECL_STRCASECMP 0 >config.h echo #define HAVE_DECL_STRICMP 0 >>config.h echo #define HAVE_DECL_STRNCASECMP 0 >>config.h echo #define HAVE_DECL_STRNICMP 0 >>config.h echo #define HAVE_DECL_STRSEP 0 >>config.h echo #define HAVE_GETGID 1 >>config.h echo #define HAVE_GETUID 1 >>config.h :: echo #define HAVE_INTTYPES_H 1 >>config.h echo #define HAVE_LIMITS_H 1 >>config.h echo #define HAVE_MEMORY_H 1 >>config.h :: echo #define HAVE_SNPRINTF 1 >>config.h echo #define HAVE_STDBOOL_H 1 >>config.h :: echo #define HAVE_STDINT_H 1 >>config.h echo #define HAVE_STDLIB_H 1 >>config.h echo #define HAVE_STRCASECMP 1 >>config.h echo #define HAVE_STRCSPN 1 >>config.h echo #define HAVE_STRICMP 1 >>config.h echo #define HAVE_STRINGS_H 1 >>config.h echo #define HAVE_STRING_H 1 >>config.h echo #define HAVE_STRNCASECMP 1 >>config.h echo #define HAVE_STRNICMP 1 >>config.h echo #define HAVE_STRSEP 1 >>config.h echo #define HAVE_STRSPN 1 >>config.h echo #define HAVE_SYS_STAT_H 1 >>config.h echo #define HAVE_SYS_TYPES_H 1 >>config.h echo #define HAVE_UNISTD_H 1 >>config.h :: echo #define HAVE_VSNPRINTF 1 >>config.h echo #define PACKAGE_BUGREPORT "" >>config.h echo #define PACKAGE_NAME "" >>config.h echo #define PACKAGE_STRING "" >>config.h echo #define PACKAGE_TARNAME "" >>config.h echo #define PACKAGE_VERSION "" >>config.h echo #define STDC_HEADERS 1 >>config.h echo #ifndef _GNU_SOURCE >>config.h echo # define _GNU_SOURCE 1 >>config.h echo #endif >>config.h REM ... in case you forgot to unzip via SFN but later need it! if exist syslimit.h goto next echo #define _GCC_NEXT_LIMITS_H >syslimit.h echo #include_next "limits.h" >>syslimit.h echo #undef _GCC_NEXT_LIMITS_H >>syslimit.h :next REM This saves us from wasting precious cmdline space w/ "-DHAVE_CONFIG_H" echo #include "config.h" >> compiler.h1 copy /b compiler.h1 + compiler.h compiler.h2 >NUL copy /b compiler.h2 compiler.h >NUL for %%a in (h1 h2) do if exist compiler.%%a del compiler.%%a :begin REM Compiling more than one .C file at a time is no faster (and wastes REM precious cmdline length!!) for %%a in (nasm nasmlib float insnsa assemble) do call %ME% /gcc %%a for %%a in (labels hashtbl crc64 parser outform) do call %ME% /gcc %%a REM small workaround needed since FreeCOM mistreats "output/outbin.c" REM (forward slash confuses it: it becomes "output /outbin.c" with an REM errorneous space ... unlike WinXP's or DR-DOS' or 4DOS) if not exist outobj.c copy /b output\out*.c >NUL for %%a in (bin aout coff elf32 elf64 obj as86) do call %ME% /gcc out%%a for %%a in (rdf2 dbg ieee macho) do call %ME% /gcc out%%a for %%a in (preproc pptok listing eval) do call %ME% /gcc %%a for %%a in (exprlib stdscan tokhash) do call %ME% /gcc %%a if not exist vsnpf.c copy /b lib\vsnprint.c vsnpf.c >NUL if not exist vsnpf.c copy /b lib\vsnpri~1.c vsnpf.c >NUL if not exist snprintf.c copy /b lib\snprintf.c >NUL for %%a in (snprintf vsnpf) do call %ME% /gcc %%a for %%a in (ndisasm disasm sync insnsd) do if exist %%a.o ren %%a.o %%a.o~ echo on gcc -s -o nasm.exe *.o @echo off for %%a in (*.o~) do ren %%a *.o for %%a in (ndisasm disasm sync insnsd) do call %ME% /gcc %%a echo on gcc -s -o ndisasm.exe ndis*.o dis*.o sync.o nasmlib.o insnsd.o vsn*.o snp*.o @echo off set N1= set N2= echo. if not "%DEBUG%"=="" goto end if not "%OS%"=="Windows_NT" choice /n /t:n,10 Pack the .EXEs via UPX? if errorlevel 2 goto end REM upx --ultra-brute nasm.exe ndisasm.exe REM upx --best --lzma --all-filters nasm.exe ndisasm.exe upx --best nasm.exe ndisasm.exe goto end :gcc shift REM putting this check here to save GCC cmdline length if exist %1.o goto adios echo on gcc -c -std=c99 %N1% %N2% %1.c @echo off goto adios :end set N1= set N2= set ME= echo. if exist nasm.exe nasm.exe -v if exist ndisasm.exe ndisasm.exe -v :adios if not "%DEBUG%"=="" if "%NASMMAKE%"=="-O0" set NASMMAKE=