Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add make target `clean-program` to makefiles #772

Closed
mitzimorris opened this issue Nov 22, 2019 · 5 comments · Fixed by #773
Closed

add make target `clean-program` to makefiles #772

mitzimorris opened this issue Nov 22, 2019 · 5 comments · Fixed by #773
Labels

Comments

@mitzimorris
Copy link
Member

@mitzimorris mitzimorris commented Nov 22, 2019

Summary:

when building a stan exe from the stan program file, make creates intermediate files.
add a make command to removes both the exe and all intermediate files.

Description:

Example - compile CmdStan's example file bernoulli.stan - note resulting intermediate files:

~/github/stan-dev/cmdstan (develop)> ls -1F examples/bernoulli
bernoulli.data.R
bernoulli.data.json
bernoulli.stan

~/github/stan-dev/cmdstan (develop)> make examples/bernoulli/bernoulli
...
--- Translating Stan model to C++ code ---
...
--- Compiling, linking C++ code ---
...

~/github/stan-dev/cmdstan (develop)> ls -1F examples/bernoulli
bernoulli*
bernoulli.d
bernoulli.data.R
bernoulli.data.json
bernoulli.hpp
bernoulli.o
bernoulli.stan
~/github/stan-dev/cmdstan (develop)> 

command make clean-program examples/bernoulli/bernoulli should remove exe, .d, .hpp, and .o files.

Reproducible Steps:

Please report steps to reproduce the issue. If it's not possible to reproduce, please include a description of how you discovered the issue.

If you have a reproducible example, please include it.

Current Output:

The current output. Knowing what is the current behavior is useful.

Expected Output:

Describe what you expect the output to be. Knowing the correct behavior is also very useful.

Additional Information:

Provide any additional information here.

Current Version:

v2.21.0

@mitzimorris mitzimorris mentioned this issue Nov 22, 2019
2 of 2 tasks complete
@syclik

This comment has been minimized.

Copy link
Member

@syclik syclik commented Nov 22, 2019

@mitzimorris, sorry, but that's not going to work with make. The space is a delimiter and will result in two targets being passed to make: 1) clean-program and 2) examples/bernoulli/bernoulli. The second target will just try to build it.

One way to deal with something like this is to use a pattern target, so something like make clean-examples/bernoulli/bernoulli. That can be matched, the dependencies found, etc.

@syclik

This comment has been minimized.

Copy link
Member

@syclik syclik commented Nov 22, 2019

Btw, that's just a technical limitation with make. If you find a way to work around it, please let me know! I haven't seen any way to manipulate the targets passed in well enough to handle arguments to make targets.

@mitzimorris

This comment has been minimized.

Copy link
Member Author

@mitzimorris mitzimorris commented Nov 22, 2019

sure, make clean-<path/to/exe> would be fine.

the issue is being able to have a simple way to do cleanups after building the exe - make clean-all is not fine-grained enough.

@wesbarnett

This comment has been minimized.

Copy link
Contributor

@wesbarnett wesbarnett commented Nov 25, 2019

What if the name/path of the compiled binary is passed as an argument?

clean-program:
	rm -v ${STANPROG}{,.o,.hpp}

Then you could just run:

make STANPROG=/path/to/model clean-program

Edit: Need a way to ensure the ARG is set though.

@wesbarnett

This comment has been minimized.

Copy link
Contributor

@wesbarnett wesbarnett commented Nov 25, 2019

Here's a way to check if the passed argument is set. Might be safer to pass the name of the stanfile and then pattern match from that. Perhaps there is a better convention though. Here's an example:

.PHONY: clean-program
clean-program:
ifdef STANFILE
	$(RM) $(wildcard $(patsubst %.stan,%.d,${STANFILE}))
	$(RM) $(wildcard $(patsubst %.stan,%.hpp,${STANFILE}))
	$(RM) $(wildcard $(patsubst %.stan,%.o,${STANFILE}))
	$(RM) $(wildcard $(patsubst %.stan,%$(EXE),${STANFILE}))
else
	$(error STANFILE not set)
endif

Edit: I created a PR with what this might look like (updated to ensure someone doesn't accidentally remove the stan file).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants
You can’t perform that action at this time.