0

So I am writing some assembly code which is then compiled by a Makefile:

# linking
main: main.o #
    ld -o build/main build/main.o -melf_i386
# compiling
main.o: main.s #
    as -o build/main.o main.s --32

I had to add build directory, cause I often push the code to my GitHub repository, and its kinda hard to .gitignore the linux executables. Now I know, that I can execute bash commands in Makefile. F.e I tested something like bash -c "pwd", and yes, it printed my current working directory. What I wanted to actually do was to jump to build directory right after the compilation. So I wrote my Makefile like this:

# linking
main: main.o #
    ld -o build/main build/main.o -melf_i386
    bash -c "cd ~/Desktop/asm/build"
# compiling
main.o: main.s #
    as -o build/main.o main.s --32

The output was:

[frynio@manjaro asm]$ make
as -o build/main.o main.s --32
ld -o build/main build/main.o -melf_i386
bash -c "cd ~/Desktop/asm/build"
[frynio@manjaro asm]

So as you can see it didnt change the directory (tried with just a relative build path, doesn't work as well). How can I make it work?

Cyrus
  • 84,225
  • 14
  • 89
  • 153
minecraftplayer1234
  • 2,127
  • 4
  • 27
  • 57
  • 3
    When you run `bash -c "cd ..."` it executes in its own shell. So the `cd` occurred but inside of the shell spawned under your make. That shell had to exit to get back to your shell for the prompt, which is still at its own current directory. – lurker Feb 28 '17 at 19:41
  • Hmm, I get it. So is there a way to actually execute `cd` command in a way I would like it to be executed? :D – minecraftplayer1234 Feb 28 '17 at 19:43
  • @Frynio see the answers in the question I linked - there are about three million different ways :) – cxw Feb 28 '17 at 19:44

0 Answers0