Linux MakeFile Help, Devolupment Order?

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.
User avatar
GeniusCobyWalker
Member
Member
Posts: 65
Joined: Mon Jan 12, 2009 4:17 pm

Linux MakeFile Help, Devolupment Order?

Post by GeniusCobyWalker »

I want it to scan subdirectories also how would I do that?
Tried Google, cd Source\, tried Source before wildcard.
Any advice?

Heres my makefile:

Code: Select all

CC = gcc
CFLAGS = -nostdlib -nostartfiles -nodefaultlibs -m32	

ASM = nasm
ASMFLAGS =

LD = ld
LDFLAGS = -T linker.ld  -m elf_i386

BIN = Bin/
OUTPUT = Kernel.bin

CSOURCES = $(wildcard *.c)
CHEADERS = $(wildcard *.h)
ASMSOURCES = $(wildcard *.s)

COBJECTS = $(patsubst %.c,%.o, $(CSOURCES))
ASMOBJECTS = $(patsubst %,%.o, $(ASMSOURCES))

.PHONY : all clean
	rm Bin/Kernel.bin
all: $(BIN)$(OUTPUT)
clean:
	
	rm -f *.o
	rm Bin/Floppy.img
	rm Bin/Kernel.bin
$(ASMOBJECTS) : $(ASMSOURCES)
	$(ASM) -f elf32 $(ASMFLAGS) -o $@ $(patsubst %.o,%, $@)
$(COBJECTS) : $(CSOURCES) $(CHEADERS)
	$(CC) -c $(CFLAGS) -o $@ $(patsubst %.o,%.c, $@)
$(BIN)$(OUTPUT): $(COBJECTS) $(ASMOBJECTS)
	$(LD) $(LDFLAGS) -o $(BIN)$(OUTPUT) $(COBJECTS) $(ASMOBJECTS)
	cat  stage1 stage2 pad Bin/Kernel.bin > Bin/Floppy.img
	rm -f *.o
	
$(CSOURCES) :
$(ASMSOURCES) :
$(CHEADERS) :
	
Last edited by GeniusCobyWalker on Mon Jan 26, 2009 7:09 pm, edited 1 time in total.
Full Knowledge in:
GML, Ti-Basic, Zilog Z80 Assembly, SX28 Assembly and Blender
Experience in:
C++,OpenGl,NDS C++,Dark Basic,Dark Basic Pro,Dark Gdk and PSP Coding
Using:
Ubuntu ,GEdit ,NASM ,GCC ,LD ,Bochs
JohnnyTheDon
Member
Member
Posts: 524
Joined: Sun Nov 09, 2008 2:55 am
Location: Pennsylvania, USA

Re: Linux MakeFile Help

Post by JohnnyTheDon »

Replace

Code: Select all

CSOURCES = $(wildcard *.c)
CHEADERS = $(wildcard *.h)
ASMSOURCES = $(wildcard *.s)
with

Code: Select all

CSOURCES = $(shell find ./Source -name "*.c" | xargs)
CHEADERS = $(shell find ./Source -name "*.h" | xargs)
ASMSOURCES = $(shell find ./Source -name "*.s" | xargs)
Replace Source with the root directory you want to search. Eg. everything in source or in a subfoler of source will get compiled.

And don't use backslashes in Linux. Bad idea.
User avatar
GeniusCobyWalker
Member
Member
Posts: 65
Joined: Mon Jan 12, 2009 4:17 pm

Re: Linux MakeFile Help

Post by GeniusCobyWalker »

What about deleting all .o files in Source Folder?

Tried:

Code: Select all

