#!/bin/bash

# Project Calico BPF dataplane build scripts.
# Copyright (c) 2020-2024 Tigera, Inc. All rights reserved.
# SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later

# Generate the cross-product of all the compile options, excluding some cases that don't make sense.
# Emit the filename for each option to stdout.
#
# WARNING: naming and set of cases must be kept in sync with tc.ProgFilename() in Felix's compiler.go.

emit_filename() {
  echo "bin/${from_or_to}_${ep_type}_${host_drop}${extra}${log_level}.o"
  echo "bin/${from_or_to}_${ep_type}_${host_drop}${extra}${log_level}_v6.o"
}

for log_level in debug no_log; do
  echo "bin/conntrack_cleanup_${log_level}_v4.o"
  echo "bin/conntrack_cleanup_${log_level}_v6.o"
  echo "bin/connect_balancer_${log_level}_v4.o"
  echo "bin/connect_balancer_${log_level}_v46.o"
  echo "bin/connect_balancer_${log_level}_v6.o"
  echo "bin/xdp_${log_level}.o"
  echo "bin/xdp_${log_level}_v6.o"
  directions="from to"
  for host_drop in "" "host_drop_"; do
    if [ "${host_drop}" = "host_drop_" ]; then
      # The workload-to-host drop setting only applies to the from-workload hook.
      ep_types="wep"
      directions="from"
    else
      ep_types="wep hep ipip l3 nat lo vxlan"
      directions="from to"
    fi
    for ep_type in $ep_types; do
      for from_or_to in $directions; do
        extra="dsr_"
        if [ "${ep_type}" = "hep" ]; then
          emit_filename
        fi
        if [ "${from_or_to}" = "from" ] && [ "${ep_type}" = "wep" ]; then
          emit_filename
        fi
        extra=""
        emit_filename
      done
    done
  done
done
