xref: /haiku/build/jam/CommandLineArguments (revision da854e342fee790d64ab96d249fed83acd8a5205)
1# Rules related to processing of jam command line arguments.
2
3rule ProcessCommandLineArguments
4{
5	# analyze and optionally replace jam's target parameters
6	HAIKU_ORIGINAL_JAM_TARGETS = $(JAM_TARGETS) ;
7	HAIKU_BUILD_PROFILE = ;
8	if $(JAM_TARGETS) {
9		switch $(JAM_TARGETS[1]) {
10			# If the target to be built is "all" (i.e. the default) and we're in
11			# the output directory, the root directory of the build system, or
12			# in "src/", we change the target to be built to "haiku-image".
13			case all : {
14				if ! $(INVOCATION_SUBDIR) || $(INVOCATION_SUBDIR) = src {
15					JAM_TARGETS = haiku-image ;
16				}
17			}
18
19			# Print usage text.
20			case help : {
21				Echo "Individual targets (applications, libraries, drivers,...)"
22					" can be built by just" ;
23				Echo "passing them as arguments to jam. The recommended method"
24					"to build or update a" ;
25				Echo "Haiku image or installation is to use a build profile"
26					"with one of the build" ;
27				Echo "profile actions. Typical command lines using a build"
28					"profile looks like this:" ;
29				Echo "  jam @image" ;
30				Echo "  jam @install update libbe.so" ;
31				Echo "  jam @vmware-image mount" ;
32				Echo ;
33				Echo "Default build profiles:" ;
34				Echo "  image         - A raw disk image." ;
35				Echo "  anyboot-image - A custom image for either CD or disk." ;
36				Echo "  cd-image      - An ISO9660 CD image." ;
37				Echo "  vmware-image  - A VMware disk image." ;
38				Echo "  install       - A Haiku installation in a directory." ;
39				Echo ;
40				Echo "Build profile actions:" ;
41				Echo "  build                - Build a Haiku"
42					"image/installation. This is the default" ;
43				Echo "                         action, i.e. it can be"
44					"omitted." ;
45				Echo "  update <target> ...  - Update the specified targets in"
46					" the Haiku" ;
47				Echo "                         image/installation." ;
48				Echo "  update-all           - Update all targets in the Haiku"
49					" image/installation." ;
50				Echo "  mount                - Mount the Haiku image in the"
51					" bfs_shell." ;
52				Echo ;
53				Echo "Package upload to (git.haiku-os.org/hpkg-upload):" ;
54				Echo "  jam upload-packages <packages ...> " ;
55				Echo ;
56				Echo "Remote repository creation (for testing a set of"
57					" packages):" ;
58				Echo "  jam build-remote-test-repository <packages ...> " ;
59				Echo ;
60				Echo "For more details on how to customize Haiku builds read" ;
61				Echo "build/jam/UserBuildConfig.ReadMe." ;
62				Exit ;
63			}
64
65			# The "run" target allows for running arbitrary command lines
66			# containing build system targets, which are built and replaced
67			# accordingly.
68			case run : {
69				if $(JAM_TARGETS[2]) {
70					JAM_TARGETS = [ RunCommandLine $(JAM_TARGETS[2-]) ] ;
71				} else {
72					Exit "\"jam run\" requires parameters!" ;
73				}
74			}
75
76			# Copy the given set of local package files to the git repository
77			# server, where they will be used for creating a new repository
78			# during the push hook.
79			case upload-packages : {
80				UploadPackages $(JAM_TARGETS[1]) : $(JAM_TARGETS[2-]) ;
81				JAM_TARGETS = $(JAM_TARGETS[1]) ;
82				NotFile $(JAM_TARGETS) ;
83				Always $(JAM_TARGETS) ;
84			}
85
86			# Copy the given set of local package files to the remote repository
87			# and create a new version of that remote repository (useful for
88			# testing the package repository before pushing).
89			case build-remote-test-repository : {
90				BuildRemoteHaikuPortsRepository $(JAM_TARGETS[1])
91					: $(JAM_TARGETS[2-]) ;
92				JAM_TARGETS = $(JAM_TARGETS[1]) ;
93				NotFile $(JAM_TARGETS) ;
94				Always $(JAM_TARGETS) ;
95			}
96
97			# A target starting with "@" is a build profile.
98			case @* : {
99				HAIKU_BUILD_PROFILE = [ Match "@(.*)" : $(JAM_TARGETS[1]) ] ;
100				HAIKU_BUILD_PROFILE_ACTION = $(JAM_TARGETS[2]:E=build) ;
101				HAIKU_BUILD_PROFILE_PARAMETERS = $(JAM_TARGETS[3-]) ;
102				HAIKU_BUILD_PROFILE_DEFINED = ;
103			}
104
105			case * : {
106				# "update-image", "update-vmware-image", and "update-install"
107				# targets allow for updating only specific targets in the
108				# image/installation dir.
109				if $(JAM_TARGETS[1]) in update-image update-vmware-image
110						update-install {
111					SetUpdateHaikuImageOnly 1 ;
112					HAIKU_PACKAGES_UPDATE_ONLY = 1 ;
113					HAIKU_INCLUDE_IN_IMAGE on $(JAM_TARGETS[2-]) = 1 ;
114					HAIKU_INCLUDE_IN_PACKAGES on $(JAM_TARGETS[2-]) = 1 ;
115
116					if $(JAM_TARGETS[1]) = update-image {
117						JAM_TARGETS = haiku-image ;
118					} else if $(JAM_TARGETS[1]) = update-vmware-image {
119						JAM_TARGETS = haiku-vmware-image ;
120					} else {
121						JAM_TARGETS = install-haiku ;
122					}
123				}
124			}
125		}
126	}
127}
128