\[ \int (g+h x)^2 \log \left (e \left (f (a+b x)^p (c+d x)^q\right )^r\right ) \, dx \]
Optimal antiderivative \[ -\frac {\left (-a h +b g \right )^{2} p r x}{3 b^{2}}-\frac {\left (-c h +d g \right )^{2} q r x}{3 d^{2}}-\frac {\left (-a h +b g \right ) p r \left (h x +g \right )^{2}}{6 b h}-\frac {\left (-c h +d g \right ) q r \left (h x +g \right )^{2}}{6 d h}-\frac {p r \left (h x +g \right )^{3}}{9 h}-\frac {q r \left (h x +g \right )^{3}}{9 h}-\frac {\left (-a h +b g \right )^{3} p r \ln \! \left (b x +a \right )}{3 b^{3} h}-\frac {\left (-c h +d g \right )^{3} q r \ln \! \left (d x +c \right )}{3 d^{3} h}+\frac {\left (h x +g \right )^{3} \ln \! \left (e \left (f \left (b x +a \right )^{p} \left (d x +c \right )^{q}\right )^{r}\right )}{3 h} \]
command
integrate((h*x+g)^2*log(e*(f*(b*x+a)^p*(d*x+c)^q)^r),x, algorithm="giac")
Giac 1.9.0-11 via sagemath 9.6 output
\[ \text {Timed out} \]
Giac 1.7.0 via sagemath 9.3 output
\[ -\frac {1}{9} \, {\left (h^{2} p r + h^{2} q r - 3 \, h^{2} r \log \left (f\right ) - 3 \, h^{2}\right )} x^{3} + \frac {1}{3} \, {\left (h^{2} p r x^{3} + 3 \, g h p r x^{2} + 3 \, g^{2} p r x\right )} \log \left (b x + a\right ) + \frac {1}{3} \, {\left (h^{2} q r x^{3} + 3 \, g h q r x^{2} + 3 \, g^{2} q r x\right )} \log \left (d x + c\right ) - \frac {{\left (3 \, b d g h p r - a d h^{2} p r + 3 \, b d g h q r - b c h^{2} q r - 6 \, b d g h r \log \left (f\right ) - 6 \, b d g h\right )} x^{2}}{6 \, b d} + \frac {{\left (3 \, a b^{2} g^{2} p r - 3 \, a^{2} b g h p r + a^{3} h^{2} p r\right )} \log \left (b x + a\right )}{3 \, b^{3}} + \frac {{\left (3 \, c d^{2} g^{2} q r - 3 \, c^{2} d g h q r + c^{3} h^{2} q r\right )} \log \left (-d x - c\right )}{3 \, d^{3}} - \frac {{\left (3 \, b^{2} d^{2} g^{2} p r - 3 \, a b d^{2} g h p r + a^{2} d^{2} h^{2} p r + 3 \, b^{2} d^{2} g^{2} q r - 3 \, b^{2} c d g h q r + b^{2} c^{2} h^{2} q r - 3 \, b^{2} d^{2} g^{2} r \log \left (f\right ) - 3 \, b^{2} d^{2} g^{2}\right )} x}{3 \, b^{2} d^{2}} \]