Simplified Makefile and fixed minor issue with fabric.p4

Change-Id: I8a1dfe5a647b93f5dab133c42e7ffb3910485999
diff --git a/pipelines/fabric-pro/src/main/resources/Makefile b/pipelines/fabric-pro/src/main/resources/Makefile
index 76323c2..c6a6d76 100644
--- a/pipelines/fabric-pro/src/main/resources/Makefile
+++ b/pipelines/fabric-pro/src/main/resources/Makefile
@@ -6,78 +6,23 @@
 MAVERICKS_OPTIONS=-DCPU_PORT=$(MAVERICKS_CPU_PORT)
 MONTARA_OPTIONS=-DCPU_PORT=$(MONTARA_CPU_PORT)
 
-all: fabric-tofino fabric-spgw-tofino
-int: fabric-int-tofino fabric-spgw-int-tofino
-
 fabric-tofino:
-	p4c -x p4-16 -b tofino-v1model-barefoot \
-		-I $(P4_SRC_DIR) \
-		$(MAVERICKS_OPTIONS) -o p4c-out/tofino/fabric/mavericks \
-		--p4runtime-file p4c-out/tofino/fabric/mavericks/fabric.p4info \
-		--p4runtime-format text main.p4
-	p4c -x p4-16 -b tofino-v1model-barefoot \
-		-I $(P4_SRC_DIR) \
-		$(MONTARA_OPTIONS) -o p4c-out/tofino/fabric/montara \
-		--p4runtime-file p4c-out/tofino/fabric/montara/fabric.p4info \
-		--p4runtime-format text main.p4
+	./fabric-compile.sh "$(P4_SRC_DIR)" "$(MAVERICKS_OPTIONS)" "$(MONTARA_OPTIONS)" \
+		"" fabric
 
 fabric-spgw-tofino:
-	p4c -x p4-16 -b tofino-v1model-barefoot \
-		-I $(P4_SRC_DIR) \
-		$(MAVERICKS_OPTIONS) -DWITH_SPGW -o p4c-out/tofino/fabric-spgw/mavericks \
-		--p4runtime-file p4c-out/tofino/fabric-spgw/mavericks/fabric.p4info \
-		--p4runtime-format text main.p4
-	p4c -x p4-16 -b tofino-v1model-barefoot \
-		-I $(P4_SRC_DIR) \
-		$(MONTARA_OPTIONS) -DWITH_SPGW -o p4c-out/tofino/fabric-spgw/montara \
-		--p4runtime-file p4c-out/tofino/fabric-spgw/montara/fabric.p4info \
-		--p4runtime-format text main.p4
+	./fabric-compile.sh "$(P4_SRC_DIR)" "$(MAVERICKS_OPTIONS)" "$(MONTARA_OPTIONS)" \
+		"-DWITH_SPGW" fabric-spgw
 
 fabric-spgw-int-tofino: fabric-spgw-int-1-tofino fabric-spgw-int-2-tofino
 
 fabric-spgw-int-1-tofino:
-	p4c -x p4-16 -b tofino-v1model-barefoot \
-		-I $(P4_SRC_DIR) \
-		$(MAVERICKS_OPTIONS) -DWITH_SPGW -DWITH_INT_TRANSIT -DINT_SWITCH_ID=100 -o p4c-out/tofino/fabric-spgw-int-1/mavericks \
-		--p4runtime-file p4c-out/tofino/fabric-spgw-int-1/mavericks/fabric.p4info \
-		--p4runtime-format text main.p4
-	p4c -x p4-16 -b tofino-v1model-barefoot \
-		-I $(P4_SRC_DIR) \
-		$(MONTARA_OPTIONS) -DWITH_SPGW -DWITH_INT_TRANSIT -DINT_SWITCH_ID=100 -o p4c-out/tofino/fabric-spgw-int-1/montara \
-		--p4runtime-file p4c-out/tofino/fabric-spgw-int-1/montara/fabric.p4info \
-		--p4runtime-format text main.p4
-	sed -i 's/FabricIngress\.//g' p4c-out/tofino/fabric-spgw-int-1/*/*.p4info
-	sed -i 's/FabricEgress\.//g' p4c-out/tofino/fabric-spgw-int-1/*/*.p4info
-	sed -i 's/FabricIngress\.//g' p4c-out/tofino/fabric-spgw-int-1/*/context.json
-	sed -i 's/FabricEgress\.//g' p4c-out/tofino/fabric-spgw-int-1/*/context.json
+	./fabric-compile.sh "$(P4_SRC_DIR)" "$(MAVERICKS_OPTIONS)" "$(MONTARA_OPTIONS)" \
+		"-DWITH_SPGW -DWITH_INT_TRANSIT -DINT_SWITCH_ID=100" fabric-spgw-int-1
 
 fabric-spgw-int-2-tofino:
