Windows 2000+ batch build sistem

Windows 2000+ batch build sistem

offline
  • bocke  Male
  • Moderator foruma
  • Glavni moderator Linux foruma
  • Veliki Pingvin
  • Guru
  • Pridružio: 16 Dec 2005
  • Poruke: 12256
  • Gde živiš: Južni pol

Nešto sa čime sam se igrao početkom prošle godine. U pitanju je build skript za Tiny C compiler. Mogao sam da koristim i neki make alat, ali hteo sam da malo utvrdim Batch.

Način upotrebe: make.cmd se stavi u direktorijumu koji se nalazi u PATH promenljivoj okruženja (ili u dir gde se nalazi makefile.cmd). Zatim se napravi jednostavan makefile.cmd batch program poput ovog:

:: MAKEFILE FOR FIB.C :: Make sure Makefile is started from make.cmd @if not defined RUN_FROM_MAKE goto :EOF :: GENERAL OPTIONS @set PROGRAMNAME=fib @set DEBUGGING= @set WARNINGS=-Wall @set FLAGS= :: FILE OPTIONS @set SOURCES=*.c @set OBJECTS=*.o @set OUTPUT=%PROGRAMNAME%.exe :: LIBRARIES TO USE @set LIBRARIES=%TCCLIB%

Komande koje ovaj skript podržava su:
F - ukoliko se makefile ne zove makefile.cmd moguće ga je navesti ovom opcijom
clean - Očisti binarne datoteke

