WINEBUILD(1)

πŸ“¦ version 6.0, in ubuntu jammy

πŸ’– WINEBUILD(1) πŸ’–

okay bestie, welcome to the Wine Developers Manual, and today we're getting into winebuild β€” yes, that's the same winebuild(1) you keep seeing in your man searches, she's a whole icon, let's go πŸŽ€


✨ NAME ✨

winebuild β€” the Wine dll builder. That's it, that's the job πŸ’…


🌸 SYNOPSIS 🌸

winebuild [options] [inputfile...]

πŸ¦‹ DESCRIPTION πŸ¦‹

So basically, winebuild generates the assembly files you need to build a Wine dll β€” and a Wine dll is lowkey just a Win32 dll wrapped up inside a Unix library, no cap. Two vibes in one girlie 🫢

winebuild has different modes, depending on what kind of file you ask it to generate. You pick the mode with one of the mode options listed down below. And on top of the mode option, you can also throw in a bunch of other command-line options, all described in the OPTIONS section, because she's flexible like that πŸ’β™€οΈ


πŸ‘‘ MODE OPTIONS πŸ‘‘

okay so this is the part where you have to commit. You have to specify exactly one of the following options, depending on what you want winebuild to generate. Not zero. Not two. One. Main character energy, singular ✨

  • --dll β€” Build an assembly file from a .spec file (peep SPEC FILE SYNTAX for the details), or from a standard Windows .def file. You pass the .spec/.def file via the -E option. The resulting file then has to be assembled and linked to the other object files to build a working Wine dll. In this mode, the input files should be the list of all object files that will be linked into the final dll β€” that way winebuild can get the list of all the undefined symbols that need to be imported from other dlls πŸ”₯
  • --exe β€” Build an assembly file for an executable. This is basically the same as the --dll mode except it doesn't require a .spec/.def file as input, because an executable doesn't need to export functions. Some executables do export functions though, and for those you can specify a .spec/.def file via the -E option. The executable gets named from the .spec/.def file name if it's there, or explicitly through the -F option. The resulting file must be assembled and linked to the other object files to build a working Wine executable, and all the other object files must be listed as input files πŸ’–
  • --def β€” Build a .def file from a spec file. The .spec file is specified via the -E option. You use this when building dlls with a PE (Win32) compiler πŸŽ€
  • --implib β€” Build a .a import library from a spec file. The .spec file is specified via the -E option. And if the output library name ends in .delay.a, then you get a delayed import library instead. Cute surprise ✨
  • --staticlib β€” Build a .a static library from object files. Simple, clean, slay πŸ’…
  • --resources β€” Generate a .o file containing all the input resources. This one's useful when building with a PE compiler, since the PE binutils literally cannot handle multiple resource files as input (rude of them tbh). For a standard Unix build, the resource files are automatically included when building the spec file, so there's no need for an intermediate .o file at all πŸ™ˆ
  • --builtin β€” Mark a PE module as a Wine builtin module, by adding the "Wine builtin DLL" signature string after the DOS header. Branding, but make it binary πŸ¦‹
  • --fixup-ctors β€” Fixup constructors after a module has been built. You should do this on the final .so module if its code contains constructors, to make sure Wine has a chance to initialize the module before the constructors are executed. Order matters, bestie ⭐

πŸ’… OPTIONS πŸ’…

