#!/bin/bash

# Project Calico BPF dataplane build scripts.
# Copyright (c) 2020 Tigera, Inc. All rights reserved.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.

# 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}${fib}${extra}${log_level}.o"
}

for log_level in debug info no_log; do
  echo "bin/connect_time_${log_level}_v4.o"
  echo "bin/connect_time_${log_level}_v6.o"
  echo "bin/xdp_${log_level}.o"
  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"
    else
      ep_types="wep hep tnl wg"
    fi
    for fib in "" "fib_"; do
      for ep_type in $ep_types; do
        if [ "${host_drop}" = "host_drop_" ] || [ "${fib}" = "fib_" ]; then
          # The workload-to-host drop setting only applies to the from-workload hook.
          # The FIB only applies in the from-endpoint hooks.
          directions="from"
        else
          directions="from to"
        fi
        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
done