-	p4c -x p4-16 -b tofino-v1model-barefoot \
-		-I $(P4_SRC_DIR) \
-		$(MAVERICKS_OPTIONS) -DWITH_SPGW -DWITH_INT_TRANSIT -DINT_SWITCH_ID=200 -o p4c-out/tofino/fabric-spgw-int-2/mavericks \
-		--p4runtime-file p4c-out/tofino/fabric-spgw-int-2/mavericks/fabric.p4info \
-		--p4runtime-format text main.p4
-	p4c -x p4-16 -b tofino-v1model-barefoot \
-		-I $(P4_SRC_DIR) \
-		$(MONTARA_OPTIONS) -DWITH_SPGW -DWITH_INT_TRANSIT -DINT_SWITCH_ID=200 -o p4c-out/tofino/fabric-spgw-int-2/montara \
-		--p4runtime-file p4c-out/tofino/fabric-spgw-int-2/montara/fabric.p4info \
-		--p4runtime-format text main.p4
-	sed -i 's/FabricIngress\.//g' p4c-out/tofino/fabric-spgw-int-2/*/*.p4info
-	sed -i 's/FabricEgress\.//g' p4c-out/tofino/fabric-spgw-int-2/*/*.p4info
-	sed -i 's/FabricIngress\.//g' p4c-out/tofino/fabric-spgw-int-2/*/context.json
-	sed -i 's/FabricEgress\.//g' p4c-out/tofino/fabric-spgw-int-2/*/context.json
-
-fabric-int-tofino:
-	p4c -x p4-16 -b tofino-v1model-barefoot \
-		-I $(P4_SRC_DIR) \
-		$(MAVERICKS_OPTIONS) -DWITH_INT_TRANSIT -o p4c-out/tofino/fabric-int/mavericks \
-		--p4runtime-file p4c-out/tofino/fabric-int/mavericks/fabric.p4info \
-		--p4runtime-format text main.p4
-	p4c -x p4-16 -b tofino-v1model-barefoot \
-		-I $(P4_SRC_DIR) \
-		$(MONTARA_OPTIONS) -DWITH_INT_TRANSIT -o p4c-out/tofino/fabric-int/montara \
-		--p4runtime-file p4c-out/tofino/fabric-int/montara/fabric.p4info \
-		--p4runtime-format text main.p4
+	./fabric-compile.sh "$(P4_SRC_DIR)" "$(MAVERICKS_OPTIONS)" "$(MONTARA_OPTIONS)" \
+		"-DWITH_SPGW -DWITH_INT_TRANSIT -DINT_SWITCH_ID=200" fabric-spgw-int-2
 
 clean:
 	rm -rf p4c-out/*
diff --git a/pipelines/fabric-pro/src/main/resources/fabric-compile.sh b/pipelines/fabric-pro/src/main/resources/fabric-compile.sh
new file mode 100755
index 0000000..54830ea
--- /dev/null
+++ b/pipelines/fabric-pro/src/main/resources/fabric-compile.sh
@@ -0,0 +1,24 @@
+#!/usr/bin/env bash
+
+set -x
+
+P4_SRC_DIR=$1
+MAVERICKS_OPTIONS=$2
+MONTARA_OPTIONS=$3
+OTHER_PP_FLAGS=$4
+NAME=$5
+
+p4c -x p4-16 -b tofino-v1model-barefoot \
+		-I ${P4_SRC_DIR} \
+		${MAVERICKS_OPTIONS} ${OTHER_PP_FLAGS} -o p4c-out/tofino/${NAME}/mavericks \
+		--p4runtime-file p4c-out/tofino/${NAME}/mavericks/fabric.p4info \
+		--p4runtime-format text main.p4
+	p4c -x p4-16 -b tofino-v1model-barefoot \
+		-I ${P4_SRC_DIR} \
+		${MONTARA_OPTIONS} ${OTHER_PP_FLAGS} -o p4c-out/tofino/${NAME}/montara \
+		--p4runtime-file p4c-out/tofino/${NAME}/montara/fabric.p4info \
+		--p4runtime-format text main.p4
+	sed -i 's/FabricIngress\.//g' p4c-out/tofino/${NAME}/*/*.p4info
+	sed -i 's/FabricEgress\.//g' p4c-out/tofino/${NAME}/*/*.p4info
+	sed -i 's/FabricIngress\.//g' p4c-out/tofino/${NAME}/*/context.json
+	sed -i 's/FabricEgress\.//g' p4c-out/tofino/${NAME}/*/context.json
diff --git a/pipelines/fabric/src/main/resources/fabric.p4 b/pipelines/fabric/src/main/resources/fabric.p4
index cb287a3..1ed6647 100644
--- a/pipelines/fabric/src/main/resources/fabric.p4
+++ b/pipelines/fabric/src/main/resources/fabric.p4
@@ -46,8 +46,10 @@
     EgressNextControl() egress_next;
 
     apply {
+#ifdef WITH_INT_TRANSIT
         fabric_metadata.int_metadata.ingress_tstamp =
             (bit<32>) standard_metadata.ingress_global_timestamp;
+#endif // WITH_INT_TRANSIT
         packet_io_ingress.apply(hdr, fabric_metadata, standard_metadata);
 #ifdef WITH_SPGW
 #ifdef WITH_SPGW_PCC_GATING