the full menu, no skips, we eat every bite:

  • --as-cmd=as-command β€” Specify the command to use to compile assembly files. The default is as.
  • -b, --target=cpu-manufacturer[-kernel]-os β€” Specify the target CPU and platform on which the generated code will be built. The target specification is in the standard autoconf format, as returned by config.sub. Yes, -kernel is part of the format β€” it goes in the middle, don't lose her 🫢
  • -B directory β€” Add the directory to the search path for the various binutils tools like as, nm and ld.
  • --cc-cmd=cc-command β€” Specify the C compiler to use to compile assembly files. The default is to instead use the assembler specified with --as-cmd.
  • -d, --delay-lib=name β€” Set the delayed import mode for the specified library, which must be one of the libraries imported with the -l option. Delayed mode means the library won't be loaded until a function imported from it is actually called. She's patient like that 😌
  • -D symbol β€” Ignored, for compatibility with the C compiler. Not everything's about you, -D πŸ’€
  • -e, --entry=function β€” Specify the module entry point function. If you don't specify it, the default is DllMain for dlls, and main for executables (and if the standard C main is not defined, WinMain is used instead). This is only valid for Win32 modules.
  • -E, --export=filename β€” Specify a .spec file (see SPEC FILE SYNTAX for the details), or a standard Windows .def file that defines the exports of the DLL or executable that is being built.
  • --external-symbols β€” Allow linking to external symbols directly from the spec file. Normally, symbols exported by a dll have to be defined in the dll itself. This option makes it possible to use symbols defined in another Unix library. (heads up though: for symbols defined in another dll, a forward specification must be used instead.)
  • -f option β€” Specify a code generation option. Currently -fPIC and -fasynchronous-unwind-tables are supported. Other options are ignored for compatibility with the C compiler.
  • --fake-module β€” Create a fake PE module for a dll or exe, instead of the normal assembly or object file. The PE module contains the resources for the module, but no executable code. Fake it till you make it, but make it literal ✨
  • -F, --filename=filename β€” Set the file name of the module. The default is to use the base name of the spec file (without any extension).
  • -h, --help β€” Display a usage message and exit. Your emergency exit πŸšͺ
  • -H, --heap=size β€” Specify the size of the module local heap in bytes (only valid for Win16 modules). The default is no local heap.
  • -I directory β€” Ignored, for compatibility with the C compiler. Again. Not your era, -I πŸ™ˆ
  • -k, --kill-at β€” Remove the stdcall decorations from the symbol names in the generated .def file. Only meaningful in --def mode.
  • -K flags β€” Ignored, for compatibility with the C compiler. The third ignored one, they're just here for the vibes πŸ’€
  • --large-address-aware β€” Set a flag in the executable to notify the loader that this application supports address spaces larger than 2 gigabytes. Big girl energy, literally πŸ‘‘
  • --ld-cmd=ld-command β€” Specify the command to use to link the object files. The default is ld.
  • -L, --library-path=directory β€” Append the specified directory to the list of directories that are searched for import libraries.
  • -l, --library=name β€” Import the specified library, looking for a corresponding libname.def file in the directories specified with the -L option.
  • -m16, -m32, -m64 β€” Generate respectively 16-bit, 32-bit or 64-bit code. Pick your era 🌈
  • -marm, -mthumb β€” Select between generating code that executes in ARM and Thumb states.
  • -march=option, -mcpu=option, -mfpu=option, -mfloat-abi=option β€” Set code generation options for the assembler.
  • -mno-cygwin β€” Build a library that uses the Windows runtime instead of the Unix C library.
  • -munix β€” Build the Unix counterpart of a builtin module.
  • -M, --main-module=module β€” When building a 16-bit dll, set the name of its 32-bit counterpart to module. This is used to enforce that the load order for the 16-bit dll matches that of the 32-bit one. Sibling solidarity πŸ’–
  • -N, --dll-name=dllname β€” Set the internal name of the module. It is only used in Win16 modules. The default is to use the base name of the spec file (without any extension). This is used for KERNEL, since it lives in KRNL386.EXE. It shouldn't be needed otherwise.
  • --nm-cmd=nm-command β€” Specify the command to use to get the list of undefined symbols. The default is nm.
  • --nxcompat=yes|no β€” Specify whether the module is compatible with no-exec support. The default is yes.
  • -o, --output=file β€” Set the name of the output file (default is standard output). If the output file name ends in .o, the text output is sent to a temporary file that is then assembled to produce the specified .o file.
  • -r, --res=rsrc.res β€” Load resources from the specified binary resource file. The rsrc.res file can be produced from a source resource file with wrc(1) (or with a Windows resource compiler). This option is only necessary for Win16 resource files β€” the Win32 ones can simply be listed as input files and will automatically be handled correctly (though the -r option will also work for Win32 files). ✨
  • --safeseh β€” Mark object files as SEH compatible.
  • --save-temps β€” Do not delete the various temporary files that winebuild generates. Hoarder mode, but make it debugging πŸŽ€
  • --subsystem=subsystem[:major[.minor]] β€” Set the subsystem of the executable, which can be one of the following:
    • console β€” for a command line executable
    • windows β€” for a graphical executable
    • native β€” for a native-mode dll
    • wince β€” for a ce dll

