LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 02-11-2015, 04:36 AM   #1
diracsbracket
LQ Newbie
 
Registered: Jun 2014
Posts: 8

Rep: Reputation: Disabled
How to write a Makefile with .c and .asm file


Hi,
I am working with Debian and gcc.

I have a single C file main.c, with some code in it.
For this trivial build, I am using the following Makefile:

Code:
SOURCES=main.c
CFLAGS=-c -w -gdwarf-4 -g3 -O0

LDFLAGS=
CC=

OBJECTS=$(SOURCES:.c=.o)
EXECUTABLE=myprogram

all: clean $(SOURCES) $(EXECUTABLE)

$(EXECUTABLE): $(OBJECTS)
	$(CC)gcc $(LDFLAGS) $(OBJECTS) -o $@

clean:
	rm -f $(EXECUTABLE) $(OBJECTS) $(MAKE)

.c.o:
	$(CC)gcc $(CFLAGS) $(LDFLAGS) $< -o $@
Now, in main.c, I want to use an assembly function, say myFunction which is implemented in the file function.asm.

My question is now: how do I build this? How do I modify the Makefile above to do this ?

Many thanks for your help!!!

PD.

Last edited by diracsbracket; 02-11-2015 at 04:42 AM.
 
Old 02-11-2015, 04:43 AM   #2
pan64
LQ Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 9,895

Rep: Reputation: 2921Reputation: 2921Reputation: 2921Reputation: 2921Reputation: 2921Reputation: 2921Reputation: 2921Reputation: 2921Reputation: 2921Reputation: 2921Reputation: 2921
that is quite simple, probably you only need a .asm.o rule, here is an example: http://cs.smith.edu/dftwiki/index.ph...SM_and_C_Files

By the way you should write CC=gcc in the beginning and use $(CC) instead of $(CC)gcc at the end.
And you need to remove $(MAKE) at the end of the rm command

Last edited by pan64; 02-11-2015 at 04:57 AM.
 
1 members found this post helpful.
Old 02-11-2015, 01:25 PM   #3
rtmistler
Moderator
 
Registered: Mar 2011
Location: Sutton, MA. USA
Distribution: MINT Debian, Angstrom, SUSE, Ubuntu
Posts: 5,973
Blog Entries: 12

Rep: Reputation: 2038Reputation: 2038Reputation: 2038Reputation: 2038Reputation: 2038Reputation: 2038Reputation: 2038Reputation: 2038Reputation: 2038Reputation: 2038Reputation: 2038
I usually put the fully qualified path for gcc such as /usr/bin/gcc as the definition for CC=

I forget the exacting syntax, but similarly to how you create an object from C source, you do the same to specify a dependency on an assembly object, but base that on the assembly source, have a rule which governs that and a map to an assembler which can properly interpret the source, along with flags to create a .o file. Then when you perform your executable link, using gcc, you simply include that .o from the assembler output in the link list. So it's really just a parallel rule like the gcc one for making an object, just that the object is sourced from a different type of file.
 
1 members found this post helpful.
Old 02-14-2015, 10:22 AM   #4
diracsbracket
LQ Newbie
 
Registered: Jun 2014
Posts: 8

Original Poster
Rep: Reputation: Disabled
pan64, rtmistler,
Many thanks for your kind help and suggestions!
It all makes sense now!

Best regards,
PD.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] error: asm/ppc_asm.h: No such file or directory and error: asm/processor.h: No such f Thirupathip Linux - Newbie 3 01-25-2013 04:02 AM
[SOLVED] need of makefile info ? how the linux make file is different from simple c makefile ? rpittala Linux - Newbie 2 05-07-2012 09:04 PM
How to write a Makefile mab_123 Linux - Software 1 07-06-2005 12:31 PM
Linux shell command for makefile.in to create a text file and write to it alix123 Programming 8 01-07-2005 09:18 AM
How to write a Makefile? lpriyamb Linux - Software 2 10-15-2003 05:11 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 09:47 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration