Page 1 of 2

Build File Help Ubuntu (Linux)

Posted: Fri Jan 16, 2009 2:57 pm
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) :

Re: Build File Help Ubuntu (Linux)

Posted: Fri Jan 16, 2009 2:58 pm
by xyzzy
Define "doesn't work"

Re: Build File Help Ubuntu (Linux)

Posted: Fri Jan 16, 2009 3:03 pm
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.

Re: Build File Help Ubuntu (Linux)

Posted: Fri Jan 16, 2009 7:08 pm
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.

Re: Build File Help Ubuntu (Linux)

Posted: Fri Jan 16, 2009 7:28 pm
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.

Re: Build File Help Ubuntu (Linux)

Posted: Fri Jan 16, 2009 7:38 pm
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.

Re: Build File Help Ubuntu (Linux)

Posted: Fri Jan 16, 2009 7:45 pm
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. :)

Re: Build File Help Ubuntu (Linux)

Posted: Sat Jan 17, 2009 12:43 pm
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

Re: Build File Help Ubuntu (Linux)

Posted: Sat Jan 17, 2009 12:47 pm
by JamesM

Code: Select all

man make

Code: Select all

wget http://www.google.com/?q=Makefile+tutorial

Re: Build File Help Ubuntu (Linux)

Posted: Sat Jan 17, 2009 12:47 pm
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.

Re: Build File Help Ubuntu (Linux)

Posted: Sat Jan 17, 2009 12:48 pm
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.

Re: Build File Help Ubuntu (Linux)

Posted: Sat Jan 17, 2009 12:59 pm
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).

Re: Build File Help Ubuntu (Linux)

Posted: Sat Jan 17, 2009 1:05 pm
by Troy Martin
You do have to download powershell, but IMHO it's confusing and a little awkward to work with.

Re: Build File Help Ubuntu (Linux)

Posted: Sat Jan 17, 2009 1:42 pm
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.

Re: Build File Help Ubuntu (Linux)

Posted: Sun Jan 18, 2009 7:49 pm
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