简体   繁体   中英

Run partially build of Makefile

I've the following makefile which is look like following

PROJ_DIR := $(CURDIR)
all: pre app app1 app2 app3
apps = app app1 app2 app3 
pre:
  mkdir temp
app:
    cd PROJ_DIR/app ; npm install

app1:
    cd PROJ_DIR/app1 ; npm install
...
#Need to wait to app1...n to finish the install process in order to proceed and zip all the app installed artifacts
build:$(apps)
     #zip all the apps artifacts

clean:build
    rm -rf test

Now when I run this with make everything is working as expected . The problem is that I want to run partial build like

make -j1 pre app1 build clean (in the sequence only app1 should run and not app2 app3 etc ) here I've a problem since I've the apps pre-requestie(hint from Renaud ) which helps to wait when I execute the whole the make with make but if I want to run it partially it still run them all (all the apps) , is there a trick which can help in both for the execution type ?

Not sure I understand all details but there is one important thing to consider: make does exactly what you tell it to do, no more, no less (hopefully). So, if you tell it that build depends on all your apps you cannot expect make to do build before it also did all apps. It's that simple. It's what

build: $(apps)

says: build depends on $(apps) or, in other words, it is impossible to do build before having done $(apps) .

If you want to build with only one app, you need another target than build ... or you need to change the definition of the apps make variable. And guess what, it's probably the easiest thing to do because make let's you do this on the command line:

$ make apps='app1' pre build clean

or, if you want to build and pack only app1 and app2 :

$ make apps='app1 app2' pre build clean

By default the variables that are assigned on the command line take precedence over the definitions from inside the Makefile. Executing make apps='app1' pre build clean will do exactly the same as if you edit the Makefile to change the definition of apps and then execute make pre build clean .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM