M2(1)
okay bestie, welcome to M2(1) π the manual page for gm2, the GNU Modula-2 Compiler. Buckle up, it's giving long, so this is part 1 of 2 β we're not done yet, don't go anywhere π«Ά
π NAME π
gm2 β The GNU Modula-2 Compiler
β¨ SYNOPSIS β¨
okay so the synopsis section is literally empty π like the page just wakes up and chooses violence. Moving on.
π DESCRIPTION π
also empty. no description. it's giving minimalism, it's giving mystery, it's giving "read the options and find out" π
π OPTIONS π
okay so here's the whole vibe: for any given input file, the file name suffix decides what kind of compilation gets done. these are the input file names we support:
file.modβ Modula-2 implementation or program source files. if you wanna compile a project that uses a different source file extension, go look at the-fmod=option πfile.defβ Modula-2 definition module source files. and no, definition modules are not compiled separately β in GNU Modula-2 definition modules get parsed as required when program or implementation modules are compiled. same deal as above: see the-fdef=option if you wish to compile a project which uses a different source file extension.
and yes, you can specify more than one input file on the gm2 command line β¨ multiple files, no problem.
-gβ create debugging information so that debuggers such asgdbcan inspect and control executables. essential. iconic. periodt.-Iβ used to specify the search path for definition and implementation modules. for example:
gm2 -g -c -I.:../../libs foo.mod
if this option is not specified then the default path is added, which consists of the current directory followed by the appropriate language dialect library directories.
-fobject-path=β used to specify the path for objects during the linking stage. example time:
gm2 -g -fobject-path=.:../../libs/O2 -I.:../../libs foo.mod
the combination of -I and -fobject-path= lets projects keep various styles of objects separate from their source counterparts π
for example it would be possible to compile implementation modules with different levels of optimization and with/without debugging and keep them in separate directories. if the -fobject-path= option is not specified then it is set internally by using the path as specified by the -I option. if the -I was also not specified then it uses the current directory. in all cases the appropriate language dialect library directories are appended to the end of the path.
-fdebug-builtinsβ call a real function, rather than the builtin equivalent. this can be useful for debugging parameter values to a builtin function as it allows users to single step code into a real function. lowkey a debugging glow-up π₯-fdump-system-exportsβ display all inbuilt system items. this is an internal command line option.-fswigβ generate a swig interface file.-fsharedβ generate a shared library from the module.-fmakeinitβ generate the start up C++ code for the module, a file_m2_modulename.cppis created. this is an internal command line option.-fruntime-modules=β specify, using a comma separated list, the runtime modules and their order. these modules will initialized first before any other modules in the application dependancy. by default the runtime modules list is set toStorage,SYSTEM,M2RTS,RTExceptions,IOLink. note that these modules will only be linked into your executable if they are required β so adding a long list of dependant modules will not effect the size of the executable, it merely states the initialisation order should they be required π-fnilβ generate code to detect accessing data through aNILvalue pointer.-fno-nilβ do not generate code to detect accessing data through aNILvalue pointer.-fwholedivβ generate code to detect whole number division by zero or modulus by zero.-fno-wholedivβ do not generate code to detect whole number division by zero or modulus by zero.-findexβ generate code to check whether array index values are out of bounds.-fno-indexβ do not generate code to check whether array index values are out of bounds.-frangeβ generate code to check the assignment range, return value range set range and constructor range.-fno-rangeβ do not generate code to check the assignment range, return value range set range and constructor range.-freturnβ generate code to check that functions always exit with aRETURNand do not fall out at the end.-fcaseβ turns on compile time checking to check whether aCASEstatement requires anELSEclause when on was not specified.-fsoft-check-allβ turns on all runtime checks. this is the same as invoking GNU Modula-2 using the command options-fnil-frange-findex-fwholediv-fcase-freturn. the whole safety squad, assembled π‘οΈ-fauto-initβ turns on auto initialization of pointers to NIL. whenever a block is created all pointers declarated within this scope will have their addresses assigned to NIL.-fno-exceptionsβ turns off all generation of exception handling code and no references are made to the runtime exception libraries.-vβ display all calls to subsidiary programs, such as the C preprocessor, the GNU Modula-2 linker and compiler. nosy but make it productive π-fm2-statisticsβ generates quadruple information: number of quadruples generated, number of quadruples remaining after optimisation and number of source lines compiled. numbers!! we love numbers β¨-fm2-whole-programβ compile all implementation modules and program module at once. notice that you need to take care if you are compiling different dialect modules (particularly with the negative operands to modulus). but this option, when coupled together with-O3, can deliver huge performance improvements π₯-fm2-gβ improve the debugging experience for new programmers at the expense of generatingnopinstructions if necessary to ensure single stepping precision over all code related keywords. an example of this is in termination of a list of nestedIFstatements where multipleENDkeywords are mapped onto a sequence ofnopinstructions. training wheels but make them aesthetic π-fm2-lower-caseβ render keywords in error messages using lower case.-fmakelistβ this option is only applicable when linking a program module. the compiler will generate amodulename.lstfile which contains a list indicating the initialisation order of all modules which are to be linked. the actual link does not occur. the GNU Modula-2 linker scans allIMPORTs, generates a list of dependencies and produces an ordered list for initialisation. it will probably get the order wrong if your project has cyclic dependencies π but the.lstfile is plain text and can be modified if required. once the.lstfile is created it can be used by the compiler to link your project via the-fuselistoption. it has no effect if the-coption is present.fno-pthreadβ do not automatically link against the pthread library. (yep, that's written without a leading dash, that's just how it is here π) this option is likely useful ifgm2is configured as a cross compiler targetting embedded systems. by default GNU Modula-2 uses the GCC pthread libraries to implement coroutines (see theSYSTEMimplementation module).-fuselistβ providinggm2has been told to link the program module, this option uses the filemodulename.lstfor the initialisation order of modules.-fcppβ preprocess the source withcpp -lang-asm -traditional-cpp. for further details about these options see β (and then the page just... stops, iconic π). if-fcppis supplied then all definition modules and implementation modules which are parsed will be preprocessed bycpp.-fisoβ turn on ISO standard features. currently this enables the ISOSYSTEMmodule and alters the default library search path so that the ISO libraries are searched before the PIM libraries. it also effects the behaviour ofDIVandMODoperators. See β-fpimβ turn on PIM standard features. currently this enables the PIMSYSTEMmodule and determines which identifiers are pervasive (declared in the base module). if no other-fpim[234]switch is used then division and modulus operators behave as defined in PIM4. See β-fpim2β turn on PIM-2 standard features. currently this removesSIZEfrom being a pervasive identifier (declared in the base module). it placesSIZEin theSYSTEMmodule. it also effects the behaviour ofDIVandMODoperators. See β-fpim3β turn on PIM-3 standard features. currently this only effects the behaviour ofDIVandMODoperators. See β-fpim4β turn on PIM-4 standard features. currently this only effects the behaviour ofDIVandMODoperators. See β-fpositive-mod-floor-divβ forces theDIVandMODoperators to behave as defined by PIM4. all modulus results are positive and the results from the division are rounded to the floor. See β-flibs=β modifies the default library search path. the libraries supplied are:m2pim,m2iso,m2min,m2logandm2cor. these map onto the Programming in Modula-2 base libraries, ISO standard libraries, minimal library support, Logitech compatible library and Programming in Modula-2 with coroutines. multiple libraries can be specified and are comma separated with precidence going to the first in the list. it is not necessary to use-flibs=m2pimor-flibs=m2isoif you also specify-fpim,-fpim2,-fpim3,-fpim4or-fiso. unless you are using-flibs=m2minyou should includem2pimas the they provide the base modules which all other dialects utilize.-fextended-opaqueβ allows opaque types to be implemented as any type. this is a GNU Modula-2 extension and it requires that the implementation module defining the opaque type is available so that it can be resolved when compiling the module which imports the opaque type.-fsourcesβ displays the path to the source of each module. this option can be used at compile time to check the correct definition module is being used π very "who are you really" energy.-fmodulesβ displays the path to each modules object file. this option can only be invoked with the-coption. it is used to see the location of objects when linking occurs.-fdef=β recognise the specified suffix as a definition module filename. the default implmentation and module filename suffix is.def. if this option is used GNU Modula-2 will still fall back to this default if a requested definition module is not found.
and that's where part 1 ends bestie, don't close the tab, there's more coming π
-fmod=β bestie, this tells gm2 to recognise the suffix you give it as implementation and module filenames β¨ The default implmentation-and-module filename suffix is.mod. And here's the cute part: if you use this option, GNU Modula-2 will still fall back to that.moddefault whenever it needs to read an implementation module and the file with your fancy custom suffix doesn't actually exist. Safety net, slay π-fxcodeβ issues all errors and warnings in the Xcode format. Xcode girlies, this one's for you π-fonlylinkβ only link the modula-2 application, do not compile the program module beforehand. Just the linking, nothing else, periodt βοΈ-funbounded-by-referenceβ ok so this enables optimization of unbounded parameters by attempting to pass non-VARunbounded parameters by reference. The whole point is that this optimization avoids the implicit copy inside the callee procedure π§ GNU Modula-2 will only allow unbounded parameters to be passed by reference if, inside the callee procedure, they are not written to, no address is calculated on the array, and it is not passed as aVARparameter.
β οΈ Note that it is possible to write code to break this optimization, therefore this option should be used carefully. For example it would be possible to take the address of an array, pass the address and the array to a procedure, read from the array in the procedure and write to the location using the address parameter. π
Due to the dangerous nature of this option it is not enabled when the -O option is specified.
-Wverbose-unboundedβ informs the user which non-VARunbounded parameters will be passed by reference π This only produces output if the option-funbounded-by-referenceis also supplied on the command line. (Dynamic duo, iykyk π)-Wstudentsβ checks for bad programming style π This option is aimed at new users of Modula-2, in that it checks for situations which might cause confusion and thus mistakes. It checks whether variables of the same name are declared in different scopes and whether variables look like keywords. Heads up though: experienced users might find this option too aggressive π-Wpedanticβ forces the compiler to reject nestedWITHstatements referencing the same record type π« Does not allow multiple imports of the same item from a module. It also checks that: procedure variables are written to before being read; variables are not only written to but read from; variables are declared and used. If the compiler encounters a variable being read before written it will terminate with a message. It will check thatFORloop indices are not used outside the end of this loop without being reset. Full detective mode, no cap π-Wpedantic-param-namesβ procedure parameter names are checked in the definition module against their implementation module counterpart π This is not necessary in ISO or PIM versions of Modula-2, but it can be extremely useful, as long as code is intentionally written in this way.-Wpedantic-castβ warns if the ISO system function is used and if the size of the variable is different from that of the type. This is legal in ISO Modula-2, however it can be dangerous π¬ Some users may prefer to useVALinstead in these situations and useCASTexclusively for changes in type on objects which have the same size.-Wunused-variableβ warns if a variable has been declared and it not used π-Wunused-parameterβ warns if a parameter has been declared and it not used π (yes, both of them, the twins)-Wallβ turn on all Modula-2 warnings π Go big or go home.
πΈ ENVIRONMENT πΈ
ok so. it's givingβ¦ nothing. this section is empty in the original, bestie π no environment variables documented here, that's the whole vibe. moving on π¦
β¨ SEE ALSO β¨
β¦and the Info entries for gm2 and gcc π go read those too, they're lowkey essential.
π COPYRIGHT π
Copyright (c) 1999-2021 Free Software Foundation, Inc.
Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.3 or any later version published by the Free Software Foundation; with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts. A copy of the license is included in the man page gfdl(7) πβ¨
and that's the whole page bestie!! π«Ά this beauty lives in gcc-12, dated 2025-07-11, and it's filed under M2(1) β go forth and compile iconically ππ πΈ
π¦ where this page comes from
- ubuntu questing: gm2-12-arc-linux-gnu 12.5.0-6ubuntu1cross1
- ubuntu resolute: gm2-12-arc-linux-gnu 12.5.0-9ubuntu1cross1
- ubuntu stonking: gm2-12-arc-linux-gnu 12.5.0-9ubuntu1cross1
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms