0

Hey i want to compile one c file first and then the assembly and safe both object files in one directory to link them. But my makefile just use one rule.

IDIR = headers/syscalls
CL=clang
NASM = nasm
CFLAGS=-g -Wall -fsanitize=address
LDFLAGS=-g -Wall -fsanitize=address
HFLAGS= -I$(IDIR)

ODIR=src/obj


_DEPS = myunistd.h mystddef.h
DEPS = $(patsubst %,$(IDIR)/%,$(_DEPS))


_OBJ = demoSys.o myunistd.o
OBJ = $(patsubst %,$(ODIR)/%,$(_OBJ))

$(ODIR)/demoSys.o: src/demoSys.c $(DEPS)
    $(CL) -c -o $@ $< $(HFLAGS)


$(ODIR)/myunistd.o: src/myunistd.s 
    $(NASM) -f elf64 -o $@ $< 

exe: $(OBJ)
    $(CL) -o $@ $^ 



.Phony: clean

clean:
    rm -f $(ODIR)/*.o *~ core $(INCDIR)/*~

that is my makefile

Thank you for any help

Jan Wolfram
  • 145
  • 8
  • Which rule? Clarify your question a bit. – klutt Oct 24 '19 at 12:34
  • I mean the two rules with the $ sign :) the both work alone but not together. And the exe rule will just execute when you have both object files – Jan Wolfram Oct 24 '19 at 12:35
  • Are you saying you run "make exe", and it does *not* attempt to build both object files and the executable ? What's the exact command you run, and the exact output you get ? – Sander De Dycker Oct 24 '19 at 12:53
  • 3
    Without any command line parameter to select a target, make will default to building only the first target, which is $(ODIR)/demoSys.o. If you want exe to to be the default target. place its rule before the others. – Ian Abbott Oct 24 '19 at 12:53
  • i run "make" my output is "clang -c -o src/obj/demoSys.o src/demoSys.c -Iheaders/syscalls " so only using first rule. If i delete the first it makes the same with second rule – Jan Wolfram Oct 24 '19 at 12:56
  • 1
    Then @IanAbbott is right - you need to either do "make exe", or place the exe target as the first target so it's picked as the default. – Sander De Dycker Oct 24 '19 at 12:57
  • Thanks to Ian Abbott his solution worked for me :) – Jan Wolfram Oct 24 '19 at 12:58
  • 1
    You could add a rule for a phony "all" target, `all: exe`, before the rule for $(ODIR)/demoSys.o, then "make" will build the "all" target, which depends on the "exe" target.... – Ian Abbott Oct 24 '19 at 12:59

0 Answers0