Author Topic: Makefile  (Read 9411 times)

Offline fixit

  • Jr. Member
  • *
  • Posts: 23
Makefile
« on: August 05, 2016, 10:00:46 PM »
How do I run a makefile ?

I tried nasm makefile.
Code: [Select]
nasm: warning: file name already has no extension: output will be in `nasm.out'
makefile:1: error: parser: instruction expected
makefile:2: error: parser: instruction expected
makefile:3: error: parser: instruction expected
makefile:4: error: parser: instruction expected
makefile:5: error: symbol `nasm' redefined
makefile:5: error: parser: instruction expected

Offline Frank Kotler

  • NASM Developer
  • Hero Member
  • *****
  • Posts: 2667
  • Country: us
Re: Makefile
« Reply #1 on: August 06, 2016, 03:38:42 PM »
Heh, "might as well try to assemble a sonnet." Rather than run Nasm on your makefile, the "make" utility runs Nasm (and/or other tools) on assembly files specified in your makefile. By default, "make" looks for "makefile" or "Makefile" in the current directory. It is often spelled "Makefile" so it alphabetizes near the top of the source listing. Another name can be specified with the "-f" switch - "make -f mkfiles/myprog.mak" or whatever. The default target usually just builds the executable. The most famous target is probably "make install". "make clean" is another common target. The whole idea is to avoid running tools on files that haven't changed since the last build, saving time on a complex project. "man make" or "info make" will tell you more than you want to know. Wikipedia has a brief rundown:
https://en.wikipedia.org/wiki/Makefile

In short, just get into the directory and type "make".

Best,
Frank



Offline fixit

  • Jr. Member
  • *
  • Posts: 23
Re: Makefile
« Reply #2 on: August 06, 2016, 04:32:24 PM »
This is an example from here.

Quote
https://forum.nasm.us/index.php?topic=2253.0

Code: [Select]
make
nasm -f elf editbin.asm
nasm -f elf cursor.asm
ld -s -o editbin editbin.o cursor.o
ld: i386 architecture of input file `editbin.o' is incompatible with i386:x86-64 output
ld: i386 architecture of input file `cursor.o' is incompatible with i386:x86-64 output
makefile:2: recipe for target 'editbin' failed
make: *** [editbin] Error 1
Am I getting this because I am using a 64 bit system ?
« Last Edit: August 06, 2016, 04:33:55 PM by fixit »

Offline Frank Kotler

  • NASM Developer
  • Hero Member
  • *****
  • Posts: 2667
  • Country: us
Re: Makefile
« Reply #3 on: August 06, 2016, 05:28:44 PM »
Yeah, probably. Try editing John's "makefile" like so:

Code: [Select]
editbin: editbin.o
ld -s -o -m elf_i386 editbin editbin.o cursor.o getkey.o
editbin.o: editbin.asm cursor.asm
nasm -f elf editbin.asm
nasm -f elf cursor.asm
nasm -f elf getkey.asm

No guarantee, I've got a 32-bit system too. I find makefiles tricky, since an "invisible" character - TAB - is a vital part of the syntax. Some editors silently replace TAB (ascii 9) with spaces (good ol' edit.com used to do it), causing "make" to barf with an unhelpful error message.

Best,
Frank


Offline fixit

  • Jr. Member
  • *
  • Posts: 23
Re: Makefile
« Reply #4 on: August 06, 2016, 06:50:00 PM »
Thanks worked like a charm.

And program works well.

Fairly small editor though a com file would probably be smaller.