Yet again, Makefiles...

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
pcmattman
Member
Member
Posts: 2566
Joined: Sun Jan 14, 2007 9:15 pm
Libera.chat IRC: miselin
Location: Sydney, Australia (I come from a land down under!)
Contact:

Yet again, Makefiles...

Post 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.
Last edited by pcmattman on Mon May 07, 2007 3:30 am, edited 1 time in total.
jnc100
Member
Member
Posts: 775
Joined: Mon Apr 09, 2007 12:10 pm
Location: London, UK
Contact:

Post 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.
pcmattman
Member
Member
Posts: 2566
Joined: Sun Jan 14, 2007 9:15 pm
Libera.chat IRC: miselin
Location: Sydney, Australia (I come from a land down under!)
Contact:

Post by pcmattman »

Thanks, that fixed the 'nothing to link' problem...

Now the command line limit still remains :?
jnc100
Member
Member
Posts: 775
Joined: Mon Apr 09, 2007 12:10 pm
Location: London, UK
Contact:

Post 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.
pcmattman
Member
Member
Posts: 2566
Joined: Sun Jan 14, 2007 9:15 pm
Libera.chat IRC: miselin
Location: Sydney, Australia (I come from a land down under!)
Contact:

Post 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...
pcmattman
Member
Member
Posts: 2566
Joined: Sun Jan 14, 2007 9:15 pm
Libera.chat IRC: miselin
Location: Sydney, Australia (I come from a land down under!)
Contact:

Post 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.
nick8325
Member
Member
Posts: 200
Joined: Wed Oct 18, 2006 5:49 am

Post 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.
User avatar
Solar
Member
Member
Posts: 7615
Joined: Thu Nov 16, 2006 12:01 pm
Location: Germany
Contact:

Post 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.)
Every good solution is obvious once you've found it.
pcmattman
Member
Member
Posts: 2566
Joined: Sun Jan 14, 2007 9:15 pm
Libera.chat IRC: miselin
Location: Sydney, Australia (I come from a land down under!)
Contact:

Post 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...
pcmattman
Member
Member
Posts: 2566
Joined: Sun Jan 14, 2007 9:15 pm
Libera.chat IRC: miselin
Location: Sydney, Australia (I come from a land down under!)
Contact:

Post by pcmattman »

The cross-compiler build failed :?

So I used the @-files and everything is working perfectly, thanks all.
User avatar
Alboin
Member
Member
Posts: 1466
Joined: Thu Jan 04, 2007 3:29 pm
Location: Noricum and Pannonia

Post 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.
C8H10N4O2 | #446691 | Trust the nodes.
Post Reply