Build File Help Ubuntu (Linux)

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

Build File Help Ubuntu (Linux)

Post by GeniusCobyWalker »

I tried to make a Build.bat file that Assembles, Compiles, Linkes, and Makes a Floppy called "build.bat"
The file is below anyone know why this doesn't work?
(Yes I looked at the Make File Tutorial)( And Googled it!)

!!UPDATED MAKEFILE!! and ERROR

Files:
OS Files:Image

"Error":
coby@coby-laptop:~/Desktop/OS$ make
makefile:24: *** missing separator. Stop.
"makefile":

Code: Select all

CC = gcc
CFLAGS = -m32 -ffreestanding -nostdlib -nodefaultlibs -mcmodel=large -DBUILDING_KERNEL

ASM = nasm
ASMFLAGS =

LD = ld
LDFLAGS = -T linkerscript.ld --strip-all -nostdlib -nodefaultlibs

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

all: $(BIN)$(OUTPUT)
clean:
  rm -f *.o
$(BIN)$(OUTPUT): $(COBJECTS) $(ASMOBJECTS)
   $(LD) $(LDFLAGS) -o $(BIN)$(OUTPUT) $(COBJECTS) $(ASMOBJECTS)
$(COBJECTS) : $(CSOURCES) $(CHEADERS)
   $(CC) -c $(CFLAGS) -o $@ $(patsubst %.o,%.c, $@)
$(ASMOBJECTS) : $(ASMSOURCES)
   $(ASM) -f elf32 $(ASMFLAGS) -o $@ $(patsubst %.o,%, $@)
$(CSOURCES) :
$(ASMSOURCES) :
$(CHEADERS) :
Last edited by GeniusCobyWalker on Mon Jan 19, 2009 11:47 am, edited 2 times 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
xyzzy
Member
Member
Posts: 391
Joined: Wed Jul 25, 2007 8:45 am
Libera.chat IRC: aejsmith
Location: London, UK
Contact:

Re: Build File Help Ubuntu (Linux)

Post by xyzzy »

Define "doesn't work"
JohnnyTheDon
Member
Member
Posts: 524
Joined: Sun Nov 09, 2008 2:55 am
Location: Pennsylvania, USA

Re: Build File Help Ubuntu (Linux)

Post by JohnnyTheDon »

Build File Help Ubuntu (Linux)
Batch files don't work in linux. And this isn't a makefile. I posted a makefile for you on another thread.
User avatar
Troy Martin
Member
Member
Posts: 1686
Joined: Fri Apr 18, 2008 4:40 pm
Location: Langley, Vancouver, BC, Canada
Contact:

Re: Build File Help Ubuntu (Linux)

Post by Troy Martin »

Troll or incompetent noob, community, take your pick.

Linux =/= DOS & Windows. Makefiles are files that describe how the "make" command should work.
Image
Image
Solar wrote:It keeps stunning me how friendly we - as a community - are towards people who start programming "their first OS" who don't even have a solid understanding of pointers, their compiler, or how a OS is structured.
I wish I could add more tex
User avatar
Love4Boobies
Member
Member
Posts: 2111
Joined: Fri Mar 07, 2008 5:36 pm
Location: Bucharest, Romania

Re: Build File Help Ubuntu (Linux)

Post by Love4Boobies »

Ubuntu (Linux)? :roll: :lol:

Anyway, I'm not very familiar with makefiles. I've only use batch scripts for large projects (or IDEs). But from what I gather from the GNU Make documentation, this should have worked, right?

Code: Select all

foo.asm : foo.bin
          nasm -ofoo.bin foo.asm
I'm using mingw32-make. Am I doing something wrong? And please, don't just answer use cygwin or msys instead; I wanna know if there's something I'm missing here. It complains about there being no rules defined for foo.asm.
"Computers in the future may weigh no more than 1.5 tons.", Popular Mechanics (1949)
[ Project UDI ]
JohnnyTheDon
Member
Member
Posts: 524
Joined: Sun Nov 09, 2008 2:55 am
Location: Pennsylvania, USA

Re: Build File Help Ubuntu (Linux)

Post by JohnnyTheDon »

Use Linux Instead... jk. Though it would be a good idea.

It won't work for three reasons:

1. 'foo.asm : foo.bin' is backwards. Makefiles use 'target : dependencies'. foo.bin depends on foo.asm.
2. You must include a target called 'all'. After fixing the previous error, just add

Code: Select all

all : foo.bin
By default make starts with all and branches out from there.
3. You must add 'foo.asm: ' at the end of the makefile. Otherwise, make won't check if foo.asm has been changed since the last build.

I recommend makefiles that build all .c and .asm files in a directory, so you don't have to change your makefile every time you add a file. However, it is up to you.
User avatar
Love4Boobies
Member
Member
Posts: 2111
Joined: Fri Mar 07, 2008 5:36 pm
Location: Bucharest, Romania

Re: Build File Help Ubuntu (Linux)

Post by Love4Boobies »

JohnnyTheDon wrote:1. 'foo.asm : foo.bin' is backwards. Makefiles use 'target : dependencies'. foo.bin depends on foo.asm.
Oh, I did do that... I don't know why I got them reversed on the forum.

Anyway, thanks for the quick reply. :)
"Computers in the future may weigh no more than 1.5 tons.", Popular Mechanics (1949)
[ Project UDI ]
User avatar
GeniusCobyWalker
Member
Member
Posts: 65
Joined: Mon Jan 12, 2009 4:17 pm

