gbadev.org forum archive

This is a read-only mirror of the content originally found on forum.gbadev.org (now offline), salvaged from Wayback machine copies. A new forum can be found here.

Coding > Makefile to compile EFS/FAT version

#171146 - headspin - Tue Nov 03, 2009 2:48 am

I'm trying to modify a makefile to compile an EFS or FAT version based on the following:

Code:
EFS := 1


I can get this to work in the Makefile itself like so:

Code:
$(TARGET).nds   :   $(TARGET).arm7 $(TARGET).arm9
ifeq ($(EFS), 1)
   ndstool -c $(TARGET).nds -7 $(TARGET).arm7 -9 $(TARGET).arm9 $(NITRODIR) $(LOGO) $(ICON) "$(NAME);$(AUTHOR);$(VERSION)"
   efs $(TARGET).nds
else
   ndstool -c $(TARGET).nds -7 $(TARGET).arm7 -9 $(TARGET).arm9 $(LOGO) $(ICON) "$(NAME);$(AUTHOR);$(VERSION)"
endif


But for some reason in the arm9 main.s the EFS value does not seem to be set..

Code:
#if (EFS == 1)
   mov r0, #(EFS_AND_FAT | EFS_DEFAULT_DEVICE)   @ Init EFS
   mov r1, #0
   bl EFS_Init
#else
   bl fatInitDefault                     @ Init FAT
#endif


So that is always failing to see if EFS is set to "1" in the makefile. On the other hand if I do a "#define EFS 1" at the start of main.s then it will be set and do what it's supposed to do.

Why isn't the environment variable set in the Makefile registered in the pre-processor commands in main.s? The Makefile in question is the main one, not the one for the arm7 or arm9 so it should be set before compiling main.s in arm9 right?
_________________
Warhawk DS | Manic Miner: The Lost Levels | The Detective Game

#171147 - kusma - Tue Nov 03, 2009 2:52 am

headspin wrote:
Why isn't the environment variable set in the Makefile registered in the pre-processor commands in main.s?

Because environment variables and preprocessor definitions aren't the same thing? You need to do something along the lines of
Code:
ifeq ($(EFS), 1)
CPPFLAGS += -DEFS
endif

...to get the desired effect.

#171148 - headspin - Tue Nov 03, 2009 3:05 am

kusma wrote:
Because environment variables and preprocessor definitions aren't the same thing?


That would explain it

kusma wrote:
You need to do something along the lines of
Code:
ifeq ($(EFS), 1)
CPPFLAGS += -DEFS
endif

...to get the desired effect.


Hmm that didn't seem to work
_________________
Warhawk DS | Manic Miner: The Lost Levels | The Detective Game

#171149 - Drovor - Tue Nov 03, 2009 3:06 am

In the Makefile try adding "-DEFS=1" to the CFLAGS option.

The "#if (EFS == 1)" checks for preprocessor flags, not environment variables.

For example compile this with "gcc main.c -DEFS=1" then try "gcc main.c -DEFS=2"
Code:

#include <stdio.h>
int main()
{
  #if (EFS == 1)
    printf("EFS = 1\n");
  #elif (EFS == 2)
    printf("EFS = 2\n");
  #endif
  return 0;
}

#171151 - headspin - Tue Nov 03, 2009 3:18 am

Still doesn't seem to be working. I have EFS := 1 in the main Makefile, and in the arm9 makefile I have

Code:
ifeq ($(EFS), 1)
   CFLAGS += -DEFS=1
   ASFLAGS += -DEFS=1
endif


After the CFLAGS and ASFLAGS values are set. This is an asm file (main.s) so I tried adding it to the ASFLAGS value aswell. No joy :(
_________________
Warhawk DS | Manic Miner: The Lost Levels | The Detective Game

#171154 - kusma - Tue Nov 03, 2009 11:13 am

headspin wrote:

Code:
ifeq ($(EFS), 1)
   CFLAGS += -DEFS=1
   ASFLAGS += -DEFS=1
endif


After the CFLAGS and ASFLAGS values are set. This is an asm file (main.s) so I tried adding it to the ASFLAGS value aswell. No joy :(


First of all, -D directives are C pre-processor defines, not C compiler directives (there's a difference, even though it might be small). So in general -D (and -I) directives should go in CPPFLAGS, not CFLAGS (some people seem to think CPPFLAGS is for C++ flags, but that's what CXXFLAGS is for). Secondly, you should use the $(COMPILE.S) rule (as opposed to the $(COMPILE.s) rule)... if you use make's implicit build-rules, that is. If not, you should make sure you call "gcc -x assembler-with-cpp", and make sure you include $(CPPFLAGS) in your "%.o : %.S"-rule.