Page 1 of 1

Yet again, Makefiles...

Posted: Mon May 07, 2007 3:17 am
by pcmattman
I'm finally well on my way to a properly working makefile! Only one thing now stands between me and a working makefile that I never have to touch again (theoretically).

It's this:

Code: Select all

ld-elf -T linker.ld -Map link.map -o kernel.bin
c:/djgpp/bin/ld-elf.exe: no input files
make: *** [kernel.bin] Error 1
There should be filenames...

My makefile:

Code: Select all

# compiler and flags
CXX:=gpp
CXXFLAGS:=-I ./include -nostdlib -fno-rtti -fno-exceptions
## DJGPP ELF-ENABLED LD ###
LD:=ld-elf
LDFLAGS:=-T linker.ld -Map link.map -o
# assembler
AS:=as-elf
# source and objects, and final binary
PROJDIRS:=$(find * -type d -not -name "CVS")
SRCS:=$(shell find $(PROJDIRS) -name "*.cc" -type f)
OBJS:=$(patsubst %.cc,%.o,$(SRCS))
FINALBIN:=kernel.bin

# clean up
clean:
	rm $(OBJS) *.bin

# buld the full kernel
all: $(FINALBIN)

# link command
$(FINALBIN) : $(OBJS)
	$(LD) $(LDFLAGS) $(FINALBIN) $(OJBS)

# C++ source
%.o : %.cc
	$(CXX) $(CXXFLAGS) -c $< -o $@

# assembly
%.o : %.asm
	$(AS) $< -o $@
The thing is, 'make clean' works perfectly! Any ideas?

Edit: I put in a hack to make it work:

Code: Select all

$(LD) $(LDFLAGS) $(FINALBIN) $(patsubst %.cc,%.o,$(SRCS))
New problem, it seems even Cygwin has a character limit:

Code: Select all

ld-elf -T linker.ld -Map link.map -o kernel.bin ./ata/ata_pio.o ./console/consol
e.o ./fs/fat32.o ./kernel.o ./lib/iostream.o ./portio.o ./syscore/fault.o ./sysc
ore/gdt.o ./syscore/idt.o ./syscore/irq.o ./syscore/math.o ./syscore/mem.o ./sys
core/paging.o ./syscore/timer.o ./tasking/mt.o
process_begin: CreateProcess(c:\djgpp\bin\ld-elf.exe, ld-elf -T linker.ld -Map l
ink.map -o kernel.bin ./ata/ata_pio.o ./console/console.o ./fs/fat32.o ./kernel.
o ./lib/iostream.o ./portio.o ./syscore/fault.o ./syscore/gdt.o ./syscore/idt.o
./syscore/irq.o ./syscore/math.o ./syscore/mem.o ./syscore/paging.o ./syscore/ti
mer.o ./tasking/mt.o, ...) failed.
make (e=87): The parameter is incorrect.
Edit 2: OK, source of the problem is now known:
MSDN wrote: * Maximum Path Length

In the Windows API, the maximum length for a path is MAX_PATH, which is defined as 260 characters. A path is structured as follows: drive letter, colon, backslash, components separated by backslashes, and a null-terminating character. For example, the maximum path on the D drive is D:\<256 chars>NUL.

Posted: Mon May 07, 2007 3:30 am
by jnc100
How about fixing the typo in the link command?
pcmattman wrote:

Code: Select all

# link command
$(FINALBIN) : $(OBJS)
   $(LD) $(LDFLAGS) $(FINALBIN) $(OJBS) 
I think you mean $(OBJS) rather than $(OJBS)?

Regards,
John.

Posted: Mon May 07, 2007 3:33 am
by pcmattman
Thanks, that fixed the 'nothing to link' problem...

Now the command line limit still remains :?

Posted: Mon May 07, 2007 3:41 am
by jnc100
From the Windows SDK for CreateProcess, 2nd argument:
Microsoft SDK wrote: lpCommandLine
[in, out] The command line to be executed. The maximum length of this string is 32K characters.
Windows 2000: The maximum length of this string is MAX_PATH characters.
Are you using Win2000?

Also, you mention Cygwin whereas your linker is located in a djgpp directory. Are you sure its cygwin?

Regards,
John.

Posted: Mon May 07, 2007 3:43 am
by pcmattman
Using Cygwin as a command line... DJGPP as a compiler.

WinXP. Could it be that I have an old version of MSVC++ (version 6) and libraries have been overwritten? I doubt it, though...

That's really weird.

Edit: it seems I'm not the only one... Does anyone know of a verson of Cygwin (or maybe MinGW?) that doesn't use the WinAPI (CreateProcess)?

Edit: I'm downloading the Cygwin GCC and binutils. Fingers crossed...

Posted: Mon May 07, 2007 5:00 am
by pcmattman
Edit: got the Cygwin stuff. G++ executes perfectly. LD fails:

Code: Select all

ld -T linker.ld -o kernel.bin ata/ata_pio.o console/console.o fs/fat32.o lib/ios
tream.o syscore/fault.o syscore/gdt.o syscore/idt.o syscore/irq.o syscore/math.o
 syscore/mem.o syscore/paging.o syscore/timer.o tasking/mt.o
ld: cannot perform PE operations on non PE output file 'kernel.bin'.
My linker script tells it to output in the elf32-i386 format.

Posted: Mon May 07, 2007 5:24 am
by nick8325
pcmattman wrote:Using Cygwin as a command line... DJGPP as a compiler.
DOS has a much shorter command-line limit than Windows. DJGPP can work around that, so if a DJGPP program runs another DJGPP program there's no limit. Try the DJGPP version of make, if you're not using it already.

Failing that, you could use an @-file (see the first option under http://sourceware.org/binutils/docs-2.1 ... tions.html).

EDIT: sorry, didn't notice your latest post. You could link to PE and then objcopy to an ELF file.

PS: you might need to pass -mno-stack-arg-probe to GCC, and --image-base=0 to LD.

Posted: Mon May 07, 2007 5:52 am
by Solar
pcmattman, your questions - here and by PM - are all over the place...

The maximum length of a path (CreateProcess) has nothing to do with the maximum length of a command line.

In your private message you said that you had the command line length problem solved by removing an erroneous single quote. Is this the case, or does the problem persist?

Your "PE operation on a non-PE file" is one of the classical errors. Your toolchain doesn't fit - one tool is acting on ELF (Unix-style) binary format, another on PE (Windows-style) binary format. You can solve this with objcopy, but the whole problem is best circumvented by using a cross-compiler under Cygwin (see the Wiki for a tutorial on how to build one).

Excessive linker command lines can be shortened by using the "ar" utility, which I recommended to you earlier, or the @-files nick8325 found out about. (I only checked the GCC docs, sorry.)

Posted: Mon May 07, 2007 3:23 pm
by pcmattman
In your private message you said that you had the command line length problem solved by removing an erroneous single quote. Is this the case, or does the problem persist?
I assumed it was.

I'm about to build a cross-compiler...

Posted: Tue May 08, 2007 3:25 pm
by pcmattman
The cross-compiler build failed :?

So I used the @-files and everything is working perfectly, thanks all.

Posted: Tue May 08, 2007 3:28 pm
by Alboin
Maybe a little late, but if your have any more problems with makefiles on Windows you might want to check out an alternative like CMake or Scons. Which, I hear, work better on Windows.