Re: Build File Help Ubuntu (Linux)

Post by GeniusCobyWalker »

How do you know what commands you can use in Linux make files?
Not a ton of Linux experience

Windows Example Command: Echo Text
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
JamesM
Member
Member
Posts: 2935
Joined: Tue Jul 10, 2007 5:27 am
Location: York, United Kingdom
Contact:

Re: Build File Help Ubuntu (Linux)

Post by JamesM »

Code: Select all

man make

Code: Select all

wget http://www.google.com/?q=Makefile+tutorial
User avatar
Love4Boobies
Member
Member
Posts: 2111
Joined: Fri Mar 07, 2008 5:36 pm
Location: Bucharest, Romania

Re: Build File Help Ubuntu (Linux)

Post by Love4Boobies »

Simple -- you're not using makefiles with linux, you're using them with a tool called 'make'. It is used of automatically compiling/assembling/whatever (not limited to software development) only when certain files are updated (timestamps are checked). This tool can also be used under Windows; for example MinGW comes with a version of make (mingw32-make.exe). You can check the documentation here.
"Computers in the future may weigh no more than 1.5 tons.", Popular Mechanics (1949)
[ Project UDI ]
User avatar
Troy Martin
Member
Member
Posts: 1686
Joined: Fri Apr 18, 2008 4:40 pm
Location: Langley, Vancouver, BC, Canada
Contact:

Re: Build File Help Ubuntu (Linux)

Post by Troy Martin »

In other words:
Read what we post: makefiles are not shell scripts. Makefiles are for the "make" command. Shell scripts are like Linux batch files, but more powerful. Read the wiki's makefile tutorial again.
Image
Image
Solar wrote:It keeps stunning me how friendly we - as a community - are towards people who start programming "their first OS" who don't even have a solid understanding of pointers, their compiler, or how a OS is structured.
I wish I could add more tex
User avatar
Love4Boobies
Member
Member
Posts: 2111
Joined: Fri Mar 07, 2008 5:36 pm
Location: Bucharest, Romania

Re: Build File Help Ubuntu (Linux)

Post by Love4Boobies »

Troy Martin wrote:Shell scripts are like Linux batch files, but more powerful.
Note that in later versions of Windows, certain extensions may be activated. Also, they're working on a much more powerful scripting thingy called Windows PowerShell, but I'm not sure it's included with Windows or you have to download it from Microsoft's website (and I'm too lazy to check -- I don't have Windows on this machine).
"Computers in the future may weigh no more than 1.5 tons.", Popular Mechanics (1949)
[ Project UDI ]
User avatar
Troy Martin
Member
Member
Posts: 1686
Joined: Fri Apr 18, 2008 4:40 pm
Location: Langley, Vancouver, BC, Canada
Contact:

Re: Build File Help Ubuntu (Linux)

Post by Troy Martin »

You do have to download powershell, but IMHO it's confusing and a little awkward to work with.
Image
Image
Solar wrote:It keeps stunning me how friendly we - as a community - are towards people who start programming "their first OS" who don't even have a solid understanding of pointers, their compiler, or how a OS is structured.
I wish I could add more tex
User avatar
stephenj
Member
Member
Posts: 140
Joined: Wed Jul 23, 2008 1:37 am
Location: Canada

Re: Build File Help Ubuntu (Linux)

Post by stephenj »

GeniusCobyWalker wrote:How do you know what commands you can use in Linux make files?
Not a ton of Linux experience

Windows Example Command: Echo Text
Make is more like a really simple language, so you need to learn "syntax" more than commands. It doesn't take that long to learn, and the time spent learning it has a very good ROI.

In general, you can use any shell-based application in make (such as echo, gcc, rm, etc.).

Just a note, nearly unrelated to this topic, you may also want to learn "shell scripting". In Linux, many programs have a command-line equivalent, so you can do some pretty interesting things in a short amount of time.
User avatar
GeniusCobyWalker
Member
Member
Posts: 65
Joined: Mon Jan 12, 2009 4:17 pm

Re: Build File Help Ubuntu (Linux)

Post by GeniusCobyWalker »

I keep getting a error heres what I typed, whats wrong?

Prompt:
coby@coby-laptop:~/Desktop/OS$ make
makefile:24: *** missing separator. Stop.
"makefile" :

Code: Select all

CC = [img]gcc[/img]
CFLAGS = -m32 -ffreestanding -nostdlib -nodefaultlibs -mcmodel=large -DBUILDING_KERNEL

ASM = nasm
ASMFLAGS =

LD = ld
LDFLAGS = -T linkerscript.ld --strip-all -nostdlib -nodefaultlibs

BIN = kernel.bin
OUTPUT = WalkerOS

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

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

.PHONY : all clean

all: $(BIN)$(OUTPUT)
clean:
  rm -f *.o
$(BIN)$(OUTPUT): $(COBJECTS) $(ASMOBJECTS)
   $(LD) $(LDFLAGS) -o $(BIN)$(OUTPUT) $(COBJECTS) $(ASMOBJECTS)
$(COBJECTS) : $(CSOURCES) $(CHEADERS)
   $(CC) -c $(CFLAGS) -o $@ $(patsubst %.o,%.c, $@)
$(ASMOBJECTS) : $(ASMSOURCES)
   $(ASM) -f elf32 $(ASMFLAGS) -o $@ $(patsubst %.o,%, $@)
$(CSOURCES) :
$(ASMSOURCES) :
$(CHEADERS) :
OS Files:Image
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
Post Reply