Reputation: 945
I am using a very basic makefile so far and there is the need to extend it. Since I only know the most basic stuff about makefiles, I am seeking for help here.
The very top of my makefile defines a few values I use for different builds etc.
The important part here is the EVALFILE
. It should link to a binary file and is mostly manually set when calling make like make ... EVALFILE="example.bin"
CC = g++
SRC = *.cpp syzygy/tbprobe.c
LIBS = -pthread -Wl,--whole-archive -lpthread -Wl,--no-whole-archive
FOLDER = bin/
ROOT = ../
NAME = Koivisto
EVALFILE = none
EXE = $(ROOT)$(FOLDER)$(NAME)_$(MAJOR).$(MINOR)
MINOR = 0
MAJOR = 5
In case of no user-input for the EVALFILE
, I like to get the file from the submodule in my git repository.
ifeq ($(EVALFILE),none)
pwd:=$(shell pwd); \
cd $(ROOT); \
git submodule update --init; \
cd $(pwd); \
EVALFILE := ../networks/default.net
endif
For this, I want to copy the pwd first to reset it later on. Then I change to the root of the repository, call my git submodule function to update the submodules. The submodule of interested here is ../networks/
which will contain a default.net
which should be used as a binary eventually.
Unfortunately the code above seems to not work. When looking at the networks/
folder after I execute the make command, there seems to be no files inside of it. Furthermore the EVALFILE
is not being set this way. If I move EVALFILE := ../networks/default.net
to the top, it does get set but still nothing inside networks/
.
I do assume I am not calling my cd, git..
calls correctly.
I am very happy if someone could help me out here.
Upvotes: 0
Views: 590
Reputation: 60295
You're doing something with the contents of $(EVALFILE)
. If it doesn't exist, you want to use a default file, and you might need to run a recipe to make that.
Assignments in the makefile aren't run if the variable's set on the command line.
So just do a plain assignment of the default value in the makefile, which you're expecting "is mostly manually set when calling make
":
EVALFILE := ../networks/default.net
and supply a rule to make the default if it doesn't already exist:
../networks/default.net:
git -C .. submodule update --init
(with a tab subbed in for leading whitespace since markdown eats tabs).
Then in recipes that need the evalfile, pass it in as a dependency:
mytest: this that $(EVALFILE)
and everything works.
Upvotes: 1