help-make
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Implement Check on Input Values


From: Ajay Jain
Subject: Implement Check on Input Values
Date: Mon, 8 Aug 2011 21:43:21 +0530

Hi,

In my make system, I need to implement check on the value of some
input parameters. For example, my makefile excepts WORK_DIR from
environment and checks the following:

1) Check to make sure that WORK_DIR is not NULL
2) Check to make sure that WORK_DIR exists
3) Check to make sure that WORK_DIR is NOT a part of TOP_DIR/Parent Directory

I need to check this logic within a rule and not otherwise as this is
not applicable to all targets.

So I wrote a (dirty) logic as follows:

check_work_dir :
    $(SET) -ex ; \
if [ "$(WORK_DIR)" = "" ]; \
then $(ECHO) "WORK_DIR is NULL" ; \
exit -1; \
fi; \
if [ ! -d "$(WORK_DIR)" ]; \
then $(ECHO) "$(WORK_DIR) does NOT exist .." ;\
exit -1;\
fi; \
cd "$(WORK_DIR)"; \
tmp_dir1=`pwd`; \
tmp_dir2=$(dir $(dir $(TOP_DIR))); \
$(ECHO) "$$tmp_dir1" \| grep "$$tmp_dir2" ; \
if [ $$? -eq 0 ]; \
then $(ECHO) "WORK_DIR : $(WORK_DIR) should NOT be contained inside
$$tmp_dir2"; \
exit -1; \
fi

Is there a better way to implement this logic?

Many TIA,
Ajay



reply via email to

[Prev in Thread] Current Thread [Next in Thread]