make.cmd batch:
:: Name         : make.cmd :: Description   : Windows 2000, XP, 2003, VISTA, 2008, 7 Make script for Tiny C Compiler. :: Author      : Bojan Popovic, http://www.bojanpopovic.com/, bocke@mycity.rs :: License      : This script is placed in a public domain. Do whatever you like with it. :: Comments      : Divided in logical "sections" for easier comprehension. :: Warning      : Do not run in Windows 9x or pure DOS! Uses Command Extensions not available in 9x/DOS. :: Tested on   : Windows 7. :: SECTION: DEBUG OPTIONS :: Leave empty to undefine, put any value to define.    @set DEBUG=    @set DEBUG_ECHO= :: END :: SECTION: INCLUDE & LIBRARY OPTIONS :: Set TCC library & include directories.    @set INCLUDEDIR=C:\Users\Boki\Desktop\Tcc\include    @set LIBDIR=C:\Users\Boki\Desktop\Tcc\lib    @set TCCLIBDIR=%LIBDIR% ::END :: SECTION: LIBRARY DEFINITIONS :: We need this for fast linking.    @set TCCLIB=%TCCLIBDIR%\libtcc.a    @set GDI32=%LIBDIR%\gdi32.def    @set KERNEL32=%LIBDIR%\kernel32.def    @set MSVCRT=%LIBDIR%\msvcrt.def    @set USER32=%LIBDIR%\user32.def ::END :: SECTION: CHECK FOR DEBUG :: If in debug mode turn echo on.    @if not defined DEBUG_ECHO echo off :: END :: SECTION: GLOBAL OPTIONS :: Set or clear some global options used in script.    set PROGRAM_NAME=%0    set ERRNO=0    set RUN_FROM_MAKE=1    set OPTIONS=    set LINK_OPTIONS= :: END :: SECTION: ERROR DEFINITIONS :: Definition of script errors.    ::      1XX - SCRIPT PARAMETER ERRORS       set INVALID_ARGUMENT=101    ::      2XX - NOT DEFINED YET    ::      3XX - EXTERNAL MAKEFILE ERRORS       set INPUT_FILE_NOT_ENTERED=301       set INVALID_INPUT_FILE=302    ::      4XX - WARNINGS       set NOTHING_TO_DO=401 :: END :: SECTION CHECK NUMBER OF PARAMETERS :: Check if script called without parameters. If it was, just build.    set ARG=%*    if not defined ARG call :MAKE && goto :EXIT :: END :: SECTION: ARGUMENT INITIALISATION :: Empty ARG variable and define ARG1 & ARG2 with 1st and 2nd parameter.    set ARG=    set ARG2=%2    set ARG3=%3 :: END :: SECTION: PROCESS ARGUMENTS :: Check command input for valid options.    for %%A in (%*) do (       if %%A==clean (call :CLEAN && goto :EXIT)       if %%A==help (call :USAGE && goto :EXIT)       if %%A==f (call :MAKEFILE %ARG2% %ARG3% && goto :EXIT)       call :ERROR %INVALID_ARGUMENT% && goto :EXIT    ) :: END :EXIT :: SUBBATCH: EXIT :: Description: Release variables on exit & exit script.    :: SECTION: CLEAR DEBUG    :: Sets debug mode off.       set DEBUG=    :: END    :: SECTION: CLEAN TCC    :: Clean up TCC environment variables       set INCLUDDIR=       set LIBDIR=       set TCCLIBDIR=    ::END    :: SECTION: CLEAN TCC LIBS    :: Clean up TCC library definitions       set TCCLIB=       set USER32=       set GDI32=       set MSVCRT=       set USER32=    :: END    :: SECTION: CLEAN MAKE    :: Clean up make.cmd specific variables       set RUN_FROM_MAKE=       set DEBUG_ECHO=       set DEBUG=    :: END    :: SECTION: CLEAN PROJECT    :: Clean up project specific definitions.       set SOURCES=       set INCLUDES=       set OBJECTS=       set OUTPUT=       set DLL=    :: END    :: SECTION: RETURN STATUS    :: If not encountered an error, exit with errorlevel 0.       if not defined ERRNO exit /b 0 else exit /b %ERRORNO%    :: END    :: SECTION: QUIT    :: Quits the script.       goto :EOF    :: END :: ENDSUBBATCH :MAKE :: SUBBATCH: MAKE :: Description: Compiles the project according to rules defined in the makefile.cmd.    :: SECTION: DEBUG - PRINT SUBBATCH NAME    :: If in debug mode, print the name of subbatch.    if defined DEBUG echo Subbatch MAKE    :: END    :: SECTION: GET MAKEFILE    :: Set the name of makefile to use.    set FILENAME=%1    if not defined FILENAME set FILENAME=makefile.cmd    :: END    :: SECTION: CHECK MAKEFILE    :: Check if makefile exists. If it does get neeeded information.       if exist %FILENAME% (call %FILENAME%) else (call :ERROR: %NOTHING_TO_DO% && goto :EOF)       :: Clear temporary variable         set RUN_FROM_MAKE=    ::END    :: SECTION: CHECK COMPILER OPTIONS    :: Check compiler options from the makefile.       :: Is the target a dynamic link library?          if defined DLL set OPTIONS=%OPTIONS% -shared       :: Debugging options (see TCC docs).          if defined DEBUGGING set OPTIONS=-g %OPTIONS%       :: Which warnings to show (see TCC docs).          if defined WARNINGS set OPTIONS=%WARNINGS% %OPTIONS%       :: Compiler flags (see TCC docs).          if defined FLAGS set OPTIONS=%FLAGS% %OPTIONS%       :: Aditional include dirs.          if defined INCLUDES (             for %%I in (%INCLUDES%) do set OPTIONS=%OPTIONS% -I%%I          )    :: END    :: SECTION: CHECK PROJECT VARIABLES    :: Check if the crucial poject variables are defined.       if not defined SOURCES (echo SOURCES NOT DEFINED) && goto :EOF       if not defined OBJECTS (echo OBJECTS NOT DEFINED) && goto :EOF       if not defined OUTPUT (echo OUTPUT NOT DEFINED) && goto :EOF    :: END    :: SECTION: DEBUG PRINT PROJECT VARIABLES    :: If in debug mode, print variable values.       if defined DEBUG (          echo Debug: sources: %SOURCES%          echo Debug: objects: %OBJECTS%          echo Debug: output : %OUTPUT%          echo Debug: options: %OPTIONS%       )    :: END    :: SECTION: CHECK SOURCE    :: Check if physical source files exist.       for %%S in (%SOURCES%) do (          :: TODO implement error def          if not exist %%S (echo %%S NOT EXIST && set ERRNO=1 && goto :EOF)       )    :: END    :: SECTION: DEBUG CHECK COMPILE CMDLINE    :: If in debug mode, print current compile command line.       if defined DEBUG (          for %%F in (%SOURCES%) do echo Debug: tcc -c %%F %OPTIONS%       )    :: END    :: SECTION: COMPILE    :: Compile source files without linking.    for %%F in (%SOURCES%) do (       tcc -c %%F %OPTIONS%       )    if %ERRORLEVEL%==1 (       :: TODO implement error def       echo COMPILATION ERROR && set ERRNO=1       goto :EOF)    :: END    :: SECTION: DLL SKIP LINKING    :: If DLL option is on, skip linking and go to EOF.    :: DLLS are automatically generated by TCC.       if defined DLL goto :EOF    ::END    :: SECTION: SET LINKING OPTIONS    :: Check linking options.       set LINK_OPTIONS=       if defined TCCLIBDIR set LINK_OPTIONS=%LINK_OPTIONS% -B%TCCLIBDIR%       if defined LIBDIR set LINK_OPTIONS=%LINK_OPTIONS% -L%LIBDIR%    :: END    :: SECTION: DEBUG CHECK LINK CMDLINE    :: If in debug mode, print current link command line.       if defined DEBUG (          echo Debug: tcc %LINK_OPTIONS% -o %OUTPUT% %OBJECTS% %LIBRARIES%       )    ::END    :: SECTION: CHECK IF COMPILED    :: Check if obj files exist. If not something went wrong with compilation.          for %%O in (%OBJECTS%) do (          if not exist %%O (             :: TODO implement error def             echo %%O NOT EXIST && set ERRNO=1             goto :EOF             )       )    ::END    :: SECTION: LINK    :: And now link the .o files to defined output exe file.       tcc %LINK_OPTIONS% -o %OUTPUT% %OBJECTS% %LIBRARIES%       if %ERRORLEVEL%==1 (          :: TODO: Implement error def.          echo LINKING ERROR && set ERRNO=1          goto :EOF          )    :: END        goto :EOF :: ENDSUBBATCH :MAKEFILE :: SUBBATCH: MAKEFILE :: Description: Sets external makefile options    :: SECTION DEFINE MAKEFILE    :: Sets makefile and optional clean flag to subbatch parameters.       set FILENAME=%1       set DOCLEANUP=%2    :: END           :: SECTION: DEBUG - PRINT SUBBATCH NAME    :: If in debug mode, print the name of subbatch.       if defined DEBUG echo Subbatch MAKEFILE.    :: END    :: SECTION: CHECK MAKEFILE NAME    :: Checks if filename entered.       if defined FILENAME (set ERRNO=0) else call :ERROR %INPUT_FILE_NOT_ENTERED% && goto :EOF    :: END    :: SECTION: MAKEFILE EXISTS    :: Checks if makefile exists, if it does gets compiler options.       if exist %FILENAME% (call %FILENAME%) else call :ERROR %INVALID_INPUT_FILE% && goto :EOF    :: END        :: SECTION: CHECK CLEAN OPTION    :: Check if clean option specified and if it was, call CLEAN subbatch.       if not defined DOCLEANUP (call :make %FILENAME% && goto :EOF)       if %DOCLEANUP%==clean (call :CLEAN %FILENAME% && goto :EOF) else (call :ERROR %INVALID_ARGUMENT% && goto :EOF)    :: END    goto :EOF ::EndSubbatch :CLEAN :: SUBBATCH: CLEAN :: Description: Cleans (deletes) output executables and intermediary files.    :: SECTION: DEBUG - PRINT SUBBATCH NAME    :: If in debug mode, print the name of subbatch.       if defined DEBUG echo Subbatch CLEAN.    :: END    :: SECTION: CHECK CLEAN    :: Check makefile for files to clean.       set CLEANUPFILE=%1       if not defined CLEANUPFILE set CLEANUPFILE=makefile.cmd    :: END    :: SECTION: DO CLEANUP    :: If specified Makefile exists do clean up. If no makefile specified, use makefile.bat       if exist %CLEANUPFILE% (set RUN_FROM_MAKE=1 && call %FILENAME%) else (call :ERROR: %NOTHING_TO_DO% && goto :EOF)       :: Release temporary variable.       set RUN_FROM_MAKE=    :: END    :: SECTION: DELETE OBJ FILES    :: If not DLL target, delete all .obj files.       if not defined DLL (          if defined OBJECTS (for %%O in (%OBJECTS%) do del %%O)          )    :: END    :: SECTION: DELETE OUTPUT    :: Delete comiled executable/dll.          if defined OUTPUT (for %%E in (%OUTPUT%) do del %%E)    :: END    :: If we got here, it's certain the operation was succesful.    set ERRNO=0        goto :EOF :: EndSubbatch :USAGE :: Subbatch: USAGE :: Description: Display usage information.    :: SECTION: DEBUG - PRINT SUBBATCH NAME    :: If in debug mode, print the name of subbatch.       if defined DEBUG echo Subbatch USAGE.    :: END    :: If we got here, it's certain the operation was succesful.    set ERRNO=0    goto :EOF ::EndSubbatch :ERROR :: Subbatch: ERROR :: Description: Sets errorlevel to adequate level and prints out the error.    :: SECTION: DEBUG - PRINT SUBBATCH NAME    :: If in debug mode, print the name of subbatch.       if defined DEBUG echo Subbatch ERROR.    :: END    :: SECTION: SET ERROR NUMBER    :: Sets error number to the first parameter of subbatch.       set ERRNO=%1    :: END    :: SECTION: SET ERROR DESCRIPTION    :: Define error messages.       if %1==%INVALID_ARGUMENT% set ERRORDESC=Invalid argument       if %1==%INPUT_FILE_NOT_ENTERED% set ERRORDESC=Missing file name       if %1==%INVALID_INPUT_FILE% set ERRORDESC=File doesn't exist       if %1==%NOTHING_TO_DO% set ERRORDESC=No makefile found. Nothing to do    :: END    :: SECTION: DISPLAY ERROR    :: Displays error message.       echo %PROGRAM_NAME%: error(%ERRNO%) %ERRORDESC%!    :: END    :: We can quit now. :: EndSubbatch :: Changelog: ::   (0.1.1) 09.01.2009. (9th of January 2009) - Refine comments and indenting [Bojan Popovic] ::   (0.1.0) 07.01.2009. (7th of January 2009) - Initial version [Bojan Popovic]

Ovaj kod je u javnom domenu. Radite sa njim šta god hoćete.

Ovde su batchevi (preimenovani u txt) i primeri:
https://www.mycity.rs/must-login.png



Registruj se da bi učestvovao u diskusiji. Registrovanim korisnicima se NE prikazuju reklame unutar poruka.
Ko je trenutno na forumu
 

Ukupno su 431 korisnika na forumu :: 27 registrovanih, 4 sakrivenih i 400 gosta   ::   [ Administrator ] [ Supermoderator ] [ Moderator ] :: Detaljnije

Najviše korisnika na forumu ikad bilo je 3028 - dana 22 Nov 2019 07:47

Korisnici koji su trenutno na forumu:
Korisnici trenutno na forumu: A.R.Chafee.Jr., Bane san, Duh sa sekirom, galijot, Georgius, ibssa, kovinacc, Maksim 3, MarKhan, nenad81, ostoja, pein, prekodrinski, RJ, royst33, Sibin2, Sirius, stug, theNedjeljko, tmanda323, Toni, VJ, vladas87, vlvl, voja64, zodiac94, |_MeD_|