The entry point of a command line executable is a normal C main function. A wmain function can be used instead if you need the argument array to use Unicode strings. A graphical executable has a WinMain entry point.

Optionally, a major and minor subsystem version can also be specified; the default subsystem version is 4.0.

  • -u, --undefined=symbol β€” Add symbol to the list of undefined symbols when invoking the linker. This makes it possible to force a specific module of a static library to be included when resolving imports. Peer pressure, but for linkers 🫢
  • -v, --verbose β€” Display the various subcommands being invoked by winebuild. She's telling you everything, and honestly? We're listening.
  • --version β€” Display the program version and exit.
  • -w, --warnings β€” Turn on warnings. πŸ””
friendly reminder bestie: you still need exactly one mode option from up top before any of this does anything. Don't forget her πŸ’œ

✨ SPEC FILE SYNTAX ✨

okay bestie, so a spec file is literally just a list of ordinal declarations, and the general syntax is giving this:

ordinal functype [flags] exportname ( [args...] ) [handler]
ordinal variable [flags] exportname ( [data...] )
ordinal extern [flags] exportname [symbolname]
ordinal stub [flags] exportname [ (args...) ]
ordinal equate [flags] exportname data
# comments

Declarations have to fit on one single line, unless you escape the end of the line with a backslash character. And the # character anywhere in a line? It makes the rest of that line ignored as a comment. periodt. πŸ’…

ordinal is the ordinal number for the entry point, or '@' for automatic ordinal allocation (Win32 only).

flags is a little series of optional flags, each one preceded by a - character. The supported flags are:

  • -norelay β€” this entry point is not displayed in relay debugging traces (Win32 only).
  • -noname β€” the entry point gets exported by ordinal instead of by name. The name is still available for importing, so don't panic.
  • -ret16 β€” the function returns a 16-bit value (Win16 only).
  • -ret64 β€” the function returns a 64-bit value (Win32 only).
  • -register β€” the function uses CPU register to pass arguments.
  • -private β€” the function cannot be imported from other dlls, it can only be accessed through GetProcAddress.
  • -ordinal β€” the entry point will be imported by ordinal instead of by name. The name is still exported.
  • -thiscall β€” the function uses the thiscall calling convention (first parameter in %ecx register on i386).
  • -fastcall β€” the function uses the fastcall calling convention (first two parameters in %ecx/%edx registers on i386).
  • -syscall β€” the function is an NT system call. A system call thunk will be generated, and the actual function will be called by the __wine_syscall_dispatcher function that will be generated on the Unix library side.
  • -import β€” the function is imported from another module. This can be used instead of a forward specification when an application expects to find the function's implementation inside the dll.
  • -arch=[!]cpu[,cpu] β€” the entry point is only available on the specified CPU architecture(s). The names win32 and win64 match all 32-bit or 64-bit CPU architectures respectively. In 16-bit dlls, specifying -arch=win32 causes the entry point to be exported from the 32-bit wrapper module. A CPU name can be prefixed with ! to exclude only that specific architecture.

πŸ’– Function ordinals πŸ’–

Syntax:

ordinal functype [flags] exportname ( [args...] ) [handler]

This declaration is literally defining a function entry point. The prototype defined by exportname ( [args...] ) specifies the name available for dynamic linking and the format of the arguments. You can use '@' instead of exportname for ordinal-only exports.

functype should be one of:

  • stdcall β€” for a normal Win32 function
  • pascal β€” for a normal Win16 function
  • cdecl β€” for a Win16 or Win32 function using the C calling convention
  • varargs β€” for a Win16 or Win32 function using the C calling convention with a variable number of arguments