rm Source/*.o,rm -f *.o, rm Source/-f *.o 
Full Knowledge in:
GML, Ti-Basic, Zilog Z80 Assembly, SX28 Assembly and Blender
Experience in:
C++,OpenGl,NDS C++,Dark Basic,Dark Basic Pro,Dark Gdk and PSP Coding
Using:
Ubuntu ,GEdit ,NASM ,GCC ,LD ,Bochs
JohnnyTheDon
Member
Member
Posts: 524
Joined: Sun Nov 09, 2008 2:55 am
Location: Pennsylvania, USA

Re: Linux MakeFile Help

Post by JohnnyTheDon »

You really don't have a clue what you're doing, do you? -f is an option, not part of the path.

Do

Code: Select all

find ./Source -name "*.o" | xargs rm -f
User avatar
gzaloprgm
Member
Member
Posts: 141
Joined: Sun Sep 23, 2007 4:53 pm
Location: Buenos Aires, Argentina
Contact:

Re: Linux MakeFile Help

Post by gzaloprgm »

Doesn't make support something like **/*.c for all c files in subdirectories?
gcc -c kernel/*/*.c works perfectly on gcc, on mingw doesn't.
Visit https://gzalo.com : my web site with electronic circuits, articles, schematics, pcb, calculators, and other things related to electronics.
Hangin10
Member
Member
Posts: 162
Joined: Wed Feb 27, 2008 12:40 am

Re: Linux MakeFile Help

Post by Hangin10 »

There is a very well written tutorial on the wiki: makefile.
Craze Frog
Member
Member
Posts: 368
Joined: Sun Sep 23, 2007 4:52 am

Re: Linux MakeFile Help

Post by Craze Frog »

gzaloprgm wrote:
Doesn't make support something like **/*.c for all c files in subdirectories?
gcc -c kernel/*/*.c works perfectly on gcc, on mingw doesn't.
Don't use forward slashes on Windows. Bad idea.

And also the practices for wildcard expansion are different on Windows and Linux. On Linux it's usually done by the shell. In Windows it's usually done by the program.
User avatar
Solar
Member
Member
Posts: 7615
Joined: Thu Nov 16, 2006 12:01 pm
Location: Germany
Contact:

Re: Linux MakeFile Help

Post by Solar »

1) Don't use MinGW in a DOS box, use a GCC Cross-Compiler in Cygwin. Trust us. It's less painfull that way.

2) The Makefile tutorial covers finding of sources, deleting of sources, scanning of subdirectories plus several other things.

3) Don't copy & paste solutions found somewhere. Understand why something works and something else doesn't. It's worth the time if you don't focus solely on your subject (getting your Makefile to work), but try to take in the bigger picture (why bash style path expansion cannot work in a DOS box, for example).
Every good solution is obvious once you've found it.
User avatar
GeniusCobyWalker
Member
Member
Posts: 65
Joined: Mon Jan 12, 2009 4:17 pm

Re: Linux MakeFile Help

Post by GeniusCobyWalker »

Im not using MingW in DOSBox.
Besides i'm on Ubuntu.
Full Knowledge in:
GML, Ti-Basic, Zilog Z80 Assembly, SX28 Assembly and Blender
Experience in:
C++,OpenGl,NDS C++,Dark Basic,Dark Basic Pro,Dark Gdk and PSP Coding
Using:
Ubuntu ,GEdit ,NASM ,GCC ,LD ,Bochs
User avatar
AJ
Member
Member
Posts: 2646
Joined: Sun Oct 22, 2006 7:01 am
Location: Devon, UK
Contact:

Re: Linux MakeFile Help

Post by AJ »

GeniusCobyWalker wrote:Im not using MingW in DOSBox.
Besides i'm on Ubuntu.
You use the Minimalist GNU for Windows on Ubuntu? If that's really true, are you trying to use it with WINE? That sounds like a Bad Idea. Alternatively, you are just very confused about your toolchain. I suggest following Solar's advice and building a Cross-Compiler. For the original question, see his Makefile tutorial on the wiki (that was pointed out by Hangin10).

Cheers,
Adam
User avatar
GeniusCobyWalker
Member
Member
Posts: 65
Joined: Mon Jan 12, 2009 4:17 pm

Re: Linux MakeFile Help

Post by GeniusCobyWalker »

I'm using GEdit, Gcc, Nasm, Ld and Bochs

All Programs for Ubuntu. Why did you think i'm emulating Windows?
Full Knowledge in:
GML, Ti-Basic, Zilog Z80 Assembly, SX28 Assembly and Blender
Experience in:
C++,OpenGl,NDS C++,Dark Basic,Dark Basic Pro,Dark Gdk and PSP Coding
Using:
Ubuntu ,GEdit ,NASM ,GCC ,LD ,Bochs
User avatar
gzaloprgm
Member
Member
Posts: 141
Joined: Sun Sep 23, 2007 4:53 pm
Location: Buenos Aires, Argentina
Contact:

Re: Linux MakeFile Help

Post by gzaloprgm »

That was me :P

I just said cobywalker could simplify his makefile by using the double wildcard (he's using ubuntu and there the double wildcard method works).

Someone missunderstood everything (Mingw on Wine on Gnu/linux (?)).

Cheers,
Gonzalo

BTW, why you insist in creating a cross compiler? What's the problem of compiling my kernel with mingw, I'm using my own bootloader and I can link as a plain binary file w/o the need of making a cross-compiler or anything.
Visit https://gzalo.com : my web site with electronic circuits, articles, schematics, pcb, calculators, and other things related to electronics.
User avatar
neon
Member
Member
Posts: 1567
Joined: Sun Feb 18, 2007 7:28 pm
Contact:

Re: Linux MakeFile Help

Post by neon »

BTW, why you insist in creating a cross compiler? What's the problem of compiling my kernel with mingw, I'm using my own bootloader and I can link as a plain binary file w/o the need of making a cross-compiler or anything.
There is nothing "wrong" with any type of tool chain used when creating executive software. As long as your tool chain and project is designed in a way to easily work with large scale software, it will work fine. Everything else (portability and the like) depends on your design.

In other words, if it works for you, stick with it ;)
OS Development Series | Wiki | os | ncc
char c[2]={"\x90\xC3"};int main(){void(*f)()=(void(__cdecl*)(void))(void*)&c;f();}
User avatar
GeniusCobyWalker
Member
Member
Posts: 65
Joined: Mon Jan 12, 2009 4:17 pm

Re: Linux MakeFile Help

Post by GeniusCobyWalker »

I have another question.
I'm going to drop everything with my Kernel (cut-pasted-edited tutorial code) and
start-over making a kernel along with tutorials instead of coping and pasting.

What order should I do this in?
1) Bootloader, Kernel,TUI, GUI
2)Kernel, Bootloader, TUI, GUI
1) Bootloader, Kernel, GUI
2)Kernel, Bootloader, GUI
Full Knowledge in:
GML, Ti-Basic, Zilog Z80 Assembly, SX28 Assembly and Blender
Experience in:
C++,OpenGl,NDS C++,Dark Basic,Dark Basic Pro,Dark Gdk and PSP Coding
Using:
Ubuntu ,GEdit ,NASM ,GCC ,LD ,Bochs
User avatar
piranha
Member
Member
Posts: 1391
Joined: Thu Dec 21, 2006 7:42 pm
Location: Unknown. Momentum is pretty certain, however.
Contact:

Re: Linux MakeFile Help

Post by piranha »

GeniusCobyWalker wrote:I have another question.
I'm going to drop everything with my Kernel (cut-pasted-edited tutorial code) and
start-over making a kernel along with tutorials instead of coping and pasting.

What order should I do this in?
1) Bootloader, Kernel,TUI, GUI
2)Kernel, Bootloader, TUI, GUI
1) Bootloader, Kernel, GUI
2)Kernel, Bootloader, GUI
*Starts Crying*

Firstly, whats with 1,2,1,2? Learn to count first, but I'm gonna assume you mean 1,2,3,4. Edit, No, TUI/GUI are not different options enough to repeat numbers. They're both interfaces and are therefor the same idea.

Bootloader, Kernel, MM, tasking, syscalls, VFS, FS drivers, more drivers, etc, etc, program loading, etc, etc, and then from there the TUI/GUI thing is your choice.

However, don't even think about making an interface until you get MM, tasking, VFS, syscalls, and program loading going. Then make your interface as a loadable program to test out your kernel.

This ought to keep you busy for 2-4 years at your rate.

-JL
SeaOS: Adding VT-x, networking, and ARM support
dbittman on IRC, @danielbittman on twitter
https://dbittman.github.io
Locked