I am using two different OSes.
If I interchange the command it doesnot work. Is there any single line set of commands like:
I want a command (or commands) that works for both of them without showing any error. The place where I need this command is in make file.
I have a makefile like this:
all:
open file.pdf
xdg-open file.pdf
other things ..
Here, inside the makefile how can I be sure that make commands run without error both in Mac and in Linux?
Thanks to @rubiks, now the code works fine. The code looks like this:
# set pdfviewer for linux and unix machines
####################################################
UNAME_S := $(shell uname -s)
$(info $$UNAME_S == $(UNAME_S))
ifeq ($(UNAME_S),Linux)
PDFVIEWER := xdg-open
else ifeq ($(UNAME_S),Darwin)
PDFVIEWER := open
else
$(error unsupported system: $(UNAME_S))
endif
$(info $$PDFVIEWER == $(PDFVIEWER))
####################################################
# open the pdf file
default: all
$(PDFVIEWER) my_pdf_filename.pdf
I think it is better to do this a little more intelligently and determine the OS you are on:
if [ `uname` == "Darwin" ]; then
open file.pdf
else
xdg-open file.pdf
fi
If you are trying to configure your terminal so that you can always use the same command, I would recommend adding this to your .bashrc or .bash_profile:
if [ `uname` == "Linux" ]; then
alias open=xdg-open
fi
This way, you can always use the command open and it will work on either OS.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With