args should be one or several of:

  • word β€” (16-bit unsigned value)
  • s_word β€” (16-bit signed word)
  • long β€” (pointer-sized integer value)
  • int64 β€” (64-bit integer value)
  • int128 β€” (128-bit integer value)
  • float β€” (32-bit floating point value)
  • double β€” (64-bit floating point value)
  • ptr β€” (linear pointer)
  • str β€” (linear pointer to a null-terminated ASCII string)
  • wstr β€” (linear pointer to a null-terminated Unicode string)
  • segptr β€” (segmented pointer)
  • segstr β€” (segmented pointer to a null-terminated ASCII string).
Note: The 16-bit and segmented pointer types are only valid for Win16 functions. 🫢

handler is the name of the actual C function that will implement that entry point in 32-bit mode. The handler can also be specified as dllname.function to define a forwarded function (one whose implementation is in another dll). If handler is not specified, it is assumed to be identical to exportname.

This first example defines an entry point for the 32-bit GetFocus() call:

@ stdcall GetFocus() GetFocus

This second example defines an entry point for the 16-bit CreateWindow() call (the ordinal 100 is just an example); it also shows how long lines can be split using a backslash:

100 pascal CreateWindow(ptr ptr long s_word s_word s_word \
    s_word word word word ptr) WIN_CreateWindow

To declare a function using a variable number of arguments, specify the function as varargs and declare it in the C file with a '...' parameter for a Win32 function, or with an extra VA_LIST16 argument for a Win16 function. See the wsprintf* functions in user.exe.spec and user32.spec for an example.


🌸 Variable ordinals 🌸

Syntax:

ordinal variable [flags] exportname ( [data...] )

This declaration defines data storage as 32-bit words at the ordinal specified. exportname will be the name available for dynamic linking. data can be a decimal number or a hex number preceded by "0x". The following example defines the variable VariableA at ordinal 2 and containing 4 ints:

2 variable VariableA(-1 0xff 0 0)

This declaration only works in Win16 spec files. In Win32 you should use extern instead (see below). πŸ‘€


πŸ¦‹ Extern ordinals πŸ¦‹

Syntax:

ordinal extern [flags] exportname [symbolname]

This declaration defines an entry that simply maps to a C symbol (variable or function). It only works in Win32 spec files. exportname will point to the symbol symbolname that must be defined in the C code. Alternatively, it can be of the form dllname.symbolname to define a forwarded symbol (one whose implementation is in another dll). If symbolname is not specified, it is assumed to be identical to exportname.


πŸ’… Stub ordinals πŸ’…

Syntax:

ordinal stub [flags] exportname [ (args...) ]

This declaration defines a stub function. It makes the name and ordinal available for dynamic linking, but will terminate execution with an error message if the function is ever called. so like, don't call it unless you want chaos. πŸ’€


✨ Equate ordinals ✨

Syntax:

ordinal equate [flags] exportname data

This declaration defines an ordinal as an absolute value. exportname will be the name available for dynamic linking. data can be a decimal number or a hex number preceded by "0x".


πŸ‘‘ AUTHORS πŸ‘‘

winebuild has been worked on by many people over the years. The main authors are Robert J. Amstadt, Alexandre Julliard, Martin von Loewis, Ulrich Weigand and Eric Youngdale. Many other people have contributed new features and bug fixes. For a complete list, see the git commit logs.


πŸ› BUGS πŸ›

It is not yet possible to use a PE-format dll in an import specification; only Wine dlls can be imported.

Bugs can be reported on the Wine bug tracker.


πŸŽ€ AVAILABILITY πŸŽ€

winebuild is part of the Wine distribution, which is available through WineHQ, the Wine development headquarters.


πŸ”— SEE ALSO πŸ”—


And that's the whole spec-file sermon, bestie πŸ’– This iconic page is from Wine 6.0, dated October 2005, and it's literally WINEBUILD(1) energy forever. No cap. πŸ’…βœ¨
πŸ“¦ where this page comes from