Previous: Generating the Command Line Switches, Up: Using the GNU make Utility


20.4 Overcoming Command Line Length Limits

One problem that might be encountered on big projects is that many operating systems limit the length of the command line. It is thus hard to give gnatmake the list of source and object directories.

This example shows how you can set up environment variables, which will make gnatmake behave exactly as if the directories had been specified on the command line, but have a much higher length limit (or even none on most systems).

It assumes that you have created a list of directories in your Makefile, using one of the methods presented in Automatically Creating a List of Directories. For the sake of completeness, we assume that the object path (where the ALI files are found) is different from the sources patch.

Note a small trick in the Makefile below: for efficiency reasons, we create two temporary variables (SOURCE_LIST and OBJECT_LIST), that are expanded immediately by make. This way we overcome the standard make behavior which is to expand the variables only when they are actually used.

On Windows, if you are using the standard Windows command shell, you must replace colons with semicolons in the assignments to these variables.

     # In this example, we create both ADA_INCLUDE_PATH and ADA_OBJECT_PATH.
     # This is the same thing as putting the -I arguments on the command line.
     # (the equivalent of using -aI on the command line would be to define
     #  only ADA_INCLUDE_PATH, the equivalent of -aO is ADA_OBJECT_PATH).
     # You can of course have different values for these variables.
     #
     # Note also that we need to keep the previous values of these variables, since
     # they might have been set before running 'make' to specify where the GNAT
     # library is installed.
     
     # see "Automatically creating a list of directories" to create these
     # variables
     SOURCE_DIRS=
     OBJECT_DIRS=
     
     empty:=
     space:=${empty} ${empty}
     SOURCE_LIST := ${subst ${space},:,${SOURCE_DIRS}}
     OBJECT_LIST := ${subst ${space},:,${OBJECT_DIRS}}
     ADA_INCLUDE_PATH += ${SOURCE_LIST}
     ADA_OBJECT_PATH += ${OBJECT_LIST}
     export ADA_INCLUDE_PATH
     export ADA_OBJECT_PATH
     
     all:
             gnatmake main_unit